orbit/dev/scene-restart-probe.mjs

37 lines
1.7 KiB
JavaScript

import Phaser from '../js/vendor/phaser.js';
import { ConfigLoader } from '../js/config/ConfigLoader.js';
import { config } from '../js/config/Config.js';
import { createGameConfig } from '../js/config/GameConfig.js';
import { GameScene } from '../js/scenes/GameScene.js';
const data = await ConfigLoader.load();
config.init(data);
globalThis.__ORBIT_DEV_SEED = 'PROBE';
const gameConfig = createGameConfig();
gameConfig.scene = [GameScene];
if (typeof Phaser !== 'undefined') Phaser.NoAudioContext = true;
const game = new Phaser.Game(gameConfig);
const out = { steps: [] };
window.__PROBE__ = out;
const tick = (ms) => new Promise((r) => setTimeout(r, ms));
const until = async (fn, label, budgetMs) => {
const t0 = Date.now();
while (Date.now() - t0 < budgetMs) {
if (fn()) return true;
await tick(250);
}
out.steps.push(`TIMEOUT: ${label}`);
return false;
};
game.events.once('ready', async () => {
const s = game.scene.getScene('GameScene');
if (!await until(() => game.scene.isActive('GameScene') && s.ship && s.commsPanel, 'boot', 180000)) { window.__PROBE__ = out; return; }
out.steps.push('booted: ship=' + s.ship.x + ' gates=' + (s.systemContent?.gates?.length ?? 'n/a'));
s.scene.start('GameScene');
await until(() => !game.scene.isActive('GameScene'), 'shutdown', 120000);
out.steps.push('shutdown observed');
const up = await until(() => game.scene.isActive('GameScene') && s.ship && s.commsPanel && s.mineralHud, 'reboot', 240000);
out.steps.push('reboot ok=' + up + ' active=' + game.scene.isActive('GameScene') + ' ship=' + !!s.ship + ' hud=' + !!s.mineralHud + ' minerals=' + (s.ship && s.ship.minerals));
out.steps.push('pageErrors=' + JSON.stringify((window.__PAGE_ERRORS__ || []).slice(0, 6)));
window.__PROBE__ = out;
});