Newer
Older
rpg / v1 / apps / game / tools / compare-shot.mjs
/**
 * Сравнительный просмотр с v2 (трек 21): те же участки мира, что снимает
 * v2/apps/game/tools/compare-shot.mjs — герой в одном и том же тайле, день
 * 10:00, снимок в файл. Тайлы участков общие (карты v2 конвертированы 1:1).
 *
 *   node v1/apps/game/tools/compare-shot.mjs --dir /tmp
 *   → /tmp/cmp_v1_meadows.png, cmp_v1_ponds.png, ... (5 сегментов)
 */
import { fileURLToPath } from 'node:url';
import { startDevServer, openGame } from './lib.mjs';

const dir = process.argv[process.argv.indexOf('--dir') + 1] ?? '/tmp';

const server = await startDevServer({ port: 5311 });
let ctx = null;
try {
    // Новая игра, врагов спим (мир для снимков), день 10:00.
    ctx = await openGame({ url: server.url, newGame: true });
    const a = ctx.agent;
    await a.command('scene:sleepAll', {});
    await a.command('scene:setTime', { hours: 10 });

    const shot = async (name) => {
        await a.waitFor('!s.transitioning', { timeoutTicks: 600 });
        await new Promise((r) => setTimeout(r, 400)); // дозреть фейду/камере
        const path = `${dir}/cmp_v1_${name}.png`;
        await a.screenshot(path);
        console.log(`снимок: ${path}`);
    };
    const area = (id) => a.waitFor(`s.area === "${id}"`, { timeoutTicks: 1200 });
    const goto = async (id) => {
        const w = await area(id);
        if (!w.ok) throw new Error(`не перешли в «${id}»`);
        await a.waitFor('!s.transitioning', { timeoutTicks: 600 });
    };

    // 1) Луга — стартовая поляна (спавн 16,28).
    await shot('meadows');

    // 2) Пруды: телепорт к тайлу-переходу (2,2), шаг на него.
    await a.command('scene:teleport', { x: 3, y: 2 });
    if (!(await a.walkTo(2, 2, { timeoutTicks: 600 }))) throw new Error('не дошёл до перехода в пруды');
    await goto('ponds');
    await shot('ponds');

    // 3) Звенец: шагом на тропу (54,28), внутри — к колодцу (16,14).
    if (!(await a.walkTo(2, 2, { timeoutTicks: 600 }))) throw new Error('не дошёл до обратного перехода');
    await goto('meadows');
    await a.command('scene:teleport', { x: 53, y: 28 });
    if (!(await a.walkTo(54, 28, { timeoutTicks: 600 }))) throw new Error('не дошёл до тропы в Звенец');
    await goto('zvenets');
    await a.command('scene:teleport', { x: 16, y: 14 });
    await shot('zvenets');

    // 4) Дом Ирвина: подойти к двери (13,12) и нажать действие.
    const near = await a.approach(13, 12, { timeoutTicks: 600 });
    if (near === null) throw new Error('не подошёл к двери дома');
    a.press('interact');
    await goto('house_elder');
    await shot('house_elder');

    // 5) Роща: выход из дома (5,8), тропа (54,20), внутри — к резонатору (24,16).
    if (!(await a.walkTo(5, 8, { timeoutTicks: 600 }))) throw new Error('не вышел из дома');
    await goto('zvenets');
    await a.command('scene:teleport', { x: 53, y: 20 });
    if (!(await a.walkTo(54, 20, { timeoutTicks: 600 }))) throw new Error('не дошёл до выхода в рощу');
    await goto('rust_grove');
    await a.command('scene:teleport', { x: 24, y: 16 });
    await shot('rust_grove');
} catch (e) {
    console.error(e);
    process.exitCode = 1;
} finally {
    if (ctx) await ctx.browser.close();
    server.stop();
}
process.exit(process.exitCode ?? 0);