Split The code is public; the app answers only to the crew.

The snapshot, as a value: `saved.ts` says what a match is worth keeping, and refuses anything else #133

shipped merged opened this has it
opened this

Write the one module a resumable match needs — a plain snapshot and a boundary that parses it — and wire nothing.

This is the first third of #71, which was parked when pull #117 closed red: 726 changed lines across seven files, including the middle of world.ts, on a base five merges stale (33775fe), and a conflict in world.ts nobody could cheaply unpick. Nothing in that pull was wrong in kind; it was one run's worth of work three times over. Build it in three, smallest first, each green on its own.

Done looks like:

  • [ ] A new src/client/saved.ts holding a plain snapshot type: rules, matchId, round, score, loss streak, playerTeam, the world seed, the player's name, and per player — money, primary, secondary, armour, helmet, kit, kills, deaths, headshots, damage. Nothing mid-round: no positions, no health, no bomb.
  • [ ] snapshot(world, matchId) builds one from a World and reads nothing else. It imports types from world.ts and changes no line of it.
  • [ ] parseSaved(raw: string | null) is a real boundary, in the shape parseSettings already has: an unknown weapon id, money out of range, the wrong number of players, a matchId that is not the shape the server issues, a blob over a stated byte cap, a number where a string belongs, null, "undefined" and a hostile object with a prototype key all yield null. It never throws.
  • [ ] writeSaved/readSaved/clearSaved hold the one localStorage key and swallow a storage failure exactly as saveSettings does (settings.ts:138) — a private tab is not a reason to stop playing.
  • [ ] saved.test.ts covers the round trip (snapshot → JSON → parse → equal) and one rejection per rule above. Every test fails without the code.
  • [ ] The pull says plainly that nothing calls this yet, and which issue calls it next.

Files: src/client/saved.ts (new), src/client/saved.test.ts (new). Nothing else.

Risks: none to the running app — it is dead code for one merge, which is the point: it is the half that can be tested hardest and reviewed fastest. Keep the type in terms of what world.ts already exports so the next issue does not re-shape it.

Crew: scout — a boundary, plain data in and out, with tests.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs