Table of Contents

Class DataPath

Namespace
Squiggles.Core.Data
Assembly
SquigglesCommon4X.dll

A utility class used for handling multiple save slots. Different DataPath instances can have different properties and rules.

public class DataPath
Inheritance
DataPath
Inherited Members

Constructors

DataPath(string, bool)

Creates a new DataPath

public DataPath(string sub_dir, bool allow_delete = true)

Parameters

sub_dir string

The path which serves as the root of this data path

allow_delete bool

whether or not this data path allows deletion operations.

Fields

META_DATA_FILE_PATH

private const string META_DATA_FILE_PATH = "save_slot_meta.json"

Field Value

string

_allowDelete

Whether or not this data path allows deletion operations.

private readonly bool _allowDelete

Field Value

bool

_saveSlotMetaData

Any save slot metadata. Helpful for learning more about the save slot in question when presenting multiple slots.

private readonly Dictionary<string, string> _saveSlotMetaData

Field Value

Dictionary<string, string>

Properties

CurrentPath

The path to the current data path. I.e. the root directory to save/load to/from

public string CurrentPath { get; private set; }

Property Value

string

JsonSettings

Settings for JSON Serialization.

public JsonSerializerOptions JsonSettings { get; set; }

Property Value

JsonSerializerOptions

Methods

AddSlotMetaData(string, string)

Assigns a key-value for the metadata of this save slot. Useful for setting identifying information for different save slots. See ISaveSlotInformationProvider for information on how save slot names are generated.

public void AddSlotMetaData(string key, string value)

Parameters

key string
value string

DeleteSaveSlot()

Deletes this save slot and all data within it. Only allowed if _allowDelete is true. This rudimentarily prevents deleting certain save slots (i.e. the root slot) but is not a hard limit because we're programmers. If there's a will and a page on Stack Overflow, life will find a way.

public void DeleteSaveSlot()

EnsureDirectoryPaths(string)

private static void EnsureDirectoryPaths(string file_path)

Parameters

file_path string

GetMetaData(string)

Gets the value of a particular metadata for the given key.

public string GetMetaData(string key)

Parameters

key string

Returns

string

the metadata value, or "" if not found.

LoadDefaultJsonSettings()

private void LoadDefaultJsonSettings()

LoadDict(string, bool)

public Dictionary LoadDict(string path, bool print_errors)

Parameters

path string
print_errors bool

Returns

Dictionary

LoadMetaData()

Loads metadata from disk.

public void LoadMetaData()

LoadText(string, bool)

Loads the full text of a file as a single string.

public string LoadText(string path, bool print_errors)

Parameters

path string

the file path to save (relative from this data path's root), no '/' prefix needed

print_errors bool

Whether or not to print out errors to console when met. Used to handle situations where a file not existing is expected and handled otherwise. Only has an effect in a DEBUG context

Returns

string

the full text of the file as a string. Or null if it failed to load the file.

Load<T>(string, bool)

Loads data from a json file to the serializable class.

public T Load<T>(string path, bool print_errors = true) where T : class

Parameters

path string

The path of a json file relative to the assigned path (likely a save slot)

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.

SaveDict(Dictionary, string, bool, bool)

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

Parameters

dict Dictionary
path string
do_flush bool
print_errors bool

SaveMetaData()

Saves the metadata out to disk.

public void SaveMetaData()

SaveText(string, string, bool, bool)

public void SaveText(string text, string path, bool do_flush = false, bool print_errors = true)

Parameters

text string
path string
do_flush bool
print_errors bool

Save<T>(T, string, bool, bool)

Saves data in JSON format to the specified path

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

Parameters

data T

the serializable class to save

path string

the path relative to the assigned path (likely a save slot)

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.

print_errors bool

Type Parameters

T

inferred type of data

SetJsonSettings(JsonSerializerOptions)

Changes the JsonSerializerOptions for this given DataPath. It affects the way types are serialized into JSON when using that functionality.

public void SetJsonSettings(JsonSerializerOptions options)

Parameters

options JsonSerializerOptions

the new options to set