Fix: placed Firewalls can be selected and sold again
renderInfo assumed every tower has three levels; walls have one, so selecting a wall threw. Use each tower's own level count and add an e2e scenario that selects, upgrades, retargets and sells every kind of tower. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tb8pW2KAN4oFkh1aK1BfD8
This commit is contained in:
parent
72c49eee1f
commit
10bd6f1b04
4 changed files with 57 additions and 13 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
49
e2e/scenarios/06-select-sell.js
Normal file
49
e2e/scenarios/06-select-sell.js
Normal file
|
|
@ -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();
|
||||
};
|
||||
|
|
@ -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] ? ' <span class="up">→ ' + nxt[k][1] + '</span>' : '';
|
||||
|
|
@ -242,7 +242,7 @@
|
|||
});
|
||||
if (tower.type !== 'wall') kv += '<div class="kvp"><span>Targets</span><span>' + targetsText(def) + '</span></div>';
|
||||
const sellVal = def.refund ? tower.spent : Math.floor(tower.spent * TD.SELL_RATIO);
|
||||
const upCost = tower.level < 3 ? def.levels[tower.level].cost : null;
|
||||
const upCost = tower.level < def.levels.length ? def.levels[tower.level].cost : null;
|
||||
const owner = ctrl.kind === 'remote' && ctrl.players.length > 1;
|
||||
const ownerP = owner ? ctrl.players.find((p) => p.slot === tower.owner) : null;
|
||||
box.innerHTML =
|
||||
|
|
@ -254,7 +254,7 @@
|
|||
'<button type="button" data-act="sell" class="danger"><svg class="ic"><use href="#i-trash"/></svg>Sell <span class="cost">' + sellVal + '</span></button></div>' +
|
||||
'<div class="byline">' + (tower.type === 'wall' ? '' : '<span id="infoKills"></span>') + (ownerP ? '<span class="dot" style="background:' + NW.SLOT_COLORS[ownerP.slot] + '"></span><span id="infoOwner"></span>' : '') + '</div></div>';
|
||||
box.querySelector('.nm').textContent = def.name;
|
||||
box.querySelector('.lv').textContent = tower.type === 'wall' ? '' : 'Level ' + tower.level + ' / 3';
|
||||
box.querySelector('.lv').textContent = tower.type === 'wall' ? '' : 'Level ' + tower.level + ' / ' + def.levels.length;
|
||||
box.querySelector('.desc').textContent = def.desc;
|
||||
if (ownerP) box.querySelector('#infoOwner').textContent = 'Built by ' + ownerP.name;
|
||||
NW.drawIcon(box.querySelector('canvas'), tower.type, tower.level);
|
||||
|
|
@ -277,7 +277,7 @@
|
|||
const k = $('infoKills'); if (k) k.textContent = t.kills + (t.kills === 1 ? ' kill' : ' kills');
|
||||
const def = TD.TOWERS[t.type];
|
||||
const up = $('info').querySelector('[data-act="up"]');
|
||||
if (up && t.level < 3) up.disabled = app.ctrl.view.gold < def.levels[t.level].cost;
|
||||
if (up && t.level < def.levels.length) up.disabled = app.ctrl.view.gold < def.levels[t.level].cost;
|
||||
}
|
||||
$('info').addEventListener('click', (e) => {
|
||||
const btn = e.target.closest('button[data-act]'); if (!btn || !app.selTower) return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue