# 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)

- **Space:** game-dev-web-public (https://github.com/Tech-Realm/space-game-dev-web-public/tree/main/versioned-save-games)
- **Level:** L1 (as the registry reports it)
- **Keys it needs (names only):** none
- **Tools:** node
- **Routes:** node-local; checks: 1
- **Uses:** new (no recorded use yet)
- **Install:** `logicpacks pack use game-dev-web-public/versioned-save-games` or MCP `get_pack game-dev-web-public/versioned-save-games`
- **Files:** CHANGELOG.md, code/save.mjs, code/save.test.mjs, outcome/EVIDENCE.md, outcome/checks.yaml, outcome/results.json, pack.yaml, spec/SPEC.md, spec/source.md

## Purpose (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.



---

Canonical URL: https://logicpacks.io/packs/game-dev-web-public/versioned-save-games

Developed by TechRealm (techrealm.online), the software team. Operated by Al Jash Trading (Establishment), Abu Dhabi, since 1994, the legal entity that hosts and is responsible for the service. Economic licence CN-1030597, Abu Dhabi Registration Authority. Address: Office 5, Bani Yas West 4, Bani Yas, Abu Dhabi, UAE. Website: https://aljashtrading.com. Contact: hello@logicpacks.io, security@logicpacks.io, WhatsApp +1 713 632 2262 (https://wa.me/17136322262).

Machine-readable index: [/llms.txt](/llms.txt). Plain facts: [/about.md](/about.md). Safety: [/safety.md](/safety.md).
