Table of Contents

Class SaveData

Namespace
Squiggles.Core.Data
Assembly
SquigglesCommon4X.dll

The singleton for handling saving/loading data to/from disk. Also for managing save slots if your game uses them.

public static class SaveData
Inheritance
SaveData
Inherited Members

Fields

SAVE_SLOT_ROOT

private const string SAVE_SLOT_ROOT = "user://save_slot/"

Field Value

string

_defaultDataPath

private static readonly DataPath _defaultDataPath

Field Value

DataPath

Properties

CurrentSaveSlot

An alternate save path pointing towards the current save slot. This can be altered with SetSaveSlot. See also: SetSaveSlot(string)

public static DataPath CurrentSaveSlot { get; private set; }

Property Value

DataPath

Methods

CreateSaveSlotName()

Creates a new save slot name using DateTime.Now. Only returns the string, no changes to the SaveData are made.

public static string CreateSaveSlotName()

Returns

string

A string in to form of "YXXX-MXX-DXX-HXX-mXX-SXX-FXXXX" for the current time which is a valid directory name.

GetKnownSaveSlots()

Checks the root directory of save slots and finds all save slot directories. Meta-data should be collected afterwards.

public static string[] GetKnownSaveSlots()

Returns

string[]

A string array of save slots, sorted alphabetically

HasSaveData()

Determines whether there exists save data for this game. Useful for knowing if this is the first session or not

public static bool HasSaveData()

Returns

bool

Tru if save data exists

LoadDefaultSaveSlot()

Loads the "default" save slot, which coincidentally is named "default"

public static void LoadDefaultSaveSlot()

LoadDict(string, bool)

public static Dictionary LoadDict(string path, bool print_errors)

Parameters

path string
print_errors bool

Returns

Dictionary

LoadMostRecentSaveSlot()

Looks through the save slot directory and finds the most recent save slot (based on save slot directory)

public static void LoadMostRecentSaveSlot()

Load<T>(string, bool)

Loads data from a json file to the serializable class.

[MarkForRefactor("Currently Borked", "")]
public static T Load<T>(string path, bool print_errors = true) where T : class

Parameters

path string

The path of a json file relative to "user://"

print_errors bool

Returns

T

The data of type T that was loaded from file.

Type Parameters

T

data type to load. Must be specified when it cannot be inferred.

ParseSaveSlotName(string)

Parses the DateTime from a save slot directory name. Useful for determining when the save slot was created and not much else.

public static DateTime ParseSaveSlotName(string slot)

Parameters

slot string

The name of the save slot directory

Returns

DateTime

A DateTime set to the time at which the given save slot was created. Assuming it was created with CreateSaveSlotName()

SaveDict(Dictionary, string, bool)

public static void SaveDict(Dictionary dict, string path, bool do_flush = false)

Parameters

dict Dictionary
path string
do_flush bool

Save<T>(T, string, bool)

Saves data in JSON format to the specified path, relative to the root of "user://"

[MarkForRefactor("Currently Borked", "")]
public static void Save<T>(T data, string path, bool do_flush = false) where T : class

Parameters

data T

the serializable class to save

path string

the path relative to "user://"

do_flush bool

Whether or not to force an IO flush. This is typically unnecessary and will cause a small pause in the game. But forcing a flush does prevent loss of data in the case of a crash. So this is recommended for level save data.

Type Parameters

T

inferred type of data

SetJsonSettings(JsonSerializerOptions)

Change the JsonSerializerOptions for the root (non-save slot) SaveData system. This can be used to modify how types are serialized in JSON. Make sure this works for the Squiggles.Core.Data singletons if you want to mess with it.

public static void SetJsonSettings(JsonSerializerOptions options)

Parameters

options JsonSerializerOptions

SetSaveSlot(string)

Sets CurrentSaveSlot to point at a new save slot directory. This will force new files saved to save in that new directory. See also: CurrentSaveSlot

public static void SetSaveSlot(string slot_name)

Parameters

slot_name string

The name of the file slot. Must be valid for a directory name on the host system.