Changes

Jump to navigation Jump to search
Line 103: Line 103:  
The WriteDictionary is powerful, in that it has no limitations on the data you can save, but '''please note that any custom classes saved using this method ''has'' to have an empty constructor'''. If you want some fields not to be serialized, use the '''[System.NonSerialized]''' attribute. Properties are not serialized, so you need to create backing fields. Saving custom classes from your mod will also break saves if the mod is no longer installed, so it's best to avoid when you can.
 
The WriteDictionary is powerful, in that it has no limitations on the data you can save, but '''please note that any custom classes saved using this method ''has'' to have an empty constructor'''. If you want some fields not to be serialized, use the '''[System.NonSerialized]''' attribute. Properties are not serialized, so you need to create backing fields. Saving custom classes from your mod will also break saves if the mod is no longer installed, so it's best to avoid when you can.
   −
When you want to save data, populate the WriteDictionary with values in the '''Serialize''' method, this will then be returned when a save is loaded in the '''Deserialize''' method. If you wanted to save a setting you can write '''data["Notifications"] = true''' and load it back with '''Notifications = data.Get("Notifications", true)'''
+
When you want to save data, override and populate the WriteDictionary with values in the '''Serialize(WriteDictionary data, GameReader.LoadMode mode)''' method, this will then be returned when a save is loaded in the '''Deserialize(WriteDictionary data, GameReader.LoadMode mode)''' method. If you wanted to save a setting you can write '''data["Notifications"] = true''' and load it back with '''Notifications = data.Get("Notifications", true)'''
    
There is also a '''LoadMode''' parameter, which tells you whether it was a full save, a build mode save or a company save (Usually used when the player is moving to another map or during multiplayer synchronization), which will allow you to only save data needed for each type. E.g. you probably don't have to save player preferences for a build mode save.
 
There is also a '''LoadMode''' parameter, which tells you whether it was a full save, a build mode save or a company save (Usually used when the player is moving to another map or during multiplayer synchronization), which will allow you to only save data needed for each type. E.g. you probably don't have to save player preferences for a build mode save.

Navigation menu