orbit/dev/jobboard-wrap.mjs

102 lines
3.8 KiB
JavaScript

/**
* Dev-only probe: open the JOB BOARD, select a posting, and report the
* detail panel's text objects (which wrap, which don't, where they end
* relative to the panel's right edge).
*
* node dev/server.mjs 8080
* CHROME_PATH=... node dev/jobboard-wrap-run.mjs
*/
import Phaser from '../js/vendor/phaser.js';
import { config } from '../js/config/Config.js';
import { ConfigLoader } from '../js/config/ConfigLoader.js';
import { createGameConfig } from '../js/config/GameConfig.js';
import { MenuScene } from '../js/scenes/MenuScene.js';
import { GameScene } from '../js/scenes/GameScene.js';
import { SurfaceScene } from '../js/scenes/SurfaceScene.js';
const data = await ConfigLoader.load();
config.init(data);
const errors = [];
const origErr = console.error.bind(console);
console.error = (...a) => { errors.push(a.map(String).join(' ')); origErr(...a); };
window.addEventListener('error', (e) => errors.push(String(e.message)));
const gameConfig = createGameConfig();
gameConfig.scene = [MenuScene, GameScene, SurfaceScene];
const game = new Phaser.Game(gameConfig);
window.game = game;
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
async function waitFor(fn, tries = 260, everyMs = 100) {
for (let i = 0; i < tries; i++) {
const v = fn();
if (v) return v;
await sleep(everyMs);
}
return null;
}
try {
const menu = await waitFor(() => { const m = game.scene.getScene('MenuScene'); return m?.newGameBtn ? m : null; });
if (!menu) throw new Error('menu never booted');
menu.seedValue = 'VESTRA';
menu.startNewGame();
const gs = await waitFor(() => { const g = game.scene.getScene('GameScene'); return g?.ship ? g : null; }, 300);
if (!gs) throw new Error('GameScene never booted');
await sleep(700);
const target = gs.commsTargetFor(gs.planet);
gs.isHomeSystem = false; // PROBE STAGING — the EXPLORE drawer's Job Board slot
gs.startLanding(target);
const ss = await waitFor(() => { const c = game.scene.getScene('SurfaceScene'); return c?.jobBoardWindow ? c : null; }, 300);
if (!ss) throw new Error('surface never booted');
await sleep(600);
ss.startSurface();
await sleep(700);
ss.toggleExplore();
await sleep(1100);
ss.exploreAction('jobBoard');
await sleep(2000);
const win = ss.jobBoardWindow;
if (!win) throw new Error('no job board window');
if (win?.video?.video) { win.video.video.muted = true; win.video.video.play().catch(() => {}); }
const posts = gs.sideQuestPostings(gs.planet?.discoveryName ?? null, false);
const pick = posts[0];
if (!pick) throw new Error('no postings on the board');
win.selectedId = pick.id;
win.refresh();
await sleep(900);
const panelRight = win.geo.rightX + win.geo.rightW;
const snap = (list) =>
list
.filter((o) => o && o.isText === true || (o && typeof o.setText === 'function'))
.map((t) => ({
text: String(t.text ?? '').slice(0, 80),
x: Math.round(t.x),
y: Math.round(t.y),
width: Math.round(t.width),
height: Math.round(t.height),
right: Math.round(t.x + t.width),
overflow: Math.round(t.x + t.width) > Math.round(panelRight) ? `+${Math.round(t.x + t.width - panelRight)}` : null,
wordWrapProp: t.wordWrap ?? null,
styleWordWrap: t.style?.wordWrap ?? null,
}));
const out = {
window: gameConfig.width && { w: win.geo.W, h: win.geo.H },
panel: { rightX: win.geo.rightX, rightW: win.geo.rightW, panelRight, detailPanelY: win.geo.detailPanelY, detailH: win.geo.detailH },
selected: { id: pick.id, category: pick.category, title: pick.title, description: pick.description },
detailContent: snap(win.detailSection.content),
errors: errors.slice(-6),
};
window.__JB = out;
document.title = 'JB-DONE';
} catch (err) {
window.__JB = { stage: 'FAILED', error: String(err?.message ?? err), errors: errors.slice(-6) };
document.title = 'JB-DONE';
}