Class SaveDataBuilder
A utility class for serializing and deserializing structured data in a more custom way. Useful to pass as ref between different components.
public class SaveDataBuilder : IDisposable
- Inheritance
-
SaveDataBuilder
- Implements
- Inherited Members
Constructors
SaveDataBuilder(bool)
public SaveDataBuilder(bool isEmbedded = true)
Parameters
isEmbedded
bool
SaveDataBuilder(string, bool, bool)
Constructs a new SaveDataBuilder
public SaveDataBuilder(string filePath, bool alertErrs = false, bool useCurrentSaveSlot = true)
Parameters
filePath
stringthe file path to use
alertErrs
boolWhether or not to print out errors on failure. Defaults to false
useCurrentSaveSlot
boolWhether or not to use the root save slot ("user://")
Fields
_alertErrs
private readonly bool _alertErrs
Field Value
_data
private Dictionary _data
Field Value
- Dictionary
_filePath
private readonly string _filePath
Field Value
_isEmbedded
private readonly bool _isEmbedded
Field Value
_useCurrentSlot
private readonly bool _useCurrentSlot
Field Value
Properties
Iterator
public IEnumerable<KeyValuePair<string, string>> Iterator { get; }
Property Value
Keys
public IEnumerable<string> Keys { get; }
Property Value
Methods
Append(SaveDataBuilder, string)
public void Append(SaveDataBuilder childBuilder, string subKey)
Parameters
childBuilder
SaveDataBuildersubKey
string
GetBool(string)
Parses out a bool value from the given key, returning the default value on failure.
public bool GetBool(string key)
Parameters
key
stringthe key to search for
Returns
- bool
the value stored, else the default value
GetBool(string, out bool)
Parses out a bool value from the key and outputs the value, returning whether or not parsing was successful.
public bool GetBool(string key, out bool value)
Parameters
Returns
- bool
true if parsing was successful, false if not
GetFloat(string)
Parses out a float value from the given key, returning the default value on failure.
public float GetFloat(string key)
Parameters
key
stringthe key to search for
Returns
- float
the value stored, else the default value
GetFloat(string, out float)
Parses out a float value from the key and outputs the value, returning whether or not parsing was successful.
public bool GetFloat(string key, out float value)
Parameters
Returns
- bool
true if parsing was successful, false if not
GetInt(string)
Parses out a int value from the given key, returning the default value on failure.
public int GetInt(string key)
Parameters
key
stringthe key to search for
Returns
- int
the value stored, else the default value
GetInt(string, out int)
Parses out a int value from the key and outputs the value, returning whether or not parsing was successful.
public bool GetInt(string key, out int value)
Parameters
Returns
- bool
true if parsing was successful, false if not
GetString(string)
Parses out a string value from the given key, returning the default value on failure.
public string GetString(string key)
Parameters
key
stringthe key to search for
Returns
- string
the value stored, else the default value
GetString(string, out string)
Parses out a string value from the key and outputs the value, returning whether or not parsing was successful.
public bool GetString(string key, out string value)
Parameters
Returns
- bool
true if parsing was successful, false if not
GetVector2(string)
Parses out a Vector2 value from the given key, returning the default value on failure.
public Vector2 GetVector2(string key)
Parameters
key
stringthe key to search for
Returns
- Vector2
the value stored, else the default value
GetVector2(string, out Vector2)
Parses out a Vector2 value from the key and outputs the value, returning whether or not parsing was successful.
public bool GetVector2(string key, out Vector2 value)
Parameters
key
stringthe key to search for
value
Vector2the value passed out as an out variable
Returns
- bool
true if parsing was successful, false if not
GetVector3(string)
Parses out a Vector3 value from the given key, returning the default value on failure.
public Vector3 GetVector3(string key)
Parameters
key
stringthe key to search for
Returns
- Vector3
the value stored, else the default value
GetVector3(string, out Vector3)
Parses out a Vector3 value from the key and outputs the value, returning whether or not parsing was successful.
public bool GetVector3(string key, out Vector3 value)
Parameters
key
stringthe key to search for
value
Vector3the value passed out as an out variable
Returns
- bool
true if parsing was successful, false if not
LoadEmbedded(string)
public SaveDataBuilder LoadEmbedded(string subKey)
Parameters
subKey
string
Returns
LoadFromFile()
Loads the necessary data from file
public SaveDataBuilder LoadFromFile()
Returns
- SaveDataBuilder
returns this calling save datat builder. Constructing a new one when failing to load
PutBool(string, bool)
Stores a bool value
public void PutBool(string key, bool value)
Parameters
PutFloat(string, float)
Stores a float value
public void PutFloat(string key, float value)
Parameters
PutInt(string, int)
Stores an Int value
public void PutInt(string key, int value)
Parameters
PutString(string, string)
Stores a string value
public void PutString(string key, string value)
Parameters
PutVariant(string, Variant)
public void PutVariant(string key, Variant value)
Parameters
key
stringvalue
Variant
PutVector2(string, Vector2)
Stores a Vector2 value
public void PutVector2(string key, Vector2 value)
Parameters
key
stringthe key in the data (must be unique)
value
Vector2the value to assign
PutVector3(string, Vector3)
Stores a Vector3 value
public void PutVector3(string key, Vector3 value)
Parameters
key
stringthe key in the data (must be unique)
value
Vector3the value to assign
SaveToFile()
Writes out all data to disk using the parameters specified at construction.
public void SaveToFile()
Explicit Interface Implementations
IDisposable.Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
void IDisposable.Dispose()