Game.SaveInfo
Assembly: Assembly-CSharp
Namespace: Game.Assets
Type: class
Base: IJsonWritable, IContentPrerequisite
Summary: Represents metadata and lightweight runtime data for a saved game (city). Contains display and identification fields (id, displayName, path), gameplay summary (cityName, population, money, xp, simulationDate, gameMode), save-related data (saveGameData, metaData, sessionGuid, lastModified, isReadonly, cloudTarget, locked, autoSave), content prerequisites and enabled mods, and a preview asset. Implements custom JSON writing via IJsonWritable and participates in content prerequisite checks via IContentPrerequisite. Serialization and decoding are customized using attributes such as DecodeAlias and Exclude.
Fields
private (none)
No private fields are declared in this class. All stored values are exposed via public auto-properties.
Properties
-
public TextureAsset preview { get; set; }
Preview image asset for the save. Has a DecodeAlias("previewAsset") for decoding. When writing JSON, preview is serialized via preview.ToUri(MenuHelpers.defaultPreview). -
public string theme { get; set; }
UI/theme identifier used for the save. -
public string cityName { get; set; }
Name of the city in the save. -
public int population { get; set; }
City population count snapshot. -
public int money { get; set; }
Player money at time of save. -
public int xp { get; set; }
Experience points recorded for the save. -
public SimulationDateTime simulationDate { get; set; }
Simulation date/time snapshot for the save. -
public Dictionary<string, bool> options { get; set; }
Dictionary of game options/flags saved with the save. When serialized it is written as an IReadOnlyDictionary. -
public string[] contentPrerequisites { get; set; }
Array of required content IDs; has DecodeAlias("contentPrerequisite") to map older key names during decoding. -
public string mapName { get; set; }
Name/identifier of the map used by this save. -
public SaveGameData saveGameData { get; set; }
Reference to the detailed save game data structure (large binary/game-state container). -
public string[] modsEnabled { get; set; }
List of enabled mod IDs at the time of the save. When serialized, null is written as an empty array. -
public string id { get; set; }
[Exclude] Save identifier. Marked with [Exclude], meaning it is excluded from some decode paths (attribute usage depends on the custom deserializer), but note that Write still explicitly emits this field. -
public string displayName { get; set; }
[Exclude] User‑facing save name. Marked [Exclude] (same caveat as above) but is written by the Write method. -
public string path { get; set; }
[Exclude] Filesystem/cloud path for the save. Marked [Exclude], but written out by Write. -
public bool isReadonly { get; set; }
[Exclude] Readonly flag for the save (e.g., when stored from read-only sources). Marked [Exclude] but still written by Write. -
public string cloudTarget { get; set; }
[Exclude] Cloud storage target identifier. Marked [Exclude] but is written by Write. -
public DateTime lastModified { get; set; }
[Exclude] Timestamp of the last modification. Marked [Exclude], but Write serializes this using ISO 8601 round-trip format (ToString("o")). -
public bool autoSave { get; set; }
Whether this save is an autosave. -
public SaveGameMetadata metaData { get; set; }
[Exclude] Additional metadata for the save; marked [Exclude] (commonly internal). -
public Guid sessionGuid { get; set; }
GUID identifying the game session that produced the save. -
public bool locked { get; set; }
[Exclude] Whether the save is locked (internal flag). Write does emit this field as well. -
public string gameMode { get; set; }
Identifier of the game mode used in the save.
Constructors
public SaveInfo()
No explicit constructors are declared in code — the default parameterless constructor is used. Use the default constructor to create an instance, then populate desired properties before using Write or Copy.
Methods
public void Write(IJsonWriter writer)
Serializes the SaveInfo into JSON using a provided IJsonWriter. The method:- Writes a type begin marker using the concrete type full name.
- Emits properties including id, displayName, path, preview (as a URI via preview.ToUri(MenuHelpers.defaultPreview)), theme, cityName, population, money, xp, simulationDate, options (as IReadOnlyDictionary), locked, mapName, lastModified (ISO 8601), isReadonly, cloudTarget, autoSave, modsEnabled (writes empty array if null), gameMode, and contentPrerequisites.
-
Ends the type block. Note: Some properties carry [Exclude] attributes but are still explicitly written by this method; attributes affect decoding behavior rather than this explicit writer.
-
public SaveInfo Copy()
Creates and returns a shallow copy of this SaveInfo with the following specifics: - Primitive and reference fields are copied by assignment.
- options is deep-copied into a new Dictionary
if not null. - contentPrerequisites is cloned into a new string[] if not null.
- saveGameData, metaData, modsEnabled and other reference types are copied by reference (not deep-cloned). Use Copy when you need an independent options array/dictionary but don't require full deep copies of complex referenced data.
Usage Example
// Create and populate a SaveInfo
var save = new SaveInfo {
id = "save_001",
displayName = "My City",
path = "Saves/MyCity.sav",
cityName = "My City",
population = 12000,
money = 250000,
xp = 300,
simulationDate = new SimulationDateTime(/* ... */),
options = new Dictionary<string, bool> { { "traffic", true }, { "dayNight", false } },
contentPrerequisites = new[] { "DLC.RIVER", "ASSET_BRIDGE_01" },
mapName = "GreenValley",
autoSave = false,
sessionGuid = Guid.NewGuid(),
gameMode = "Sandbox",
preview = someTextureAssetReference
};
// Write SaveInfo to a JSON writer
using (var writer = /* obtain IJsonWriter implementation */) {
save.Write(writer);
}
// Create a copy if you want to mutate options without changing the original
var copy = save.Copy();
copy.options["traffic"] = false;
Additional notes: - DecodeAlias attributes (e.g., "previewAsset" and "contentPrerequisite") indicate how older or alternate JSON keys map to current properties when decoding. - The [Exclude] attribute is used to mark properties that typically are not included by automatic decode/encode paths; however, Write explicitly emits many of those fields for compatibility with the game's save listing format. - Copy performs a shallow copy for most fields; take care if you need deep clones of saveGameData or metaData.