diff --git a/scripts/__scr_ssave_util/__scr_ssave_util.gml b/scripts/__scr_ssave_util/__scr_ssave_util.gml index 62cda24..f64bfd0 100644 --- a/scripts/__scr_ssave_util/__scr_ssave_util.gml +++ b/scripts/__scr_ssave_util/__scr_ssave_util.gml @@ -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; diff --git a/scripts/__scr_ssave_value/__scr_ssave_value.gml b/scripts/__scr_ssave_value/__scr_ssave_value.gml index beb4f17..bff2b0e 100644 --- a/scripts/__scr_ssave_value/__scr_ssave_value.gml +++ b/scripts/__scr_ssave_value/__scr_ssave_value.gml @@ -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)) diff --git a/scripts/scr_ssave/scr_ssave.gml b/scripts/scr_ssave/scr_ssave.gml index 7a19f67..688bdb7 100644 --- a/scripts/scr_ssave/scr_ssave.gml +++ b/scripts/scr_ssave/scr_ssave.gml @@ -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 @@ -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