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

forked from trevato/cs

The round's rules stop being one 553-line file: the economy and the bomb get their own modules, and the digest does not move #113

shipped production is serving it opened this has it
opened this

src/client/world.ts is 553 lines and the largest module in the game: the player and bomb types, spawning, round start and end, the buy rules (priceOf, canBuy, buy), shooting, the bomb's plant, defuse and progress (updateBomb, useProgress), the per-tick update and the aim helpers. Every other concept the shooter has already earned its own file — combat.ts, physics.ts, weapons.ts, match.ts, bots.ts, level.ts — and this repository's bar is a module named after one concept. It is also the file that every queued extraction edits, so being able to read it in one sitting is worth a run of its own.

Done looks like

  • [ ] src/client/economy.ts owns the money: what an item costs a given player, whether they may buy it now, and what buying does to their money and their kit. src/client/bomb.ts owns the objective: carrying, dropping, planting, defusing, the kit's effect, and the progress a readout asks about. world.ts keeps the world — the types, the spawn, the round, the tick — and imports them.
  • [ ] Plain data in, plain data out, and no cycle: the new modules take a world, a player or a level as parameters and neither of them imports world.ts. If a type has to move to make that true, it moves, and the pull says which.
  • [ ] Not one behaviour changes, and the digest proves it: the constants and every per-second checkpoint in src/client/replay.test.ts are unchanged to the byte. A pull that edits one has changed the game by accident.
  • [ ] The bundle barely notices: the app's raw and gzipped size moves by less than a minifier's noise, the number is in the pull, and no ceiling in src/games.ts moves.
  • [ ] Each new module gets the tests for the rules it now owns — moved out of world.test.ts where they exist, written where they do not: armour bought twice is not paid for twice, a buy refused once the round is live, a defuse interrupted and resumed, a kit halving the defuse, a plant that needs the site and not just the bomb.
  • [ ] world.test.ts stays the world's, src/independence.test.ts unchanged in meaning, bun test green, and the shooter still boots headlessly through src/client/main.test.ts with no import site left dangling.

Files I expect to change

src/client/world.ts, src/client/economy.ts and src/client/bomb.ts (new) with their tests, src/client/world.test.ts, the import sites in src/client/main.ts, src/client/hud.ts, src/client/bots.ts and src/rl/arena.ts, and the README's module tour.

Risks

This is churn in the file four other issues are queued on, which is why it waits for the physics move (#62, pull #70) to land rather than racing it. The split has to be along the seams that are already there; if a rule turns out to need the whole world to answer, it stays in world.ts and the pull says which and why. A split that moves the digest is a bug, not a new tuning.

Suggested: Vesper — a mechanical split held by a pinned digest, the shape of #95.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs