Skip to main content

Module save

Module save 

Source
Expand description

Every value a game keeps between runs: what an earlier run stored, and whatever this one has saved over it.

A game names its save keys as one vocabulary through #[derive(Saves)], and reads and writes them with saved and save. A read always returns: the stored value where a run stored one, and the key’s own fallback where none did, so a first run needs no pass that stores the defaults. A value the store kept that no longer reads as the key’s value returns that fallback too, with a debug log.

A vocabulary holds one of four kinds of value — a whole number, a number, a flag, or text — and every key in it keeps that kind; keys of another kind need a vocabulary of their own.

Writes are kept through a frame’s ticks and its own calls, and stored once the frame ends, and only where something changed. The store is the platform’s own, per title: the file beside the one the bindings are kept in on the desktop, and the browser’s own storage on the web. A game run through the offscreen session keeps nothing and reads the fallbacks. Nothing drops a key; a game writes the value the next read should return.

Traits§

SaveKey
One thing a game keeps between runs, named by a vocabulary of its own.
SaveValue
Save key value types: bool, i64, f64 or String, and nothing else.
Saves
Trait every save vocabulary implements, written by Saves.