72 lines
3.0 KiB
JavaScript
72 lines
3.0 KiB
JavaScript
/**
|
|
* Visual probe for a screenshot (headless brave, via dev/cdp-shot.mjs): boots the game, lands, opens the shop, reveals the
|
|
* buy/sell panel — then sets window.__SHOT_READY__ so the driver captures
|
|
* the moment the trade screen (and its upper-right credits/minerals
|
|
* readout) is on screen.
|
|
*
|
|
* /opt/brave.com/brave/brave --headless --disable-gpu --remote-debugging-port=9333 about:blank &
|
|
* node dev/server.mjs 8127
|
|
* node dev/cdp-shot.mjs http://127.0.0.1:8127/dev/shop-hud-shot.html \
|
|
* /tmp/shop-hud.png 'window.__SHOT_READY__ && (r = window.__SHOT_READY__, r) && true' 90000
|
|
*/
|
|
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';
|
|
import { SurfaceScene } from '../js/scenes/SurfaceScene.js';
|
|
|
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
|
|
const data = await ConfigLoader.load();
|
|
config.init(data);
|
|
const gameConfig = createGameConfig();
|
|
gameConfig.scene = [GameScene, SurfaceScene];
|
|
const game = new Phaser.Game(gameConfig);
|
|
window.game = game;
|
|
|
|
(async () => {
|
|
let gs = null;
|
|
for (let i = 0; i < 300; i++) {
|
|
gs = game.scene?.getScene('GameScene') ?? null;
|
|
if (gs && gs.ship) break;
|
|
await sleep(100);
|
|
}
|
|
if (!gs || !gs.ship) { window.__SHOT_READY__ = { error: 'no GameScene' }; return; }
|
|
|
|
// The probe drives the trade panel on the home world — lift the TRADE gate
|
|
// (the 'Special Delivery' capital-landing witness) so Buy/Sell is live.
|
|
gs.story.capitalLanded = true;
|
|
|
|
// A known ledger + cargo so the SELL grid has filled bays.
|
|
const goods = config.get('goods.goods', []);
|
|
gs.ship.credits = 10000;
|
|
gs.ship.minerals = 37;
|
|
gs.ship.cargo.add([goods[0].id, goods[1].id]);
|
|
|
|
gs.startLanding(gs.commsTargetFor(gs.planet));
|
|
await sleep(300);
|
|
const ss = game.scene.getScene('SurfaceScene');
|
|
if (!ss) { window.__SHOT_READY__ = { error: 'no SurfaceScene' }; return; }
|
|
for (let i = 0; i < 120 && ss.sys.getStatus() !== 5; i++) await sleep(250);
|
|
ss.startSurface();
|
|
for (let i = 0; i < 40 && ss.phase !== 'surface'; i++) await sleep(100);
|
|
await sleep(900); // the planet HUD decode
|
|
|
|
ss.toggleShop();
|
|
await sleep(200);
|
|
if (!ss.shopView) ss.buildShopView();
|
|
const sv = ss.shopView;
|
|
if (!sv) { window.__SHOT_READY__ = { error: 'no shopView' }; return; }
|
|
sv.setTab('trade');
|
|
await sleep(900); // the slide-in + the HUD count-up
|
|
|
|
window.__SHOT_READY__ = {
|
|
hud: !!ss.shopHud,
|
|
credits: ss.shopHud?.creditsHud?.label?.text ?? null,
|
|
minerals: ss.shopHud?.mineralHud?.label?.text ?? null,
|
|
creditsPos: ss.shopHud ? { x: Math.round(ss.shopHud.creditsHud.label.x), y: Math.round(ss.shopHud.creditsHud.label.y) } : null,
|
|
mineralsPos: ss.shopHud ? { x: Math.round(ss.shopHud.mineralHud.label.x), y: Math.round(ss.shopHud.mineralHud.label.y) } : null,
|
|
};
|
|
})().catch((err) => { window.__SHOT_READY__ = { error: String(err && err.message || err) }; });
|