Class SaveHandler
- Namespace
- TinyLife
- Assembly
- Tiny Life.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
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
CreateSerializer(SerializerContext, EventHandler<ErrorEventArgs>, bool)
Creates a new Newtonsoft.Json.JsonSerializer that uses the Newtonsoft.Json.JsonSerializerSettings returned in CreateSerializerSettings(SerializerContext, EventHandler<ErrorEventArgs>, bool).
public static JsonSerializer CreateSerializer(SerializerContext context, EventHandler<ErrorEventArgs> errorHandler = null, bool prettyPrint = false)
Parameters
context
SerializerContextThe context that the serializer will be used for.
errorHandler
EventHandler<ErrorEventArgs>An optional error handler.
prettyPrint
boolWhether the resulting JSON should be pretty-printed.
Returns
- JsonSerializer
A new Newtonsoft.Json.JsonSerializer with some default values set.
CreateSerializerSettings(SerializerContext, 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, EventHandler<ErrorEventArgs> errorHandler = null, bool prettyPrint = false)
Parameters
context
SerializerContextThe context that the serializer settings will be used for.
errorHandler
EventHandler<ErrorEventArgs>An optional error handler.
prettyPrint
boolWhether the resulting JSON should be pretty-printed.
Returns
- JsonSerializerSettings
A new instance of Newtonsoft.Json.JsonSerializerSettings with some default values set.
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.
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
name
stringThe 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
name
string
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.
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, EventHandler<ErrorEventArgs>, bool) or CreateSerializerSettings(SerializerContext, 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, ErrorEventArgs Args, EventPhase Phase)> OnSaveLoadError
Event Type
- EventHandler<(SerializerContext Context, ErrorEventArgs Args, EventPhase Phase)>