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
This commit is contained in:
Claude 2026-10-10 21:18:43 +00:00
parent 962189419a
commit 28502984ec
29 changed files with 3370 additions and 230 deletions

View file

@ -460,6 +460,67 @@ test('upgrade / target / sell / auto / continue go through the same path', async
});
});
test('simultaneous Upgrade from both players: applied once, the second is rejected as stale (sender only), charged once (coop-5)', async () => {
await withServer({}, async (S) => {
const { a, b, room } = await S.pair();
const sim = S.srv.rooms.get(room).sim;
a.c.send({ t: 'cmd', c: 'place', type: 'filter', x: 4, y: 4 });
await a.c.snap((m) => m.tw && m.tw.length === 1);
await b.c.snap((m) => m.tw && m.tw.length === 1);
const gold = sim.gold, cost = TD.TOWERS.filter.levels[1].cost;
// both saw level 1 and pressed Upgrade at the same moment
a.c.send({ t: 'cmd', c: 'upgrade', id: 1, lv: 1 });
b.c.send({ t: 'cmd', c: 'upgrade', id: 1, lv: 1 });
await a.c.barrier(); await b.c.barrier();
assert.equal(sim.towers[0].level, 2, 'level 2, not 3');
assert.equal(sim.gold, gold - cost, 'charged once');
const rejects = [...a.c.of('reject'), ...b.c.of('reject')];
assert.equal(rejects.length, 1, 'exactly one of them was refused');
assert.deepEqual(rejects[0], { t: 'reject', c: 'upgrade', reason: 'stale', id: 1 });
// a client that saw level 2 may continue; a command without lv is still applied (older clients)
a.c.send({ t: 'cmd', c: 'upgrade', id: 1, lv: 2 });
await a.c.snap((m) => m.tw && m.tw[0][4] === 3);
sim.gold = 1000;
a.c.send({ t: 'cmd', c: 'place', type: 'filter', x: 6, y: 4 });
await a.c.snap((m) => m.tw && m.tw.length === 2);
a.c.send({ t: 'cmd', c: 'upgrade', id: 2 });
await a.c.snap((m) => m.tw && m.tw[1][4] === 2);
});
});
test('simultaneous Next wave from both players starts one wave; the other is stale (coop-5)', async () => {
await withServer({}, async (S) => {
const { a, b, room } = await S.pair();
const sim = S.srv.rooms.get(room).sim;
a.c.send({ t: 'cmd', c: 'wave', n: 1 });
b.c.send({ t: 'cmd', c: 'wave', n: 1 });
await a.c.barrier(); await b.c.barrier();
assert.equal(sim.wave, 1, 'one wave, not two');
const rejects = [...a.c.of('reject'), ...b.c.of('reject')];
assert.equal(rejects.length, 1);
assert.deepEqual(rejects[0], { t: 'reject', c: 'wave', reason: 'stale' });
b.c.send({ t: 'cmd', c: 'wave', n: 2 });
await b.c.snap((m) => m.w === 2);
a.c.send({ t: 'cmd', c: 'wave' }); // no number: always the next wave
await a.c.snap((m) => m.w === 3);
});
});
test('"lv" and "n" must be integers when present: anything else is a malformed command, never "stale"', async () => {
await withServer({}, async (S) => {
const { a, room } = await S.pair();
const sim = S.srv.rooms.get(room).sim;
a.c.send({ t: 'cmd', c: 'place', type: 'filter', x: 4, y: 4 });
await a.c.snap((m) => m.tw && m.tw.length === 1);
for (const bad of [{ c: 'upgrade', id: 1, lv: '1' }, { c: 'upgrade', id: 1, lv: 1.5 }, { c: 'wave', n: 'x' }, { c: 'wave', n: {} }]) a.c.send(Object.assign({ t: 'cmd' }, bad));
await a.c.barrier();
assert.equal(sim.towers[0].level, 1); assert.equal(sim.wave, 0);
assert.equal(a.c.of('reject').length, 0, 'not rejected by the sim: dropped as malformed');
for (let i = 0; i < 17; i++) a.c.send({ t: 'cmd', c: 'wave', n: 'x' }); // 4 + 17 = 21 malformed messages
assert.equal((await a.c.closed()).code, 4400);
});
});
test('wave command spawns monsters that appear in snapshots; refused beyond the load cap', async () => {
await withServer({}, async (S) => {
const { a, room } = await S.pair();