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

forked from trevato/cs

The shooter's entry sheds its first concept: the buy panel becomes its own module #250

shipped production is serving it opened this has it
opened this

src/client/main.ts is 1,239 lines — 614 when #181 was written, 910 and 1,068 on the way here — and it is the file almost every pull touches. #181 asked for two extractions at once in that file, and it has sat ready and untaken while the file grew six hundred lines. This is the first of three small, sequenced pulls that do it one seam at a time; the seams are already marked in the file with comment rules.

This one takes the buy panel: main.ts:538-631, the block under // --- the buy menu, rebuilt whenever it opens so the prices are honest.

Done looks like

  • [ ] A module named for the one thing it does — the buy panel: what it is built from (the economy's prices, what a player can afford, what they already carry), what it renders, and what it hands back when something is bought.
  • [ ] Plain data in and out. It takes the panel element, the world or the pieces of it that decide a price, and a callback or a returned intent; it does not reach for the document, the host or anything global.
  • [ ] main.ts keeps only the wiring: find the element, call the module, pass what comes back to the world.
  • [ ] Behaviour is identical to the line: the same prices, the same affordability rules, the same open/close keys, the same panel markup, the same beep on a buy. A test asserts the rendered panel is what it is today for a given world.
  • [ ] The tests move with the code: what src/client/main.test.ts asserts about buying is asserted against the new module, and main.test.ts keeps only what is about wiring.
  • [ ] No bytes worth arguing about: the pull states the bundle before and after, and the ceiling in src/games.ts does not move.

Files I expect to change

A new src/client/buy.ts and its test, src/client/main.ts, src/client/main.test.ts, possibly src/pages/game.ts if the panel's markup belongs beside the rest of the page's.

Risks

  • This is a move, not a rewrite. A behaviour change hidden inside a refactor is the one thing that makes a refactor unreviewable — if something is wrong in there, say so in the pull and leave it wrong, or open an issue for it.
  • Two pulls in this file at once is a conflict for nothing, which is why the other two seams wait for this one.

Suggested: whoever is next in src/client/ — the first of these three is the cheapest hour the repository can buy.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs