Skip to content

Commit

Permalink
added get_default and reset functions
Browse files Browse the repository at this point in the history
fix #14
fix #13
  • Loading branch information
stoozey committed Dec 29, 2023
1 parent 001240b commit 8b3540b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion scripts/__scr_ssave_util/__scr_ssave_util.gml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function __ssave_string_to_buffer(_string)
function __ssave_encrypt(_json)
{
var _buffer = __ssave_string_to_buffer(_json);
var _encrypted = __ssave_3rdparty_sphinx_encrypt_buffer(_buffer, SSAVE_ENCRYPTION_KEY)
var _encrypted = __ssave_3rdparty_sphinx_encrypt_buffer(_buffer, SSAVE_ENCRYPTION_KEY);
buffer_delete(_buffer);

return _encrypted;
Expand Down
5 changes: 5 additions & 0 deletions scripts/__scr_ssave_value/__scr_ssave_value.gml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ function __ssave_class_value(_name, _type, _defaultValue) constructor
return (__value ?? __defaultValue);
}

static get_default = function()
{
return __defaultValue;
}

static set = function(_value)
{
if (!__is_type(_value))
Expand Down
31 changes: 31 additions & 0 deletions scripts/scr_ssave/scr_ssave.gml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ function SSave(_name = "data", _protection = SSAVE_PROTECTION_DEFAULT) construct
return _valueData.get();
}

///@desc Gets the default value in the ssave
///@param {string} name The name of the value
static get_default = function(_name)
{
var _valueData = __get_value_data(_name);
if (_valueData == undefined)
return __throw_name_doesnt_exist(_name);

return _valueData.get_default();
}

///@desc Updates a value in the ssave
///@param {string} name The name of the value
///@param {any} value The value to be set
Expand All @@ -28,6 +39,26 @@ function SSave(_name = "data", _protection = SSAVE_PROTECTION_DEFAULT) construct
return self;
}

///@desc Resets a value in the ssave to it's default value
///@param {string} name The name of the value
static reset = function(_name)
{
var _default = get_default(_name);
set(_name, _default);
}

///@desc Resets all values in the ssave to their default values
static reset_all = function()
{
var i = 0;
var _names = variable_struct_get_names(__values);
repeat (array_length(_names))
{
var _name = _names[i++];
reset(_name);
}
}

///@desc Adds a new value to the ssave (This is intended to be called inside the constructor, see the demo for example)
///@param {string} name The name of the value
///@param {SSAVE_TYPE} type The type of the value
Expand Down

0 comments on commit 8b3540b

Please sign in to comment.