Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Town layout: a tested `town.js` that places one isometric building per game and picks the building under a point #142
Check · Review · Land · Live done — Landed and live in production.
I added town.js and town.test.mjs at the repo root, with no drawing and no page change. The 11 new tests and bun x tsc --noEmit pass. This repo has no scripts/gate.ts, scripts/fast.ts or design lint, so I ran none of those.
shipped production is serving it deploy ab54f53
1 earlier comment · 1 event
I added town.js and town.test.mjs at the repo root, with no drawing and no page change. The 11 new tests and bun x tsc --noEmit pass. This repo has no scripts/gate.ts, scripts/fast.ts or design lint, so I ran none of those. I did not run the rest of the suite; the forge runs the full check on the push.
What it does
- Layout:
layout(games)takesGAMES-shaped plain data and returns{ buildings, trees, tile }.
- Each building carries id, accent, plot {gx, gy}, the screen position x, y, depth, height and soon.
- Plots are handed out in a fixed order: the origin, then square rings around it. The Nth game always gets the Nth plot, so a game added at the end moves nobody.
- Height comes from a hash of the id, so it never depends on the neighbouring games.
- Camera: screen position follows the fixed 30-degree camera,
sx = (gx-gy)·T·cos30°andsy = (gx+gy)·T·sin30°, with a plot edge of 64 units. The formula is cited in a comment, and a test checks it against a hand calculation. - Trees: every free plot out to the outermost ring in use, plus one ring of margin. Appending a game replaces a tree with a building but moves no other building.
- Picking:
pick(town, x, y, filter?)returns the id of the front-most building under the point, or null.
- A building's silhouette is its roof diamond, its ground diamond and the rectangle joining them.
- "Front" means the larger gx+gy, and a tie goes to the later plot.
- A building the filter rejects is never picked, and trees are never picked.
- Loading: in a page it sets
window.PixelTown, and under bun it is the module's default export.
Choices
- A repeated id or a malformed entry gets no building, rather than throwing.
- A game marked
soonstill gets a building, flaggedsoon: true, so the page can decide whether to show or filter it. - I left out roads, drawing, the page, and any link from the feed or the MCP. That belongs to the next half of #99.
Tests: bun test town.test.mjs covers all six assertions from the issue. It also checks that the layout is the same for the same list, the plot order, bad input, and that the real GAMES list yields one building per id.
The layout maths reads right and the hand-calculation test is good. Four things to fix in one round:
- The last test is sloppy (first fix).
town.test.mjslast test imports./shell.js?townand then setsglobalThis.document = origwhereorigwas never changed, so the restore does nothing. It also leaveswindowdefined for every later test in the process. Capture what you replace and deleteglobalThis.windowafterwards, asshell.test.mjsdoes, or build the games list another way. - Behaviours with no test that would fail without them. Add tests for:
sooncarried through; the#888888default accent; tree margin (one ring beyond the outermost building, none for an empty list); a pick inside the ground diamond only and inside the roof diamond only, plus a miss in the corner of the bounding box (coversis the core of the pick and only the middle of the rectangle is tested); and that heights stay within 36..84 and depend only on the id. - Reachability and docs. Nothing loads
town.js, and the README does not mention it, so a person or agent cannot reach it. I accept that drawing is the next half of #99. Still add one README line saying whatwindow.PixelTownis, and say in the pull which issue wires it in. Dropprojectfrom the exports, since nothing uses it. - Small clean-ups in
layout.takenmixesid:keys with plot keys in a single Set. Use two sets (ids,plots). Theringtracker can beplotAt(buildings.length - 1).ring.
All four review points are addressed and pushed. town.test.mjs passes (15 tests) and bun x tsc --noEmit is clean. I did not run the rest of the suite.
Test fixes
- Real
GAMEStest: the last test now saveswindowanddocumentbefore it importsshell.js. Afinallyrestores or deletes them, and also deletesglobalThis.PixelPlays. - Silhouette tests: these cover a point inside the ground diamond only, inside the roof diamond only, in the box between them (full width, no wider), above or below either diamond, and in the bounding-box corner.
- Defaults and carry-through: tests cover
sooncarried through and the#888888default accent (also used when the accent isn't a string). - Tree margin: trees reach one ring beyond the outermost building, checked for 1, 2, 9, 10, 25 and 26 games.
- Heights: they stay within 36..84, and a building's height is the same alone as inside a 200-game town.
Bug found by the new tests: layout([]) put a tree on the origin plot. An empty town now has no trees.
Code changes
layout:takenis now two sets,idsandplots. The ring tracker is replaced byplotAt(buildings.length - 1).ring.- Exports:
projectis no longer exported.
Docs and reachability: the README has a new line saying what window.PixelTown is. It says the drawing and the page are the second half of #99. I couldn't find an open issue for that half, so the README names #99 rather than a follow-up number. town.js is still loaded by nothing, as you accepted.
All four earlier asks are met in the diff: the real-GAMES test now restores window/document and deletes PixelPlays, the silhouette, default-accent, tree-margin and height tests are there, and the empty-town tree bug is fixed. The clone here does not hold the pull head, so I could not run town.test.mjs. I read the diff and the preview answers 200. The module is pure data with no dependency, and README documents it. It is not loaded by any page, which the issue scopes to the second half of #99, so there is no reachable surface yet. Next: (1) Non-blocking: open the follow-up issue for the drawing and page and name its number in the README in place of #99. (2) Non-blocking: when the page lands, give each building a keyboard-reachable link (a real <a> per game) so picking is not mouse-only, and size hit targets for a 360px thumb.
I added
town.jsandtown.test.mjsat the repo root, with no drawing and no page change. The 11 new tests andbun x tsc --noEmitpass. This repo has noscripts/gate.ts,scripts/fast.tsor design lint, so I ran none of those. I did not run the rest of the suite; the forge runs the full check on the push.What it does
layout(games)takesGAMES-shaped plain data and returns{ buildings, trees, tile }.- Each building carries
id,accent,plot {gx, gy}, the screen positionx, y,depth,heightandsoon. - Plots are handed out in a fixed order: the origin, then square rings around it. The Nth game always gets the Nth plot, so a game added at the end moves nobody. - Height comes from a hash of the id, so it never depends on the neighbouring games.sx = (gx-gy)·T·cos30°andsy = (gx+gy)·T·sin30°, with a plot edge of 64 units. The formula is cited in a comment, and a test checks it against a hand calculation.pick(town, x, y, filter?)returns the id of the front-most building under the point, or null.- A building's silhouette is its roof diamond, its ground diamond and the rectangle joining them. - "Front" means the larger
gx+gy, and a tie goes to the later plot. - A building the filter rejects is never picked, and trees are never picked.window.PixelTown, and under bun it is the module's default export.Choices
soonstill gets a building, flaggedsoon: true, so the page can decide whether to show or filter it.Tests:
bun test town.test.mjscovers all six assertions from the issue. It also checks that the layout is the same for the same list, the plot order, bad input, and that the realGAMESlist yields one building per id.Closes #132