Forget every LevelValue, i.e., on a level change
Forget a SessionValue's value. SessionValue.clear() calls this.
Look up a LevelValue's value, making it with initial the first time.
Look up a SessionValue's value. SessionValue.get() calls this; user
code shouldn't need to. The first time, the value is made with initial.
The SessionValue
The function that makes the value
Load saved data from persistent storage. Persistent storage can only hold plain data: numbers, strings, booleans, arrays, and plain objects made of those.
The recommended way to use it is to load once, at the start of the game,
into a SessionValue, and then work with the session value:
class Progress { best = 0; unlocked = 1; }
const PROGRESS = new SessionValue("progress", () => stage.storage.loadPersistent("progress", new Progress()));
defaults is used when nothing has been saved. When something has been
saved, each field that defaults has is replaced by the saved value, but
only if the saved value is the same kind of thing (a number for a number,
and so on). Anything else that was saved is ignored. That means that old
or damaged saves can't put the wrong kind of thing in your fields, and a
field that you add in a later version simply gets its default.
The name that the data was saved under
An object with every field that you want, set to what it should be if nothing was saved
defaults, with the saved values filled in
Save plain data to persistent storage, to be there the next time the game is played.
It only saves plain data. If the data holds a function, a Map, a Set,
or anything else that can't be saved, this throws.
The name to save the data under
The object to save
Replace a LevelValue's value. LevelValue.set() calls this.
Replace a SessionValue's value. SessionValue.set() calls this.
StorageDevice provides three key/value stores