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

40 lines
2.4 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-state.js — act 城镇页的状态断言(acts.html)
//
// 判定全部来自 window.__d2webAct 的字段,不看图:归档是否真的读进来了、地图块
// 有几格、瓦片引用是否全部解析、图集多大、以及按键之后角色是否真的沿屏幕方向
// 位移且朝向正确。返回 JSON,由 scripts/browser/inspect-page.mjs 打印。
//
// 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-state.js
(async () => {
const sleep = (ms) => new Promise((r) => setTimeout(r, ms))
const deadline = Date.now() + 150000
while (Date.now() < deadline) {
const s = window.__d2webAct
if (s && (s.ready || s.error)) break
await sleep(500)
}
const first = { ...(window.__d2webAct ?? {}) }
await sleep(1500)
const before = { x: window.__d2webAct?.x ?? 0, y: window.__d2webAct?.y ?? 0, tick: window.__d2webAct?.tick ?? 0 }
const press = (code, down) => window.dispatchEvent(new KeyboardEvent(down ? 'keydown' : 'keyup', { code, bubbles: true }))
// 向东走 1.2 秒,再向南走 1.2 秒;记录位移与朝向
press('ArrowRight', true); await sleep(1200); press('ArrowRight', false)
const east = { x: window.__d2webAct?.x ?? 0, y: window.__d2webAct?.y ?? 0, facing: window.__d2webAct?.facing ?? -1 }
press('ArrowDown', true); await sleep(1200); press('ArrowDown', false)
await sleep(300)
const south = { x: window.__d2webAct?.x ?? 0, y: window.__d2webAct?.y ?? 0, facing: window.__d2webAct?.facing ?? -1 }
return {
ready: first.ready, error: first.error ?? null,
act: first.act, level: first.level, quadrant: first.quadrant, quadrants: first.quadrants,
cells: `${first.cellsX}x${first.cellsY}`, scene: `${first.widthPx}x${first.heightPx}`,
floors: first.floors, walls: first.walls, frames: first.frames,
atlas: `${first.atlasWidth}x${first.atlasHeight}`,
missing: first.missing, walkable: Number((first.walkable ?? 0).toFixed(3)),
character: first.character, drawCalls: first.drawCalls, tickRate: Number((first.tickRate ?? 0).toFixed(1)),
moved: { east: [Math.round(east.x - before.x), Math.round(east.y - before.y)], south: [Math.round(south.x - east.x), Math.round(south.y - east.y)], tickDelta: (window.__d2webAct?.tick ?? 0) - before.tick },
facingEast: east.facing, facingSouth: south.facing,
}
})()