/**
* Сравнительный просмотр с v1 (трек 21): те же участки мира, что снимает
* v1/apps/game/tools/compare-shot.mjs — герой в одном и том же тайле, день
* 10:00, снимок в файл. Тайлы участков общие (карты v2 конвертированы 1:1).
*
* node v2/apps/game/tools/compare-shot.mjs --dir /tmp
* → /tmp/cmp_v2_meadows.png, cmp_v2_ponds.png, ... (5 сегментов)
*/
import { fileURLToPath } from 'node:url';
import { AgentClient, launchBrowser, startDevServer } from '@rpg/engine/tools/agent-lib.mjs';
const dir = process.argv[process.argv.indexOf('--dir') + 1] ?? '/tmp';
const port = 5312;
const server = startDevServer({ port, cwd: fileURLToPath(new URL('../', import.meta.url)) });
try {
await server.waitReady;
const browser = await launchBrowser();
try {
const page = await browser.newPage();
const pageErrors = [];
page.on('pageerror', (e) => pageErrors.push(String(e)));
await page.goto(`http://localhost:${port}/`, { waitUntil: 'domcontentloaded', timeout: 60000 });
await page.waitForFunction('window.__beacon === true', { timeout: 60000 });
await new Promise((r) => setTimeout(r, 1200));
const client = new AgentClient(page);
// Страница стартует в меню; дальше — ручной режим, день 10:00, без пепла.
await client.call('startGame', false);
await client.call('setManual', true);
await client.call('setAsh', false);
await client.call('setFauna', false);
await client.call('setClock', 600);
const shot = async (name, area, tile) => {
await client.call('gotoArea', area, tile);
await client.call('stepTicks', 10); // ручной режим: кадр рендерится только тут
const path = `${dir}/cmp_v2_${name}.png`;
await client.screenshot(path);
console.log(`снимок: ${path}`);
};
// Тайлы те же, что в v1-сценарии: спавн лугов, entry прудов, колодец
// Звенца, дом Ирвина, резонатор рощи.
await shot('meadows', 'meadows', { x: 16, y: 28 });
await shot('ponds', 'ponds', { x: 4, y: 4 });
await shot('zvenets', 'zvenets', { x: 16, y: 14 });
await shot('house_elder', 'house_elder', { x: 5, y: 7 });
await shot('rust_grove', 'rust_grove', { x: 24, y: 16 });
const errs = pageErrors;
if (errs.length) console.error('pageerror:', errs.slice(0, 3));
} finally {
await browser.close();
}
} catch (e) {
console.error(e);
process.exit(1);
}
process.exit(0); // chromium-хэндлы держат event loop — выходим явно