LokSettingsManager¶
Inherits:
The LokSettingsManager class provides simplified ways to manage the LockerPlugin settings.
Description¶
This class is responsible for managing the access of the LockerPlugin’s settings through the use of the ProjectSettings.
The settings of this Plugin stay available in the addons/locker path of the ProjectSettings.
With this class, the settings exposed by the LockerPlugin can be registered, unregistered, set and get from the ProjectSettings.
Version: 1.1.2 Author: Daniel Sousa (github.com/nadjiel <github.com/nadjiel>_)
Property Index¶
Type |
Name |
Default value |
|---|---|---|
:ref:`Script <Script>`[] |
|
|
Dictionary |
|
Method Index¶
Constant Descriptions¶
CONFIG_PATH = "res://addons/locker/config.cfg"¶
The CONFIG_PATH constant stores the path where the LockerPlugin’s configurations should be stored, so that they can be persisted even when the Plugin is deactivated and activated again.
STRATEGY_SCRIPTS_PATH = "res://addons/locker/scripts/access_strategy/default_strategies/"¶
The STRATEGY_SCRIPTS_PATH constant stores the path to where the scripts of LokAccessStrategy as :ref:`LokAccessStrategy <LokAccessStrategy>`s to be used by this plugin.
Property Descriptions¶
Script <Script>`[] _strategy_scripts = ``_load_strategy_scripts()`¶
The _strategy_scripts property stores references to the Script knows thanks to the path in the STRATEGY_SCRIPTS_PATH constant.
Dictionary _plugin_settings = {...}¶
The _plugin_settings property stores a Dictionary that describes all the settings that should be appended to the ProjectSettings when the LockerPlugin is activated, so that they can be easily edited through the editor. Each key of this Dictionary points to the setting path in the ProjectSettings and each value describes information about the setting. The structure of this property is as follows: .. codeblock:: gdscript
- {
- “setting_1_path”: {
“default_value”: <Variant>, “current_value”: <Variant>, “is_basic”: <bool>, “property_info”: {
“name”: “setting_1_path”, “type”: <@GlobalScope.Variant.Type>, “hint”: <@GlobalScope.PropertyHint>, “hint_string”: <String>
}, “config_section”: <String>,
}, “setting_n_path”: { … }
}
The settings defined in this property are the following:
- "addons/locker/saves_directory": This setting defines the default directory where the LokGlobalStorageManager should save and load the game data.
- "addons/locker/save_files_prefix": This setting defines the default prefix that should be given to the save files by the LokGlobalStorageManager.
- "addons/locker/save_files_format": This setting defines the default file format that should be given to the save files by the LokGlobalStorageManager.
- "addons/locker/save_versions": This setting defines if, by default, the LokGlobalStorageManager should store the save versions when saving.
- "addons/locker/access_strategy": This setting stores a String that represents what LokAccessStrategy the LokGlobalStorageManager should use to save and load data. To convert from this String representation to an actual LokAccessStrategy instance, the _string_to_strategy method can be used.
- "addons/locker/encrypted_strategy/password": This setting stores the default password that should be used by the LokGlobalStorageManager’s strategy, if it is the LokEncryptedAccessStrategy.
Method Descriptions¶
void set_setting_saves_directory(String path)¶
The set_setting_saves_directory method is a shortcut to defining the "addons/locker/saves_directory" setting in the ProjectSettings to the value of the passed path.
String get_setting_saves_directory()¶
The get_setting_saves_directory method is a getter to facilitate obtaining the "addons/locker/saves_directory" setting from the ProjectSettings.
void set_setting_save_files_prefix(String prefix)¶
The set_setting_save_files_prefix method is a shortcut to defining the "addons/locker/save_files_prefix" setting in the ProjectSettings to the value of the passed prefix.
String get_setting_save_files_prefix()¶
The get_setting_save_files_prefix method is a getter to facilitate obtaining the "addons/locker/save_files_prefix" setting from the ProjectSettings.
void set_setting_save_files_format(String format)¶
The set_setting_save_files_format method is a shortcut to defining the "addons/locker/save_files_format" setting in the ProjectSettings to the value of the passed format.
String get_setting_save_files_format()¶
The get_setting_save_files_format method is a getter to facilitate obtaining the "addons/locker/save_files_format" setting from the ProjectSettings.
void set_setting_save_versions(bool state)¶
The set_setting_save_versions method is a shortcut to defining the "addons/locker/save_versions" setting in the ProjectSettings to the value of the passed state.
bool get_setting_save_versions()¶
The get_setting_save_versions method is a getter to facilitate obtaining the "addons/locker/save_versions" setting from the ProjectSettings.
void set_setting_access_strategy(String strategy)¶
The set_setting_access_strategy method is a shortcut to defining the "addons/locker/access_strategy" setting in the ProjectSettings to the value of the passed strategy.
String get_setting_access_strategy()¶
The get_setting_access_strategy method is a getter to facilitate obtaining the "addons/locker/access_strategy" setting from the ProjectSettings.
LokAccessStrategy get_setting_access_strategy_parsed()¶
The get_setting_access_strategy_parsed method is a getter to facilitate obtaining the "addons/locker/access_strategy" setting from the ProjectSettings already parsed as a LokAccessStrategy.
void set_setting_encrypted_strategy_password(String password)¶
The set_setting_encrypted_strategy_password method is a shortcut to defining the "addons/locker/encrypted_strategy/password" setting in the ProjectSettings to the value of the passed password.
String get_setting_encrypted_strategy_password()¶
The get_setting_encrypted_strategy_password method is a getter to facilitate obtaining the "addons/locker/encrypted_strategy/password" setting from the ProjectSettings.
void update_available_strategies()¶
The update_available_strategies method uses the _strategy_scripts to update what LokAccessStrategy options should be shown in the ProjectSettings as options to choose from.
void save_settings(Dictionary settings)¶
The save_settings method takes a settings Dictionary and takes the current value of each one of them from the ProjectSettings, saving them in a ConfigFile in the CONFIG_PATH.
The settings parameter has to conform to the structure explained in the _plugin_settings description.
void load_settings(Dictionary settings = _plugin_settings)¶
The load_settings method takes a settings Dictionary and loads the settings described by it from the ConfigFile in the CONFIG_PATH. This method, then, sets the loaded settings in the ProjectSettings.
The settings parameter has to conform to the structure explained in the _plugin_settings description.
Dictionary get_changed_settings(Dictionary settings = _plugin_settings)¶
The get_changed_settings method takes a settings Dictionary and looks for settings that had their values changed.
When found, their values are updated and they are returned. The settings parameter as well as the returned Dictionary conform to the structure explained in the _plugin_settings description.
void add_settings(Dictionary settings = _plugin_settings)¶
The add_settings method takes a settings Dictionary and saves each of its settings in the ProjectSettings.
The settings parameter must conform to the structure explained in the _plugin_settings description.
void remove_settings(Dictionary settings = _plugin_settings)¶
The remove_settings method takes a settings Dictionary and removes each of its settings from the ProjectSettings.
The settings parameter must conform to the structure explained in the _plugin_settings description.
:ref:`Script <Script>`[] _load_strategy_scripts()¶
The _load_strategy_scripts method returns an Array of Script constant.
:ref:`LokAccessStrategy <LokAccessStrategy>`[] _get_strategies()¶
The _get_strategies method returns an Array of LokAccessStrategy instances got from the Script property.
String _get_strategies_enum_string()¶
The _get_strategies_enum_string method parses the LokAccessStrategy knows into a String that describes them in a way compatible with ``hint_string``s.
String _get_default_strategy_name(String wanted_name)¶
The _get_default_strategy_name method tries to get the name of the LokAccessStrategy specified by the wanted_name parameter, so that name can be used in the ProjectSettings as the default choice in the strategies enum.
If there’s no such LokAccessStrategy known by the LockerPlugin, this method will return any LokAccessStrategy name it knows, or even an empty String, if it doesn’t know any :ref:`LokAccessStrategy <LokAccessStrategy>`s.
LokAccessStrategy _string_to_strategy(String string)¶
The _string_to_strategy method takes a string and returns a LokAccessStrategy that corresponds to that string.
If an invalid string is passed, this method returns null.
String _strategy_to_string(LokAccessStrategy strategy)¶
The _strategy_to_string method takes a strategy and returns a String that represents that strategy in the "addons/locker/access_strategy" setting of the ProjectSettings.
If an invalid strategy is passed, this method returns an empty String.