60 lines
2.4 KiB
JavaScript
60 lines
2.4 KiB
JavaScript
/**
|
||
* Dev-only: HOLD the comms intro open (no ACK) for a clean screenshot of
|
||
* the box in its live state (video rolling, text decoded, button armed).
|
||
* node dev/cdp-shot.mjs "http://127.0.0.1:8090/dev/comms-hold.html" out.png \
|
||
* "window.__commsHold" 60000 "document.getElementById('report')?.remove()"
|
||
*/
|
||
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);
|
||
const gameConfig = createGameConfig();
|
||
gameConfig.scene = [GameScene];
|
||
const game = new Phaser.Game(gameConfig);
|
||
window.game = game;
|
||
|
||
const report = document.createElement('pre');
|
||
report.id = 'report';
|
||
report.style.cssText = 'position:fixed;left:10px;top:10px;z-index:9999;margin:0;padding:8px 12px;font:12px/1.5 monospace;color:#eaf6ff;background:rgba(6,20,16,0.9);border:1px solid #1b3a5a;max-width:50%;';
|
||
document.body.appendChild(report);
|
||
|
||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
||
const until = async (fn, ms = 30000) => {
|
||
const t0 = Date.now();
|
||
for (;;) {
|
||
const v = fn();
|
||
if (v) return v;
|
||
if (Date.now() - t0 > ms) return null;
|
||
await sleep(150);
|
||
}
|
||
};
|
||
|
||
setTimeout(async () => {
|
||
const s = () => game.scene.getScene('GameScene');
|
||
const ready = await until(() => {
|
||
const sc = s();
|
||
return sc && sc.ship && sc.comms && sc.comms.active && sc.comms.box?.video ? sc : null;
|
||
});
|
||
if (!ready) { report.textContent = 'FAIL — comm never came up'; window.__commsHold = { ok: false }; return; }
|
||
// Let the text finish decoding + the clip settle, then signal.
|
||
await until(() => (s().comms.box._decFinished === true), 8000);
|
||
await sleep(700);
|
||
const sc = s();
|
||
const box = sc.comms.box;
|
||
const el = box.video?.video;
|
||
window.__commsHold = {
|
||
ok: true,
|
||
box: { x: Math.round(box.x), y: Math.round(box.y), w: box.W, h: box.H },
|
||
clip: el ? { paused: el.paused, muted: el.muted, t: el.currentTime?.toFixed(1) } : null,
|
||
voice: sc.comms._voiceKey ? sc.sound.isPlaying(sc.comms._voiceKey) : null,
|
||
};
|
||
report.textContent = 'COMMS HOLD: box ' + box.W + '×' + box.H +
|
||
' @ ' + Math.round(box.x) + ',' + Math.round(box.y) +
|
||
' · clip ' + (el ? (el.paused ? 'PAUSED' : 'rolling') : '—') +
|
||
' · voice ' + (sc.comms._voiceKey ? 'talking' : 'done');
|
||
}, 600);
|