97 lines
4.3 KiB
JavaScript
97 lines
4.3 KiB
JavaScript
/**
|
|
* Dev-only: boot GameScene and open the RESEARCH console (depth 80) so a
|
|
* headless screenshot shows the whole feature — left video feed (muted
|
|
* loop), category tabs, the top→down tech tree (Tether Level 1 owned →
|
|
* Level 2 available), the detail readout with the
|
|
* RESEARCH button, and a project started in flight (deck bar + status).
|
|
*
|
|
* node dev/slow-server.mjs 8081 # serves / + /sleep?ms=N
|
|
* firefox --headless --screenshot RESEARCH_SHOT.png \
|
|
* --window-size=1280,720 \
|
|
* "http://127.0.0.1:8081/dev/research-shot.html"
|
|
*
|
|
* The page carries a defer'd <script src="/sleep?ms=7000"> — the `load`
|
|
* event (when --screenshot fires) is held until AFTER the boot, the
|
|
* window open, the research start and the report paint (dev/slow-server).
|
|
* The report (top-left) lists console errors and the research state.
|
|
*/
|
|
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 { GameScene } from '../js/scenes/GameScene.js';
|
|
|
|
const data = await ConfigLoader.load();
|
|
config.init(data);
|
|
|
|
// Capture console errors + uncaught exceptions for the report.
|
|
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)));
|
|
window.addEventListener('unhandledrejection', (e) => errors.push(`rejection: ${e.reason}`));
|
|
|
|
const gameConfig = createGameConfig();
|
|
gameConfig.scene = [GameScene];
|
|
const game = new Phaser.Game(gameConfig);
|
|
window.game = game;
|
|
|
|
// The report lives OUTSIDE the canvas — a DOM <pre> the screenshot can
|
|
// always read (headless canvases don't have to cooperate).
|
|
const report = document.createElement('pre');
|
|
report.id = 'report';
|
|
report.style.cssText = 'position:fixed;left:10px;top:10px;z-index:9999;max-width:70%;margin:0;padding:8px 12px;font:13px/1.5 monospace;color:#eaf6ff;background:rgba(6,20,16,0.92);border:1px solid #1b3a5a;white-space:pre-wrap;';
|
|
document.body.appendChild(report);
|
|
const setReport = (lines) => { report.textContent = (Array.isArray(lines) ? lines : [lines]).join('\n'); };
|
|
setReport('booting…');
|
|
|
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
|
|
async function waitScene() {
|
|
for (let i = 0; i < 100; i++) {
|
|
const s = game.scene.getScene('GameScene');
|
|
if (s && s.ship && s.researchWindow) return s;
|
|
await sleep(100);
|
|
}
|
|
throw new Error('GameScene never booted');
|
|
}
|
|
|
|
try {
|
|
const s = await waitScene();
|
|
setReport(['GAME SCENE BOOTED', errors.length ? errors.slice(0, 3).join('\n') : 'no console errors']);
|
|
await sleep(800); // let the boot settle (dossier decode, deck flicker)
|
|
|
|
// Open the console (the deck RESEARCH button does exactly this).
|
|
s.deckAction('research');
|
|
await sleep(700); // the boot reveal finishes
|
|
|
|
// Start the first researchable project — the window offers Tether L2.
|
|
s.beginResearch('exploration', 'tether_l2');
|
|
await sleep(400);
|
|
|
|
// The report: errors + the research state + the window's paint states.
|
|
const win = s.researchWindow;
|
|
const st = s.researchState;
|
|
const entry = win.trees.get('exploration');
|
|
const nodeStates = entry
|
|
? entry.tree.order.map((id) => `${id}=${win._nodeState(id)}`).join(' ')
|
|
: 'NO TREE';
|
|
const p = st.progress(s.time.now);
|
|
const lines = [
|
|
errors.length === 0 ? 'SMOKE OK — no console errors' : `ERRORS:\n${errors.slice(0, 3).join('\n')}`,
|
|
`window: ${win.openState} · cat=${win.activeCat} · sel=${win.selected ? win.selected.category + '/' + win.selected.id : '—'}`,
|
|
`state: ${st.unlocked.size} unlocked · active=${st.getActive() ? st.getActive().category + '/' + st.getActive().id : '—'}`,
|
|
p ? `progress: ${Math.round(p.fraction * 100)}%` : 'progress: —',
|
|
`nodes: ${nodeStates}`,
|
|
`video: ${win.video ? (win.video.video?.paused ? 'paused' : 'playing') : 'NO SIGNAL'}`,
|
|
];
|
|
setReport(lines);
|
|
window.__RESEARCH_SHOT = { ready: true, lines, errors };
|
|
console.info('research-shot: report painted');
|
|
} catch (err) {
|
|
errors.push(`FATAL: ${err.message}`);
|
|
setReport(['FATAL: ' + err.message, ...errors.slice(0, 3)]);
|
|
window.__RESEARCH_SHOT = { ready: true, fatal: String(err.message), errors };
|
|
console.error('research-shot: fatal', err);
|
|
}
|