// La Condor nel browser vero: dal Taglia al campone delle poste, mira, fiato trattenuto e tiro col mouse e col dito. // npm run browser:condor — schermate in /tmp/regolo-condor. import { chromium } from 'playwright'; import { mkdirSync } from 'node:fs'; import assert from 'node:assert/strict'; import { staticServer } from './helpers.mjs'; import { ARGS } from './chromium.mjs'; const out = process.env.OUT ?? '/tmp/regolo-condor'; mkdirSync(out, { recursive: true }); const server = await staticServer(); let browser; const errors = []; try { browser = await chromium.launch({ args: ARGS }); for (const [name, mobile, viewport] of [['desktop', false, { width: 1280, height: 860 }], ['touch', true, { width: 844, height: 390 }]]) { const page = await browser.newPage({ viewport, hasTouch: mobile, isMobile: mobile }); page.on('pageerror', e => errors.push(e.message)); await page.goto(`http://127.0.0.1:${server.port}/`); await page.click('#splash'); await page.click('#new-game'); await page.click('#rione [data-rione="campomigliaio"]'); await page.click('#skip-intro'); await page.evaluate(async () => { const { settle } = await import('/tests/helpers.mjs'); settle(game); game.go('giardini_poste'); settle(game); game.act('talk', 'taglia'); settle(game); game.choose(game.options().findIndex(o => o.text.startsWith('Taglia! Si fa una gara'))); settle(game); game.choose(game.options().findIndex(o => o.text === 'Seria.')); settle(game); }); await page.waitForSelector('#bocce-controls:not([hidden])'); await page.waitForFunction(async () => (await import('/src/engine/render.js')).hasBackground('assets/closeups/campone-condor.png')); assert.equal(await page.locator('#bocce-throw').textContent(), 'Spara'); assert.ok(await page.locator('#condor-help').isVisible()); assert.ok(!(await page.locator('#bocce-power').isVisible()), 'niente cursore della forza'); await page.waitForTimeout(1200); const box = await page.locator('#scene').boundingBox(), P = (x, y) => [box.x + x / 640 * box.width, box.y + y / 360 * box.height]; if (mobile) await page.touchscreen.tap(...P(98, 138)); else { await page.mouse.move(...P(98, 138)); await page.mouse.click(...P(98, 138)); } assert.equal(await page.evaluate(() => game.closeup.step), 'aim', 'un tocco mira soltanto'); if (mobile) await page.locator('#bocce-throw').tap(); else { await page.mouse.down(); await page.waitForFunction(() => game.closeup.holdTime >= 0.9); await page.screenshot({ path: `${out}/${name}-fiato.png` }); await page.mouse.up(); } await page.waitForFunction(() => game.closeup.left === 11 && game.closeup.step === 'aim', null, { timeout: 10000 }); await page.waitForFunction(() => game.closeup.volo && game.closeup.volo.t > 0.8, null, { timeout: 15000 }); await page.screenshot({ path: `${out}/${name}-dopo.png` }); await page.close(); } assert.deepEqual(errors, []); console.log(`ok: schermate in ${out}`); } finally { await browser?.close(); server.kill(); }