towerdef/e2e/scenarios/10-content.js
Claude 28502984ec Co-op robustness, audio/a11y, new towers and enemies, Uplink rebalance
Co-op (QA'd with two to three real browsers, TCP-proxy chaos scenarios):
- partner's tower changes are never dropped after a render stall or snapshot burst
- half-open connections show "reconnecting" in ~6 s instead of 45-65 s
- upgrade and next-wave are idempotent (stale commands refused), restart message,
  promoted host gets Play again, failed joins never kill a live game, listener leaks

Audio / keyboard / a11y:
- one Audio element per track, fade/stinger supersede tokens, play() retry on the
  next gesture, 5 s fallback to the synth, mute works everywhere, dialogs with
  role/aria-modal/focus handling, accessible names for sound/speed/pause

New content:
- enemies: Daemon (healer), Proxy (regenerating shield), Botnet (flyer swarm);
  waves weave them in from wave 9 (waves 1-8 unchanged)
- towers: Sandbox (stun pulse), Load Balancer (fire-rate aura); hotkeys 1-9
- glyphs/shapes, stun/heal effects, gallery e2e that pixel-checks every kind

Orbital Uplink rebalanced after playtesting (was affordable by wave ~6 and buyable
in bulk from boss rewards): 1500 credits, upgrades 1200/2000/3200, and every Uplink
already owned makes the next one 25% dearer to buy AND to upgrade (each tower
remembers its multiplier, carried in the tower list as a 9th field). Shared
TD.priceFor/upgradePrice so the UI shows exactly what the sim charges.

Also: tablet/foldable viewports in the layout matrix (tolerant colour check),
docs (README tower/enemy tables, PROTOCOL shield/stun/pm encodings, NEXT roadmap).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tb8pW2KAN4oFkh1aK1BfD8
2026-10-10 21:18:43 +00:00

80 lines
5.4 KiB
JavaScript

// New content in a real browser game: nine towers on keys 1-9 (Sandbox 7, Load Balancer 8, Orbital Uplink 9), a Sandbox and a
// Load Balancer that can be built, selected and sold, the wave preview flagging botnet flyers, and the new enemy kinds
// (Daemon, Proxy, Botnet) running through the renderer without a page error.
module.exports = async function ({ browser, url: URL, out: OUT }) {
const assert = (c, m) => { if (!c) throw new Error('ASSERT: ' + m); console.log('ok -', m); };
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
const errors = [];
const ctx = await browser.newContext({ viewport: { width: 1280, height: 800 } });
const page = await ctx.newPage();
page.on('pageerror', (e) => errors.push('pageerror: ' + e.message));
page.on('console', (m) => { if (m.type() === 'error') errors.push('console.error: ' + m.text()); });
await page.goto(URL); await sleep(300);
await page.click('#btnSolo'); await sleep(200); await page.click('#btnHelpClose'); await sleep(200);
const box = await page.locator('#board').boundingBox();
const pt = async (cx, cy) => { const r = await page.evaluate(([a, b]) => NW.app.renderer.cellToScreen(a, b), [cx, cy]); return { x: box.x + r.x, y: box.y + r.y }; };
const sim = (fn, arg) => page.evaluate(fn, arg);
// palette: one tile per tower in table order, a unique key 1-9 on each
const pal = await page.evaluate(() => ({
order: TD.TOWER_ORDER.slice(),
tiles: [...document.querySelectorAll('#palette .tbtn')].map((b) => b.dataset.type),
keys: TD.TOWER_ORDER.map((t) => TD.TOWERS[t].key),
}));
assert(JSON.stringify(pal.tiles) === JSON.stringify(pal.order), 'the palette shows every tower in order: ' + pal.tiles.join(','));
assert(pal.order.length === 9 && new Set(pal.keys).size === 9 && pal.keys.join('') === '123456789', 'nine towers, unique hotkeys 1-9');
assert(pal.order[6] === 'sandbox' && pal.order[7] === 'balancer' && pal.order[8] === 'uplink', 'Sandbox 7, Load Balancer 8, Orbital Uplink 9');
// hotkeys select the new towers
for (const [key, type] of [['7', 'sandbox'], ['8', 'balancer'], ['9', 'uplink'], ['3', 'ids']]) {
await page.keyboard.press(key); await sleep(80);
assert(await page.evaluate(() => NW.app.selType) === type, `key ${key} arms ${type}`);
}
await page.keyboard.press('Escape');
// build a Sandbox, a Load Balancer and an IDS next to it
await sim(() => { NW.app.ctrl.sim.gold = 100000; });
const build = async (key, cx, cy) => { await page.keyboard.press(key); await sleep(60); const p = await pt(cx, cy); await page.mouse.click(p.x, p.y); await sleep(120); };
await build('7', 9, 5);
await build('8', 9, 6);
await build('3', 10, 6);
await page.keyboard.press('Escape');
await sleep(300);
let v = await sim(() => NW.app.ctrl.sim.towers.map((t) => ({ type: t.type, x: t.x, y: t.y, buff: t.buff })));
assert(v.length === 3 && v.some((t) => t.type === 'sandbox') && v.some((t) => t.type === 'balancer'), 'sandbox, balancer and ids were built');
const ids = v.find((t) => t.type === 'ids');
assert(ids.buff > 0, `the Load Balancer boosts the IDS next to it (buff ${ids.buff})`);
// select the Sandbox: info panel, upgrade, sell
let p = await pt(9, 5); await page.mouse.click(p.x, p.y); await sleep(200);
let info = await page.locator('#info').innerText();
assert(/Sandbox/.test(info), 'selecting the Sandbox shows its info panel');
await page.click('#info [data-act="up"]'); await sleep(200);
assert(await sim(() => NW.app.ctrl.sim.towers.find((t) => t.type === 'sandbox').level) === 2, 'the Sandbox upgrades');
const g0 = await sim(() => NW.app.ctrl.sim.gold);
await page.click('#info [data-act="sell"]'); await sleep(200);
assert((await sim(() => NW.app.ctrl.sim.gold)) > g0 && !(await sim(() => NW.app.ctrl.sim.towers.some((t) => t.type === 'sandbox'))), 'selling the Sandbox refunds credits and removes it');
p = await pt(9, 6); await page.mouse.click(p.x, p.y); await sleep(200);
assert(/Load Balancer/.test(await page.locator('#info').innerText()), 'selecting the Load Balancer shows its info panel');
await page.keyboard.press('Escape');
// the wave preview flags the flyers of wave 14 (botnet swarm)
await sim(() => { NW.app.ctrl.sim.wave = 13; });
await sleep(400);
const nw = await page.evaluate(() => ({ text: document.getElementById('nextwave').innerText, air: !!document.querySelector('#nextwave .tag.air'), titles: [...document.querySelectorAll('#nextwave .e')].map((e) => e.title) }));
assert(/Botnet/.test(nw.text) && nw.air && nw.titles.includes('Botnet (flies)'), 'wave 14 preview lists the botnet swarm and the AIR tag: ' + nw.text.replace(/\s+/g, ' '));
// run the new kinds through the renderer
await sim(() => {
const s = NW.app.ctrl.sim; s.wave = 14;
for (let i = 0; i < 3; i++) s.spawnQ.push({ t: s.time + i * 0.3, k: 'proxy', wave: 14 }, { t: s.time + i * 0.3 + 0.1, k: 'daemon', wave: 14 }, { t: s.time + i * 0.1, k: 'botnet', wave: 14 });
s.spawnQ.sort((a, b) => a.t - b.t);
});
await sleep(2500);
const kinds = await sim(() => [...new Set(NW.app.ctrl.sim.monsters.map((m) => m.kind))].sort());
assert(['botnet', 'daemon', 'proxy'].every((k) => kinds.includes(k)), 'proxy, daemon and botnet are on the board: ' + kinds.join(','));
await page.screenshot({ path: OUT + 'content-1-new-enemies.png' });
await sleep(2500);
assert(errors.length === 0, 'no page errors: ' + errors.join(' | '));
await ctx.close();
};