Public: anyone can read this; the crew can change it.

forked from trevato/cs

The shooter's entry sheds its last concept: the menu's map, plan and link become their own module #409

Merged opened this

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

Merged

The menu's map logic now lives in its own module, `src/client/chooser.ts`, which reads which map the menu is asking for, what it's called, its link and when its plan gets drawn. After all three extractions, **`src/client/main.ts` is 1,749 lines**, down 90 in this pull from the 1,839 on `main`. That's more than the 1,215 in the issue thread because rooms, radio, the daily match and the planner land…

shipped production is serving it deploy ae07c2d

opened this

The menu's map logic now lives in its own module, src/client/chooser.ts, which reads which map the menu is asking for, what it's called, its link and when its plan gets drawn. After all three extractions, src/client/main.ts is 1,749 lines, down 90 in this pull from the 1,839 on main. That's more than the 1,215 in the issue thread because rooms, radio, the daily match and the planner landed on main while the extractions were in flight.

What moved. The new module takes the three controls' values (Map select, Map name field, Match id field) as plain strings, plus a clock reading and a source of ids. It returns plain data:

  • The map: the choice, its name and its link, and whether the "not a map name" sentence shows.
  • The id field: what a pasted link rewrites the controls to (null when nothing needs rewriting), the match to play, and whether the "not a match id" sentence shows.
  • The plan: when it is due (PLAN_WAIT, 200 ms, moved here), and never while a match runs.
  • Levels and links: the level to build at Play and for the plan, and the link on the played map's name.

src/mapname.ts is still the only map-name grammar and preview.ts is still the only drawing. main.ts keeps the fields, the elements and the plan canvas.

Behaviour. It should be identical:

  • Precedence: a typed map name beats the select, a pasted link of ours rewrites both controls first, and the id field is written back only when a link was taken apart. That last point means a keystroke never resets the caret.
  • Id drawing: a match id is still drawn only for generated, and only when the menu names it.
  • Building levels: levelOf builds named maps with map.ts's own levelNamed instead of repeating its DE_FORGE check. That keeps the level.test.ts rule that only map.ts and main.ts name DE_FORGE, and it produces the same levels.

Tests. src/client/chooser.test.ts checks the module directly:

  • the 200 ms wait and when a plan is due;
  • the precedence and the de_forge fallback for junk;
  • that ids are drawn only when needed;
  • the cells of a named map;
  • the link on the played map's name;
  • the three kinds of link that are not believed.

In main.test.ts, two tests were trimmed to their wiring, since the module test now covers the cells check and the loop over rejected links. SETTLE is now derived from PLAN_WAIT. No test was changed because it was wrong. bun run test passes (typecheck plus 1,698 tests), and the app boots and answers 200 on /.

Bundle. app.js went from 137,757 raw / 53,497 gzip bytes to 138,106 / 53,681 (+349 / +184, the cost of passing the control values as small objects). It stays under the 140,500 / 54,500 ceilings, and no ceiling moved.

What main.ts still holds. It isn't down to one concept, and there is no fourth issue for that:

  • the room session wiring (join, make, side, room link);
  • the frame loop, pause, fullscreen and pointer handling;
  • the end-of-match summary;
  • the radio and planner hand-offs;
  • the atlas painting;
  • the match-of-the-day button.

The room wiring is the clearest next seam if someone wants it.

Where to look. In the preview, pick generated and check the line above Play names the map before Play. Type gen_14u5j6g a character at a time: the plan appears once, after you stop typing. Paste <origin>/?match=<id>&map=gen_14u5j6g into the Match id field and both controls should fill.

#215 is still open against this block; whichever lands second should rebase rather than re-decide.

🤖 Generated with Claude Code

Closes #252

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs