Class SaveHandler
- Namespace
- TinyLife
- Assembly
- TinyLife.dll
A utility class used by the game for various actions and information related to saving and loading.
public static class SaveHandler
- Inheritance
-
SaveHandler
- Inherited Members
Fields
StaticJsonConverterMigrations
A set of migrations that get applied when an object using the MigratingStaticJsonConverter<T> is loaded from disk. The passed SaveHandler.StaticMigrationInfo contains the name of the object being loaded, as well as the object that it should be loaded as.
public static readonly List<Migration<SaveHandler.StaticMigrationInfo>> StaticJsonConverterMigrations
Field Value
TypeMigrations
A set of migrations that get applied when a save file is loaded whenever a Type is searched for by name. The passed SaveHandler.TypeMigrationInfo contains the assembly name and type name of the missing type.
public static readonly List<Migration<SaveHandler.TypeMigrationInfo>> TypeMigrations
Field Value
Methods
AddResolvableType(string)
Registers the Type with the given name as resolvable by JSON (de-)serialization using a serializer returned from CreateSerializerSettings(SerializerContext, SerializerUsage, EventHandler<ErrorEventArgs>, bool) and CreateSerializer(SerializerContext, SerializerUsage, EventHandler<ErrorEventArgs>, bool).
As modded types are loaded through reflection, this generally should not be required for mod usage.
public static void AddResolvableType(string name)
Parameters
namestringThe name of the type to register as resolvable.
AddResolvableType(Type)
Registers the given Type as resolvable by JSON (de-)serialization using a serializer returned from CreateSerializerSettings(SerializerContext, SerializerUsage, EventHandler<ErrorEventArgs>, bool) and CreateSerializer(SerializerContext, SerializerUsage, EventHandler<ErrorEventArgs>, bool). As modded types are loaded through reflection, this generally should not be required for mod usage.
public static void AddResolvableType(Type type)
Parameters
typeTypeThe type to register as resolvable.
CreateSerializer(SerializerContext, SerializerUsage, EventHandler<ErrorEventArgs>, bool)
Creates a new Newtonsoft.Json.JsonSerializer that uses the Newtonsoft.Json.JsonSerializerSettings returned in CreateSerializerSettings(SerializerContext, SerializerUsage, EventHandler<ErrorEventArgs>, bool).
public static JsonSerializer CreateSerializer(SerializerContext context, SerializerUsage usages, EventHandler<ErrorEventArgs> errorHandler = null, bool prettyPrint = false)
Parameters
contextSerializerContextThe context that the serializer will be used for.
usagesSerializerUsageThe usage or combined flag ofu sages that the serializer will be used for.
errorHandlerEventHandler<ErrorEventArgs>An optional error handler.
prettyPrintboolWhether the resulting JSON should be pretty-printed.
Returns
- JsonSerializer
A new Newtonsoft.Json.JsonSerializer with some default values set.
CreateSerializerSettings(SerializerContext, SerializerUsage, EventHandler<ErrorEventArgs>, bool)
Creates a new instance of Newtonsoft.Json.JsonSerializerSettings, initialized to some default values for saving and loading Map and, specifically, MapObject instances.
Additionally, an errorHandler can optionally be attached to determine what should happen when a serialization error occurs.
public static JsonSerializerSettings CreateSerializerSettings(SerializerContext context, SerializerUsage usages, EventHandler<ErrorEventArgs> errorHandler = null, bool prettyPrint = false)
Parameters
contextSerializerContextThe context that the serializer settings will be used for.
usagesSerializerUsageThe usage or combined flag ofu sages that the serializer will be used for.
errorHandlerEventHandler<ErrorEventArgs>An optional error handler.
prettyPrintboolWhether the resulting JSON should be pretty-printed.
Returns
- JsonSerializerSettings
A new instance of Newtonsoft.Json.JsonSerializerSettings with some default values set.
GetCustomHouseholdsDir()
Returns a DirectoryInfo pointing to the directory that custom households are loaded from.
public static DirectoryInfo GetCustomHouseholdsDir()
Returns
- DirectoryInfo
The custom households directory.
GetCustomLotsDir()
Returns a DirectoryInfo pointing to the directory that custom lots are loaded from.
public static DirectoryInfo GetCustomLotsDir()
Returns
- DirectoryInfo
The custom lots directory.
GetCustomMapsDir()
Returns a DirectoryInfo pointing to the directory that custom maps are loaded from.
public static DirectoryInfo GetCustomMapsDir()
Returns
- DirectoryInfo
The custom maps directory.
GetGameDir()
Returns a DirectoryInfo that points to the game's data directory. For more information on where this directory is stored, see https://docs.tinylifegame.com/articles/game_dir.html.
public static DirectoryInfo GetGameDir()
Returns
- DirectoryInfo
The game's data directory.
GetModsDir()
Returns a DirectoryInfo pointing to the directory that mods should be put into and loaded from
public static DirectoryInfo GetModsDir()
Returns
- DirectoryInfo
The mod directory
GetSaveBackups(string)
Returns a set of all of the files in the directory of the save with the given name that have the extension ".bak" or ".old".
public static IEnumerable<FileInfo> GetSaveBackups(string name)
Parameters
namestringThe name of the save.
Returns
- IEnumerable<FileInfo>
The backup files.
GetSaveDir(string)
Returns a DirectoryInfo that points to the directory that a save with the given name is or would be stored in.
This method returns a subdirectory of GetSavesDir().
public static DirectoryInfo GetSaveDir(string name)
Parameters
namestring
Returns
- DirectoryInfo
The directory for the given save.
GetSavesDir()
Returns a DirectoryInfo that points to the game's saves directory. This method returns a subdirectory of GetGameDir().
public static DirectoryInfo GetSavesDir()
Returns
- DirectoryInfo
The game's saves directory.
GetScreenshotsDir()
Returns the DirectoryInfo that points to the directory where screenshots are stored.
public static DirectoryInfo GetScreenshotsDir()
Returns
- DirectoryInfo
The screenshots directory.
Events
OnGameLoaded
An event that is raised before and after the game is loaded.
public static event Action<GameImpl, EventPhase> OnGameLoaded
Event Type
OnGameSaved
An event that is raised before and after the game is saved.
public static event Action<GameImpl, EventPhase> OnGameSaved
Event Type
OnSaveDataCreated
An event that is raised when the game's SaveHandler.SaveData is loaded.
public static event Action<GameImpl, SaveHandler.SaveData> OnSaveDataCreated
Event Type
OnSaveDataLoaded
An event that is raised when the game's SaveHandler.SaveData is saved.
public static event Action<GameImpl, SaveHandler.SaveData> OnSaveDataLoaded
Event Type
OnSaveLoadError
An event that is raised when a Newtonsoft.Json.JsonSerializer or Newtonsoft.Json.JsonSerializerSettings created in CreateSerializer(SerializerContext, SerializerUsage, EventHandler<ErrorEventArgs>, bool) or CreateSerializerSettings(SerializerContext, SerializerUsage, EventHandler<ErrorEventArgs>, bool) is used for serialization or deserialization, and an error occurs. This event is a subscription to Newtonsoft.Json.JsonSerializerSettings.Error. If your event handler handles the error gracefully, you should set the argument's Newtonsoft.Json.Serialization.ErrorEventArgs.ErrorContext's Newtonsoft.Json.Serialization.ErrorContext.Handled to true.
public static event EventHandler<(SerializerContext Context, SerializerUsage Usages, ErrorEventArgs Args, EventPhase Phase)> OnSaveLoadError
Event Type
- EventHandler<(SerializerContext Context, SerializerUsage Usages, ErrorEventArgs Args, EventPhase Phase)>