village-builder

VB-214: Saves in the page, named by their build

Status: done (2026-11-10) Priority: 2 Size: M Arch: life Phase: implement Design ref: Commands, time steps and views (Saving: Agreed 30 Oct, revised 7 and 8 Nov by Kim); QUESTION_ARCHIVE.md, “VB-077” (30 Oct) and “VB-079” (questions 3 and 8); docs/review-life.md, section 5. Goal: VB-074 saves a run in Node; a player cannot yet keep a game. Save and load in the page: to and from a file, and in the browser keeping the last 3, by hand and when the page is hidden. Each save names the build that made it, and a save from any other build is refused with a message and an easy way to delete it and start a new game (Kim, 30 Oct and 8 Nov). Autosave at the moving round waits for a save under 0.5 s (VB-215). Acceptance criteria:

Implementation (10 Nov 2026): build.py replaces __BUILD_ID__ with the first 10 hex digits of the SHA-256 of the page before the replacement, so the same sources give the same page. src/page/saves.js (in src/page.json after page/notices.js): a save is {build, savedAt, label, save: Sim.save(st)} as gzipped JSON (CompressionStream). IndexedDB village-builder has two stores keyed <scenario>-<seed>-<cols>x<rows>:<slot>: saves holds each slot’s line (label, build, when, size, and what makes the archipelago) and blobs its bytes, so listing never reads the bytes. readSave tells gzip by its magic bytes, else reads plain JSON, and refuses any build but the page’s; a bare Sim.save (from tools/sim.js --save) names no build and is refused as another build’s. Sim.load keeps its format rule. The loader’s build(seed, scenario, size, save) regenerates the world and calls Sim.load in place of Sim.seed; a played pawn is selected in place of the offer to play. tools/sim.js --load unwraps a page save, whatever its build. The simulation does not run while the landing page or the generation screen is up (src/page/speed.js). No module of src/sim and no state changed.

Not built: a confirmation before Delete and Delete archipelago (they act at once); a save begun as the tab closes, not only hides, may not finish; saving while a debug skip runs is refused silently.

Sizes, gzipped (Node, tools/sim.js --save): founders medium at year 1, 0.06 MB (1.30 MB of JSON); populous small at year 5, 1.15 MB (6.06 MB); in the page, populous tiny seed 7 after 30 days 0.25 MB and after 130 days 0.41 MB. At medium-y5 it was 3.9 MB on 5 November, so an archipelago’s four slots are about 16 MB at worst today.

Validation (10 Nov 2026): npm test (86 scripts) and node tests/golden.js pass, and tests/smoke.js, tests/browser.js, tests/browser-mobile.js and tests/browser-speed.js pass run one by one, changed to start from the landing page (as tools/shot.js and tools/village-shot.js). npm run verify as a whole was not run, nor were times taken (VB-260). By hand, once, in real Chromium (node tests/browser-saves.js OUTDIR, which prints and asserts nothing): on populous tiny seed 7 with a played pawn, a save to slot 1 continued after a reload has the same hash of Sim.save, time and played pawn; a file saved and loaded again has the same hash and takes no slot; a save given another build id shows the refusal, and Delete it removes it; Delete archipelago removes that archipelago’s saves only; a file of another build is refused with the message; no console errors. The page file ran a year in node tools/sim.js --load. Not exercised: the auto slot on a hidden page, and Start a new game.