SaveRules beta
Interface of @v12-engine/engine
export interface SaveRulesHow a game's saves outlive its patches (Rules.saves). Any change to a game's rules changes which rules they are exactly (registry.hash), and most changes are nothing to a save: a number tuned, a bug fixed. A game that declares this loads such a save as it is. A change a save cannot be read through (a unit type renamed, a component of another shape) takes a new version, and a step that brings the saves made before up to it
Members
migrate
migrate?: Record<number, SaveMigration> | ((save: WorldSave, from: number, to: number) => WorldSave | void);What brings an older save up to date. A step for each version, by the version it starts from ({ 3: … } makes a save of version 3 one of version 4), run one after the other; or one function for all of it, told the version the save is of and the one it is to be of. A save of a version with no step after it is refused, saying so: a version with nothing to change has the step (save) => save
onMismatch
onMismatch?: 'load' | 'refuse' | ((save: WorldSave, hash: string) => 'load' | 'refuse');What becomes of a save of the game's version made with other rules, its code, its numbers or its mods having changed since: load it as it is, refuse it, or a function that says which, given the save and the hash of the rules now. load when left out
version
version?: number;The version of what the game keeps in a save: a whole number from 1, and 1 when left out. One more with every patch that saves made before have to be changed for, together with the step that changes them (migrate). A save says which it is of (WorldSave.version); one of a version newer than the game's is refused