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
100 lines
8.8 KiB
JavaScript
100 lines
8.8 KiB
JavaScript
// Small UI states that were broken or missing on phones: toasts under reduced motion (touch-5, visual-6), toasts hidden behind
|
|
// the build bar (visual-5), the static low-integrity cue, the paused state (visual-18), the tappable room chip (visual-4).
|
|
module.exports = async function ({ browser, url: URL, out: OUT }) {
|
|
const failures = [];
|
|
const assert = (c, m) => { if (!c) { failures.push(m); console.log('FAIL -', m); } else console.log('ok -', m); }; // collect every failure (the old code fails several)
|
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
const errors = [];
|
|
const phone = { viewport: { width: 390, height: 844 }, deviceScaleFactor: 2, isMobile: true, hasTouch: true };
|
|
const start = async (opts) => {
|
|
const ctx = await browser.newContext(opts);
|
|
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.evaluate(() => document.getElementById('btnSolo').click()); await sleep(200);
|
|
await page.evaluate(() => document.getElementById('btnHelpClose').click()); await sleep(150);
|
|
return { ctx, page };
|
|
};
|
|
const tryTap = (page, sel) => page.tap(sel, { timeout: 3000 }).then(() => true, () => false); // (the old UI has no such button: fail fast instead of waiting 30 s)
|
|
const rect = (page, sel) => page.evaluate((s) => { const r = document.querySelector(s).getBoundingClientRect(); return { l: r.left, t: r.top, r: r.right, b: r.bottom }; }, sel);
|
|
const overlap = (a, b) => !(a.r <= b.l || a.l >= b.r || a.b <= b.t || a.t >= b.b);
|
|
|
|
// ---- reduced motion: the toast text stays visible, the low-integrity cue is static, and the build bar never hides the toast
|
|
for (const half of ['upper', 'lower']) {
|
|
const { ctx, page } = await start({ ...phone, reducedMotion: 'reduce' });
|
|
await page.evaluate(() => { NW.app.ctrl.sim.gold = 0; });
|
|
await page.evaluate(() => document.querySelector('.tbtn[data-type="filter"]').click());
|
|
const board = await page.locator('#board').boundingBox();
|
|
const cell = await page.evaluate((h) => NW.app.renderer.cellToScreen(h === 'upper' ? 12 : 12, h === 'upper' ? 2 : 13), half);
|
|
await page.touchscreen.tap(board.x + cell.x, board.y + cell.y); await sleep(200); // first tap: preview + build bar
|
|
await tryTap(page, '#btnConfirmBuild'); await sleep(250); // not enough credits -> toast
|
|
const t = await page.evaluate(() => { const e = document.querySelector('.toast'); if (!e) return null; const cs = getComputedStyle(e), r = e.getBoundingClientRect(); return { text: e.textContent, opacity: +cs.opacity, l: r.left, t: r.top, r: r.right, b: r.bottom }; });
|
|
assert(t && /credits/i.test(t.text), `reduced motion (${half} half): toast exists "${t && t.text}"`);
|
|
assert(t && t.opacity > 0.9, `reduced motion (${half} half): toast is visible (opacity ${t && t.opacity})`);
|
|
const bar = await rect(page, '#confirm');
|
|
assert(t && !overlap(t, bar), `${half} half: the toast does not overlap the build bar`);
|
|
// the server (core) stays clear of the toast
|
|
const core = await page.evaluate(() => { const b = NW.app.ctrl.board, p = NW.app.renderer.cellToScreen(b.core.x, b.core.y), bb = document.getElementById('board').getBoundingClientRect(), s = NW.app.renderer.cellSizePx() * 0.6; return { l: bb.left + p.x - s, r: bb.left + p.x + s, t: bb.top + p.y - s, b: bb.top + p.y + s }; });
|
|
assert(t && !overlap(t, core), `${half} half: the toast does not cover the server`);
|
|
if (half === 'upper') {
|
|
await page.evaluate(() => { NW.app.ctrl.sim.lives = 3; }); await sleep(300);
|
|
const low = await page.evaluate(() => { const e = document.getElementById('statLives'), cs = getComputedStyle(e); return { cls: e.classList.contains('low'), border: cs.borderTopColor, shadow: cs.boxShadow, anim: cs.animationName }; });
|
|
assert(low.cls && low.border === 'rgb(255, 92, 122)' && low.shadow !== 'none', 'reduced motion: low integrity shows a static red border + glow: ' + JSON.stringify(low));
|
|
}
|
|
await page.screenshot({ path: OUT + `ui-states-toast-${half}.png` });
|
|
await ctx.close();
|
|
}
|
|
|
|
// ---- paused: dimmed board, a resume pill that works, and a pause button that is not a second play triangle
|
|
{
|
|
const { ctx, page } = await start(phone);
|
|
await page.tap('#btnPause'); await sleep(250);
|
|
const p = await page.evaluate(() => ({ paused: NW.app.ctrl.view.paused, tag: !document.getElementById('pausedTag').hidden, tagText: document.getElementById('pausedTag').innerText, stage: document.getElementById('stage').classList.contains('paused'), dim: getComputedStyle(document.getElementById('stage'), '::after').backgroundColor, pressed: document.getElementById('btnPause').getAttribute('aria-pressed'), icon: document.querySelector('#btnPause use').getAttribute('href') }));
|
|
assert(p.paused && p.tag && p.stage && p.pressed === 'true', 'paused: pill shown, stage marked, button pressed ' + JSON.stringify(p));
|
|
assert(/resume/i.test(p.tagText) && p.dim !== 'rgba(0, 0, 0, 0)', 'paused: the board is dimmed and the pill says how to resume');
|
|
assert(p.icon === '#i-pause', 'paused: the pause button keeps its pause icon (the Wave button owns the play triangle)');
|
|
await page.screenshot({ path: OUT + 'ui-states-paused.png' });
|
|
const tapped = await tryTap(page, '#pausedTag'); await sleep(250);
|
|
assert(tapped && await page.evaluate(() => !NW.app.ctrl.view.paused && document.getElementById('pausedTag').hidden), 'tapping the pill resumes');
|
|
await ctx.close();
|
|
}
|
|
|
|
// ---- reconnecting: the whole HUD looks dead (not only the board), apart from the menu and the room chip
|
|
{
|
|
const { ctx, page } = await start(phone);
|
|
await page.evaluate(() => { document.getElementById('reconnect').hidden = false; }); await sleep(250);
|
|
const o = await page.evaluate(() => { const g = (id) => { const cs = getComputedStyle(document.getElementById(id)); return { op: +cs.opacity, pe: cs.pointerEvents }; }; return { app: document.getElementById('app').classList.contains('offline'), wave: g('btnWave'), pause: g('btnPause'), palette: g('side'), menu: g('btnMenu') }; });
|
|
assert(o.app && o.wave.pe === 'none' && o.wave.op < 0.6 && o.palette.pe === 'none' && o.menu.pe !== 'none', 'reconnecting: HUD dims and stops taking taps, the menu stays usable ' + JSON.stringify(o));
|
|
await page.screenshot({ path: OUT + 'ui-states-offline.png' });
|
|
await ctx.close();
|
|
}
|
|
|
|
// ---- the room chip: shows the code, pulses while alone, copies / shares the invite link when tapped
|
|
{
|
|
const ctx = await browser.newContext({ ...phone, permissions: ['clipboard-read', 'clipboard-write'] });
|
|
const page = await ctx.newPage();
|
|
page.on('pageerror', (e) => errors.push('pageerror: ' + e.message));
|
|
await page.goto(URL); await sleep(300);
|
|
await page.evaluate(() => document.getElementById('btnCoop').click()); await sleep(100);
|
|
await page.evaluate(() => document.getElementById('btnCreate').click());
|
|
for (let i = 0; i < 60 && !(await page.evaluate(() => NW.app.inGame && NW.app.ctrl.status === 'joined')); i++) await sleep(100);
|
|
await sleep(300);
|
|
await page.evaluate(() => { if (!document.getElementById('help').hidden) document.getElementById('btnHelpClose').click(); }); await sleep(150); // (a first-time co-op player gets the help too)
|
|
const room = await page.evaluate(() => NW.app.ctrl.room);
|
|
const chip = await page.evaluate(() => { const e = document.getElementById('netChip'), r = e.getBoundingClientRect(); return { text: e.innerText, waiting: e.classList.contains('waiting'), w: r.width, h: r.height, inView: r.left >= 0 && r.right <= innerWidth && r.top >= 0 && r.bottom <= innerHeight }; });
|
|
assert(chip.text.includes(room) && chip.inView && chip.h >= 43.5, `room chip shows ${room}, is on screen and 44px tall (${JSON.stringify(chip)})`);
|
|
assert(chip.waiting, 'room chip pulses while waiting for a partner');
|
|
await page.evaluate(() => { navigator.share = undefined; });
|
|
await tryTap(page, '#netChip'); await sleep(400);
|
|
const toast = await page.evaluate(() => [...document.querySelectorAll('.toast')].map((t) => t.textContent).join('|'));
|
|
assert(/copied/i.test(toast), 'tapping the chip copies the invite link: "' + toast + '"');
|
|
const clip = await page.evaluate(() => navigator.clipboard.readText()).catch(() => '');
|
|
assert(clip.includes('?room=' + room), 'the clipboard holds the invite link: ' + clip);
|
|
await page.evaluate(() => { try { NW.app.ctrl.close(); } catch (e) { /* ignore */ } });
|
|
await ctx.close();
|
|
}
|
|
if (errors.length) throw new Error('console errors:\n' + errors.join('\n'));
|
|
if (failures.length) throw new Error(failures.length + ' UI state checks failed:\n - ' + failures.join('\n - '));
|
|
console.log('no console errors');
|
|
};
|