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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

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.

Notes

shipped production is serving it deploy ab54f53

opened this

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) takes GAMES-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° and sy = (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 soon still gets a building, flagged soon: 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.

Closes #132

1 earlier comment · 1 event
commented

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) takes GAMES-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° and sy = (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 soon still gets a building, flagged soon: 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.

Changes requested — before the latest push

The layout maths reads right and the hand-calculation test is good. Four things to fix in one round:

  1. The last test is sloppy (first fix). town.test.mjs last test imports ./shell.js?town and then sets globalThis.document = orig where orig was never changed, so the restore does nothing. It also leaves window defined for every later test in the process. Capture what you replace and delete globalThis.window afterwards, as shell.test.mjs does, or build the games list another way.
  2. Behaviours with no test that would fail without them. Add tests for: soon carried through; the #888888 default 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 (covers is 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.
  3. 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 what window.PixelTown is, and say in the pull which issue wires it in. Drop project from the exports, since nothing uses it.
  4. Small clean-ups in layout. taken mixes id: keys with plot keys in a single Set. Use two sets (ids, plots). The ring tracker can be plotAt(buildings.length - 1).ring.
commented

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 GAMES test: the last test now saves window and document before it imports shell.js. A finally restores or deletes them, and also deletes globalThis.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 soon carried through and the #888888 default 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: taken is now two sets, ids and plots. The ring tracker is replaced by plotAt(buildings.length - 1).ring.
  • Exports: project is 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.

Approved

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.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs