.. _LokGlobalStorageManager: ======================= LokGlobalStorageManager ======================= **Inherits:** The :ref:`LokGlobalStorageManager ` class is the main manager of the manipulation processes. Description =========== This class is registered as an autoload when the :ref:`LockerPlugin ` is active, so that it can do its tasks. It's this class that's responsible for keeping track of all the :ref:`LokStorageAccessor `s in the current scene tree, so that they can easily save and load their data. **Version**: 1.0.0 **Author**: Daniel Sousa (github.com/nadjiel _) Property Index ============== .. list-table:: :header-rows: 1 * - Type - Name - Default value * - :ref:`String ` - :ref:`saves_directory ` - ``get_setting_saves_directory()`` * - :ref:`String ` - :ref:`save_files_prefix ` - ``get_setting_save_files_prefix()`` * - :ref:`String ` - :ref:`save_files_format ` - ``get_setting_save_files_format()`` * - :ref:`bool ` - :ref:`save_versions ` - ``get_setting_save_versions()`` * - :ref:`LokAccessExecutor ` - :ref:`_access_executor ` - ``new()`` Method Index ============ .. list-table:: :header-rows: 1 * - Return type - Signature * - :ref:`void ` - :ref:`set_access_strategy `\(:ref:`LokAccessStrategy ` new_strategy\)* - :ref:`LokAccessStrategy ` - :ref:`get_access_strategy `\(\)* - :ref:`Dictionary ` - :ref:`collect_data `\(:ref:`LokStorageAccessor ` accessor, :ref:`String ` version_number = ``""``\)* - :ref:`Dictionary ` - :ref:`gather_data `\(:ref:`LokStorageAccessor `[] included_accessors = ``[]``, :ref:`String ` version_number = ``""``\)* - :ref:`void ` - :ref:`distribute_result `\(:ref:`Dictionary ` result, :ref:`LokStorageAccessor `[] included_accessors = ``[]``\)* - :ref:`String `[] - :ref:`get_saved_files_ids `\(\)* - :ref:`Dictionary ` - :ref:`save_data `\(:ref:`String ` file_id = ``current_file``, :ref:`String ` version_number = ``current_version``, :ref:`LokStorageAccessor `[] included_accessors = ``[]``, :ref:`bool ` replace = ``false``\)* - :ref:`Dictionary ` - :ref:`load_data `\(:ref:`String ` file_id = ``current_file``, :ref:`LokStorageAccessor `[] included_accessors = ``[]``, :ref:`String `[] partition_ids = ``[]``, :ref:`String `[] version_numbers = ``[]``\)* - :ref:`Dictionary ` - :ref:`read_data `\(:ref:`String ` file_id = ``current_file``, :ref:`LokStorageAccessor `[] included_accessors = ``[]``, :ref:`String `[] partition_ids = ``[]``, :ref:`String `[] version_numbers = ``[]``\)* - :ref:`Dictionary ` - :ref:`remove_data `\(:ref:`String ` file_id = ``current_file``, :ref:`LokStorageAccessor `[] included_accessors = ``[]``, :ref:`String `[] partition_ids = ``[]``, :ref:`String `[] version_numbers = ``[]``\)* - :ref:`String `[] - :ref:`_get_accessor_ids `\(:ref:`LokStorageAccessor `[] from_accessors\)* - :ref:`String ` - :ref:`_get_file_name `\(:ref:`String ` file_id\)* - :ref:`String ` - :ref:`_get_file_path `\(:ref:`String ` file_id\)* - :ref:`void ` - :ref:`_push_error_no_executor `\(\) Property Descriptions ===================== .. _LokGlobalStorageManager_saves_directory: :ref:`String ` saves_directory = ``get_setting_saves_directory()`` -------------------------------------------------------------------------- The :ref:`saves_directory ` property stores a :ref:`String ` pointing to the directory where the save files should be accessed. By default, this property initializes with the value from the ``"addons/locker/saves_directory"`` setting in the :ref:`ProjectSettings ` (which is created by the :ref:`LockerPlugin ` using the :ref:`LokSettingsManager `). .. _LokGlobalStorageManager_save_files_prefix: :ref:`String ` save_files_prefix = ``get_setting_save_files_prefix()`` ------------------------------------------------------------------------------ The :ref:`save_files_prefix ` property stores a :ref:`String ` that tells what's the prefix that should be used in the save files when creating them. By default, this property initializes with the value from the ``"addons/locker/save_files_prefix"`` setting in the :ref:`ProjectSettings ` (which is created by the :ref:`LockerPlugin ` using the :ref:`LokSettingsManager `). .. _LokGlobalStorageManager_save_files_format: :ref:`String ` save_files_format = ``get_setting_save_files_format()`` ------------------------------------------------------------------------------ The :ref:`save_files_format ` property stores a :ref:`String ` that tells what's the format that should be used in the save files when accessing them. By default, this property initializes with the value from the ``"addons/locker/save_files_format"`` setting in the :ref:`ProjectSettings ` (which is created by the :ref:`LockerPlugin ` using the :ref:`LokSettingsManager `). .. _LokGlobalStorageManager_save_versions: :ref:`bool ` save_versions = ``get_setting_save_versions()`` ------------------------------------------------------------------ The :ref:`save_versions ` property stores a ``bool`` that tells if the save files should store data about the version used when saving them, which is useful for easily versioning the saves using :ref:`LokStorageAccessorVersion `s. By default, this property initializes with the value from the ``"addons/locker/save_versions"`` setting in the :ref:`ProjectSettings ` (which is created by the :ref:`LockerPlugin ` using the :ref:`LokSettingsManager `). .. _LokGlobalStorageManager__access_executor: :ref:`LokAccessExecutor ` _access_executor = ``new()`` ------------------------------------------------------------------------- The :ref:`_access_executor <_access_executor>` property stores a :ref:`LokAccessExecutor ` that is responsible for separating the save files' operations in a separate :ref:`Thread ` so that they can be used asynchronously. Method Descriptions =================== .. _LokGlobalStorageManager_set_access_strategy: :ref:`void ` set_access_strategy\(:ref:`LokAccessStrategy ` new_strategy\) --------------------------------------------------------------------------------------------------- The :ref:`set_access_strategy ` method allows quickly setting the :ref:`LokAccessStrategy ` of the :ref:`_access_executor <_access_executor>`, if it is not ``null``. .. _LokGlobalStorageManager_get_access_strategy: :ref:`LokAccessStrategy ` get_access_strategy\(\) -------------------------------------------------------------------- The :ref:`get_access_strategy ` method allows quickly getting the :ref:`LokAccessStrategy ` of the :ref:`_access_executor <_access_executor>`. .. _LokGlobalStorageManager_collect_data: :ref:`Dictionary ` collect_data\(:ref:`LokStorageAccessor ` accessor, :ref:`String ` version_number = ``""``\) ------------------------------------------------------------------------------------------------------------------------------------------------------ The :ref:`collect_data ` method is used to get and organize the data from an ``accessor``. Optionally, a ``version_number`` can be passed to dictate from which version of the ``accessor`` the data should be got. If left undefined, this parameter defaults to the latest available. At the end, this method returns a :ref:`Dictionary ` with all the data obtained from the ``accessor``. That :ref:`Dictionary ` is guaranteed to have a ``"version"`` key saying what version was used to get that data **IF** the :ref:`save_versions ` property is ``true``. .. _LokGlobalStorageManager_gather_data: :ref:`Dictionary ` gather_data\(:ref:`LokStorageAccessor `[] included_accessors = ``[]``, :ref:`String ` version_number = ``""``\) -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- The :ref:`gather_data ` method is the central point where the data from all :ref:`LokAccessorGroup.accessors ` is collected using the :ref:`collect_data ` method. If the ``included_accessors`` parameter is not empty, this method only gathers data from the :ref:`LokStorageAccessor `s that are present in that :ref:`Array `. The ``version_number`` parameter is used as the version of the :ref:`LokStorageAccessor `s from which the data is collected. If left undefined, this parameter defaults to an empty :ref:`String `, which converts to their latest version. In the case there's :ref:`LokStorageAccessor.id ` conflicts in the same :ref:`LokStorageAccessor.partition `, the id of the last accessor encountered is prioritized. It is often unknown, though, which accessor is the last one, so it's always better to avoid repeated ids. At the end, this method returns a :ref:`Dictionary ` with all the data obtained from the :ref:`LokStorageAccessor `s. It's structure is the following: .. codeblock:: { "partition_1_id": { "accessor_1_id": { "version": (optional), ... }, "accessor_n_id": { ... } }, "partition_n_id": { ... } } .. _LokGlobalStorageManager_distribute_result: :ref:`void ` distribute_result\(:ref:`Dictionary ` result, :ref:`LokStorageAccessor `[] included_accessors = ``[]``\) ----------------------------------------------------------------------------------------------------------------------------------------------------------- The :ref:`distribute_result ` method is the central point where the result of loadings is distributed to all :ref:`LokAccessorGroup.accessors `. If the ``included_accessors`` parameter is not empty, this method only distributes data to the :ref:`LokStorageAccessor `s present in that :ref:`Array `. The version of the :ref:`LokStorageAccessor `s that receives the data is determined by the ``"version"`` key of its data in the ``data`` subdictionary of the ``result`` :ref:`Dictionary `. If there's no such entry, the version that receives the data is the latest available. If there are more than one :ref:`LokStorageAccessor `s with the same id found, the data with that id is distributed to all of these :ref:`LokStorageAccessor `s. The ``result`` :ref:`Dictionary ` that this method expects should match the following pattern: .. codeblock:: { "result": <@GlobalScope.Error>, "data": { "accessor_1_id": { "version": , ... }, "accessor_n_id": { ... } } } .. _LokGlobalStorageManager_get_saved_files_ids: :ref:`String `[] get_saved_files_ids\(\) ------------------------------------------------ The :ref:`get_saved_files_ids ` method returns an :ref:`Array ` of :ref:`String `s with the ids of all files saved in the :ref:`saves_directory `. .. _LokGlobalStorageManager_save_data: :ref:`Dictionary ` save_data\(:ref:`String ` file_id = ``current_file``, :ref:`String ` version_number = ``current_version``, :ref:`LokStorageAccessor `[] included_accessors = ``[]``, :ref:`bool ` replace = ``false``\) -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- The :ref:`save_data ` method is the main method for saving data using the :ref:`LockerPlugin `. To read more about the parameters and return of this method, see the :ref:`LokStorageManager.save_data ` description. Note that if a ``file_id`` is passed but is an empty :ref:`String `, the :ref:`LokStorageManager.current_file ` is prioritized over the empty one. .. _LokGlobalStorageManager_load_data: :ref:`Dictionary ` load_data\(:ref:`String ` file_id = ``current_file``, :ref:`LokStorageAccessor `[] included_accessors = ``[]``, :ref:`String `[] partition_ids = ``[]``, :ref:`String `[] version_numbers = ``[]``\) ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- The :ref:`load_data ` method is the main method for loading data using the :ref:`LockerPlugin `. To read more about the parameters and return of this method, see the :ref:`LokStorageManager.load_data ` description. Note that if a ``file_id`` is passed but is an empty :ref:`String `, the :ref:`LokStorageManager.current_file ` is prioritized over the empty one. .. _LokGlobalStorageManager_read_data: :ref:`Dictionary ` read_data\(:ref:`String ` file_id = ``current_file``, :ref:`LokStorageAccessor `[] included_accessors = ``[]``, :ref:`String `[] partition_ids = ``[]``, :ref:`String `[] version_numbers = ``[]``\) ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- The :ref:`read_data ` method is the main method for reading data using the :ref:`LockerPlugin `. To read more about the parameters and return of this method, see the :ref:`LokStorageManager.read_data ` description. Note that if a ``file_id`` is passed but is an empty :ref:`String `, the :ref:`LokStorageManager.current_file ` is prioritized over the empty one. .. _LokGlobalStorageManager_remove_data: :ref:`Dictionary ` remove_data\(:ref:`String ` file_id = ``current_file``, :ref:`LokStorageAccessor `[] included_accessors = ``[]``, :ref:`String `[] partition_ids = ``[]``, :ref:`String `[] version_numbers = ``[]``\) --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- The :ref:`remove_data ` method is the main method for removing data using the :ref:`LockerPlugin `. To read more about the parameters and return of this method, see the :ref:`LokStorageManager.remove_data ` description. Note that if a ``file_id`` is passed but is an empty :ref:`String `, the :ref:`LokStorageManager.current_file ` is prioritized over the empty one. .. _LokGlobalStorageManager__get_accessor_ids: :ref:`String `[] _get_accessor_ids\(:ref:`LokStorageAccessor `[] from_accessors\) ------------------------------------------------------------------------------------------------------------- The :ref:`_get_accessor_ids <_get_accessor_ids>` method returns an :ref:`Array ` of :ref:`String `s representing the ids from the :ref:`LokStorageAccessor `s received in the ``from_accessors`` parameter. .. _LokGlobalStorageManager__get_file_name: :ref:`String ` _get_file_name\(:ref:`String ` file_id\) ----------------------------------------------------------------------- The :ref:`_get_file_name <_get_file_name>` method returns a :ref:`String ` with the name of a file that has ``file_id`` as its id. If ``file_id`` is an empty :ref:`String `, the file name defaults to the :ref:`save_files_prefix `. If that property is an empty :ref:`String `, then the file name equals to the ``file_id``. If both are not empty :ref:`String `, then the file name equals to a nicely concatenated ``_``. .. _LokGlobalStorageManager__get_file_path: :ref:`String ` _get_file_path\(:ref:`String ` file_id\) ----------------------------------------------------------------------- The :ref:`_get_file_path <_get_file_path>` method returns a :ref:`String ` with the path of a file that has ``file_id`` as its id. If both the :ref:`save_files_prefix ` and the ``file_id`` are empty :ref:`String `s, then the file path will return an empty :ref:`String ` to avoid that the :ref:`saves_directory ` is used as a file. .. _LokGlobalStorageManager__push_error_no_executor: :ref:`void ` _push_error_no_executor\(\) ---------------------------------------------- The :ref:`_push_error_no_executor <_push_error_no_executor>` method pushes an error saying that no :ref:`LokAccessExecutor ` was found in this class.