Skip to content

SaveUpgrade

namespace Griff.Runtime;
public sealed class SaveUpgrade

A game saved by an earlier version of the game, as an ISaveUpgrader is handed it before it’s read: its scene and the scenes it remembers as the scene file has them (entities by name, components by their saved type name, values by property name), and its flags, to change as this version needs. Scripts’ own fields are there too, by name: a component’s in its Fields, the plain objects they hold in Objects and the systems scripts added in Systems. What’s left as it was is read as usual: values of properties and fields that are gone are ignored, new ones keep their defaults, and a component whose type is gone is kept as it was saved, with a warning.

public int CurrentVersion { get; }

The game’s SaveVersion now, which it’s being brought up to.

public IList<string> Flags { get; }

The flags set when it was saved, by name, to add to, take from or rename.

public IReadOnlyDictionary<string, JsonObject> RememberedScenes { get; }

The scenes it remembers as they were left (see RememberScene), by name, as Scene is.

public JsonObject Scene { get; }

The saved scene’s JSON, as a scene file has it, for changes the other members don’t cover.

public string Slot { get; }

The slot it’s saved in.

public int Version { get; }

The game’s SaveVersion when it was saved: 0 for one saved before the game had one.

public IReadOnlyList<SavedData> Components(string type)

Every component saved as type (its saved name: a script’s class name, or a built-in’s such as “Griff.Health”), in the scene and the scenes it remembers, to read and change by property name.

public IReadOnlyList<SavedData> Objects(string type)

The plain objects of class type (its full name: “Contract”, or “Factory.Contract” in a namespace) that scripts’ fields hold, each’s fields to read and change by name (see Fields).

public int RemoveComponent(string type)

Forgets every component of type type. How many there were.

public int RenameClass(string from, string to)

Saves every plain object and system of class from as to instead: a class renamed in code (a FormerNameAttribute on the class does this too). How many there were.

public int RenameComponent(string from, string to)

Saves every component of type from as to instead: a script class renamed in code (a FormerNameAttribute on the class does this for every scene and save). How many there were.

public int RenameEntity(string from, string to)

Renames every entity called from. How many there were.

public IReadOnlyList<SavedData> Systems(string type)

The fields of the system of class type a script added (one at most), to read and change by name.