diff --git a/README.md b/README.md index 49810fc..b78f168 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,8 @@ a decision. partner cursors and map pings. Needs the small Node server in this repo. * No build step, no framework, no external requests. Vanilla JS + canvas. -> **Status:** playable, but a review pass found bugs that are not fixed yet (for example, a placed Firewall cannot be -> sold because selecting it throws). The full list, balance analysis and the plan for the next session are in -> [docs/NEXT.md](docs/NEXT.md). +> **Status:** playable and playtested on desktop and phones. A review pass found more polish issues (mostly phone +> layout and touch precision) that are being worked through; see [docs/NEXT.md](docs/NEXT.md). ## Run it diff --git a/docs/NEXT.md b/docs/NEXT.md index 5f1e110..26e7f41 100644 --- a/docs/NEXT.md +++ b/docs/NEXT.md @@ -16,13 +16,9 @@ Development was paused on purpose before the fix stage. This file is the entry p `npm test` = 80 passing (20 sim + 59 server + 1 balance-table shape test). Verified from a fresh `git clone`. -## KNOWN BUG in the pushed build (fix first, it is two lines) +## Fixed since this was written -**Selecting a placed Firewall throws a TypeError, so walls cannot be sold** (finding `visual-1`, confirmed). -Cause: `renderInfo()` in `public/js/main.js` assumes every tower has 3 levels (`tower.level < 3`), but a wall has one -level, so `statsFor(type, i + 1)` and `def.levels[tower.level].cost` read `levels[1]`, which is `undefined`. Use -`tower.level < def.levels.length` in both places (and for the `up` button / `updateInfoDynamic`). Add an e2e assertion: -build a wall, tap it, tap Sell, check the credits. +* 2026-10-10: selecting a placed Firewall no longer throws (walls can be sold again; e2e scenario `06-select-sell`). ## Suggested order of work diff --git a/e2e/scenarios/06-select-sell.js b/e2e/scenarios/06-select-sell.js new file mode 100644 index 0000000..d3fc12e --- /dev/null +++ b/e2e/scenarios/06-select-sell.js @@ -0,0 +1,49 @@ +// Selecting, upgrading, retargeting and selling every kind of placed tower, including walls (regression: selecting a +// wall used to throw because walls have a single level). +module.exports = async function ({ browser, url: URL }) { + 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: 1100, height: 700 } }); + 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'); + 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 view = () => page.evaluate(() => { const v = NW.app.ctrl.view; return { gold: v.gold, towers: v.towers.map((t) => ({ type: t.type, x: t.x, y: t.y, level: t.level, mode: t.mode })) }; }); + + // wall: build, select, sell (full refund) + await page.click('.tbtn[data-type="wall"]'); + let p = await pt(10, 6); await page.mouse.click(p.x, p.y); + await page.keyboard.press('Escape'); + p = await pt(10, 6); await page.mouse.click(p.x, p.y); await sleep(150); + assert(await page.evaluate(() => NW.app.selTower > 0), 'clicking a placed wall selects it'); + assert((await page.locator('#info').innerText()).includes('Firewall'), 'wall info panel is shown'); + assert(await page.locator('#info [data-act="up"]').count() === 0, 'a wall has no upgrade button'); + const before = (await view()).gold; + await page.click('#info [data-act="sell"]'); await sleep(150); + let v = await view(); + assert(v.towers.length === 0 && v.gold === before + 5, 'selling a wall removes it and refunds it in full'); + + // turret: upgrade to max, cycle targeting, sell at a loss + await page.click('.tbtn[data-type="filter"]'); + p = await pt(12, 5); await page.mouse.click(p.x, p.y); + await page.keyboard.press('Escape'); + await page.mouse.click(p.x, p.y); await sleep(150); + await page.click('#info [data-act="up"]'); await sleep(100); + await page.click('#info [data-act="up"]'); await sleep(100); + v = await view(); + assert(v.towers[0].level === 3, 'turret upgraded to level 3'); + assert(await page.locator('#info [data-act="up"]').isDisabled(), 'upgrade button disabled at max level'); + await page.click('#info [data-act="mode"]'); await sleep(100); + v = await view(); + assert(v.towers[0].mode === 'last', 'target mode cycles first -> last'); + await page.click('#info [data-act="sell"]'); await sleep(150); + v = await view(); + assert(v.towers.length === 0, 'turret sold'); + if (errors.length) throw new Error('console errors:\n' + errors.join('\n')); + console.log('no console errors'); + await ctx.close(); +}; diff --git a/public/js/main.js b/public/js/main.js index 1012572..dd7facb 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -234,7 +234,7 @@ if (!sig) { box.textContent = ''; return; } if (tower) { const def = TD.TOWERS[tower.type], i = tower.level - 1; - const cur = statsFor(tower.type, i), nxt = tower.level < 3 ? statsFor(tower.type, i + 1) : null; + const cur = statsFor(tower.type, i), nxt = tower.level < def.levels.length ? statsFor(tower.type, i + 1) : null; let kv = ''; cur.forEach((row, k) => { const n = nxt && nxt[k] && nxt[k][1] !== row[1] ? ' → ' + nxt[k][1] + '' : ''; @@ -242,7 +242,7 @@ }); if (tower.type !== 'wall') kv += '