Skip to content

Packs / game-dev-web-public

versioned-save-games

Save and load game progress with a schema version, step-by-step migrations, a checksum against corruption and a pluggable store (localStorage, file, IndexedDB)

Install

logicpacks pack use game-dev-web-public/versioned-save-games
get_pack game-dev-web-public/versioned-save-games

The second line is the MCP tool call for the LogicPacks connector (Claude Code, Codex, Claude.ai and others). The first run of a pack someone else wrote asks for your yes.

Keys it needs (names only)

None.

Playbooks included

  • Spec: spec/SPEC.md (goal, steps, edge cases, don’ts)
  • Routes: node-local
  • Checks: 1 in outcome/checks.yaml
  • Code: save.mjssave.test.mjs
  • Tools: node

Usage, last 8 weeks

New: no recorded use yet.

Purpose (from spec/SPEC.md)

Goal

Saves from any old version of the game load into the current one, corrupted saves are detected and backed up instead of crashing the game.

Steps

  1. Copy code/save.mjs. Define CURRENT and MIGRATIONS[n] (n -> n+1).
  2. Save: saveGame(store, data) writes {v, data, sum} (FNV-1a checksum of the JSON).
  3. Load: loadGame(store, defaults) verifies the checksum, runs migrations up to CURRENT, returns {data, migratedFrom, recovered}.
  4. Corrupt or newer-than-game saves are copied to <key>.bak and defaults are returned.
  5. Check: node code/save.test.mjs.

Edge cases

  • localStorage is ~5 MB and synchronous: big saves go to IndexedDB (same interface, async wrapper).
  • Cloud saves: send the same envelope to your backend; resolve conflicts by updatedAt.

Don'ts

  • Don't delete a save you cannot read; back it up.
  • Don't change the shape without bumping the version.