orbit/dev/comms-trestle-hold.mjs

79 lines
3.3 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.

/**
* Dev-only: HOLD Trestle's intro comm open (no ACK) for a clean
* screenshot — the pair armed through the REAL discovery path
* (the first non-home world — the quest's own witness), the box live
* (video rolling, text decoded, button armed + pulsing).
*
* node dev/cdp-shot.mjs "http://127.0.0.1:3000/dev/comms-trestle-hold.html" out.png \
* "window.__trestleHold" 90000 "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();
const shipped = data.comms;
data.comms = { ...shipped, comms: (shipped?.comms ?? []).filter((c) => c.trigger === 'firstWorld') };
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);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 : null;
});
if (!ready) { report.textContent = 'FAIL — scene never ready'; window.__trestleHold = { ok: false }; return; }
const planet = (s().systemPlanets ?? [])[0];
if (!planet) { report.textContent = 'FAIL — no planet'; window.__trestleHold = { ok: false }; return; }
// The real arm: the FIRST non-home world discovered — the quest's own
// witness (discoveredWorldCount). Tick the ledger first, exactly like
// discovery.check does, then celebrate.
s().discovery.bySystem.get(s().systemRecord.id)?.add(planet.discoveryId);
s().celebrateDiscovery({
id: planet.discoveryId,
x: planet.x,
y: planet.y,
radius: planet.radius,
name: planet.discoveryName,
typeLabel: 'Rocky World',
});
const up = await until(() => {
const sc = s();
return sc.comms.active && sc.comms.current?.id === 'trestle-meetup' && sc.comms.box?.video && sc.comms.box?._decFinished === true ? sc : null;
}, 30000);
if (!up) { report.textContent = 'FAIL — trestle-meetup never came up'; window.__trestleHold = { ok: false }; return; }
const box = s().comms.box;
// Catch a visible pulse phase for the shot.
await until(() => (box?._ringA?.alpha ?? 0) > 0.5, 4000);
const el = box.video?.video;
window.__trestleHold = {
ok: true,
box: { x: box.x, y: box.y, w: box.W, h: box.H },
clip: el ? { paused: el.paused, muted: el.muted, loop: el.loop, src: (el.currentSrc ?? '').split('/').pop() } : null,
voice: s().sound?.isPlaying('comms_au_trestle-intro-01'),
};
report.textContent = 'TRESTLE HOLD: box ' + box.W + '×' + box.H + ' clip=' + (el ? el.currentSrc.split('/').pop() : '—');
}, 600);