diablo2-web/scripts/browser/checks/act-pack-state.js

58 lines
3.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// act-pack-state.js — 资源包路径的状态断言(acts.html 默认路径)
//
// 判定全来自 window.__d2webAct:是不是走了资源包、首屏只装了几页(证明懒加载)、
// 出画面用了多久、以及按键后角色是否沿屏幕方向位移且朝向正确。返回 JSON。
//
// CHROME=/root/.cache/ms-playwright/chromium-1223/chrome-linux64/chrome
// node scripts/browser/inspect-page.mjs "$CHROME" \
// "http://127.0.0.1:5173/acts.html?act=1" scripts/browser/checks/act-pack-state.js
(async () => {
const sleep = (ms) => new Promise((r) => setTimeout(r, ms))
const deadline = Date.now() + 120000
while (Date.now() < deadline) {
const s = window.__d2webAct
if (s && (s.ready || s.error)) break
await sleep(200)
}
const atReady = { ...(window.__d2webAct ?? {}) }
await sleep(6000)
const after = { ...(window.__d2webAct ?? {}) }
const before = { x: after.x, y: after.y }
const press = (code, down) => window.dispatchEvent(new KeyboardEvent(down ? 'keydown' : 'keyup', { code, bubbles: true }))
press('ArrowRight', true); await sleep(900); press('ArrowRight', false)
await sleep(200)
const moved = { x: window.__d2webAct?.x ?? 0, y: window.__d2webAct?.y ?? 0, facing: window.__d2webAct?.facing ?? -1 }
return {
source: atReady.source, ready: atReady.ready, error: atReady.error ?? null,
base: atReady.base, act: atReady.act, level: atReady.level, quadrant: atReady.quadrant,
cells: `${atReady.cellsX}x${atReady.cellsY}`,
floors: atReady.floors, walls: atReady.walls, frames: atReady.frames, objects: atReady.objects,
character: atReady.character,
characterMembers: atReady.characterMembers,
characterAfter: after.character,
characterMembersAfter: after.characterMembers,
levelOptions: document.querySelector('#level')?.querySelectorAll('option').length ?? -1,
pickerSelected: document.querySelector('#level')?.selectedOptions?.[0]?.textContent ?? null,
pagesAtReady: `${atReady.pagesLoaded}/${atReady.pagesTotal}`,
pagesAtFirstFrame: `${atReady.pagesAtFirstFrame}/${atReady.pagesTotal}`,
firstFrameMs: atReady.firstFrameMs,
priorityPages: atReady.priorityPages,
lazyFirstFrame: atReady.pagesAtFirstFrame < atReady.pagesTotal,
pagesAfterWait: `${after.pagesLoaded}/${after.pagesTotal}`,
lazyFirstPaint: (atReady.pagesLoaded ?? 0) < (atReady.pagesTotal ?? 0),
loadMs: atReady.loadMs,
skippedAtReady: atReady.skippedDraws,
move: [Math.round(moved.x - before.x), Math.round(moved.y - before.y)],
facing: moved.facing,
tick: after.tick,
walkable: Number((atReady.walkable ?? 0).toFixed(3)),
// 画布是否铺满窗口 + 缩放是否至少覆盖视口
canvas: [after.canvasWidth, after.canvasHeight],
viewport: [window.innerWidth, window.innerHeight],
zoom: after.zoom,
coverZoom: Math.max(window.innerWidth / Math.max(1, after.widthPx), window.innerHeight / Math.max(1, after.heightPx)),
canvasFillsWindow: after.canvasWidth >= window.innerWidth - 2 && after.canvasHeight >= window.innerHeight - 2,
mapCoversViewport: (after.zoom ?? 0) + 1e-6 >= Math.max(window.innerWidth / Math.max(1, after.widthPx), window.innerHeight / Math.max(1, after.heightPx)),
}
})()