LokGlobalStorageManager

Inherits:

The LokGlobalStorageManager class is the main manager of the manipulation processes.

Description

This class is registered as an autoload when the 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 <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 <github.com/nadjiel>_)

Property Index

Type

Name

Default value

String

saves_directory

get_setting_saves_directory()

String

save_files_prefix

get_setting_save_files_prefix()

String

save_files_format

get_setting_save_files_format()

bool

save_versions

get_setting_save_versions()

LokAccessExecutor

_access_executor

new()

Method Index

Property Descriptions

String saves_directory = get_setting_saves_directory()

The saves_directory property stores a 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 ProjectSettings (which is created by the LockerPlugin using the LokSettingsManager).

String save_files_prefix = get_setting_save_files_prefix()

The save_files_prefix property stores a 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 ProjectSettings (which is created by the LockerPlugin using the LokSettingsManager).

String save_files_format = get_setting_save_files_format()

The save_files_format property stores a 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 ProjectSettings (which is created by the LockerPlugin using the LokSettingsManager).

bool save_versions = get_setting_save_versions()

The 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 LokStorageAccessorVersion <LokStorageAccessorVersion>`s. By default, this property initializes with the value from the `”addons/locker/save_versions”`` setting in the ProjectSettings (which is created by the LockerPlugin using the LokSettingsManager).

LokAccessExecutor _access_executor = new()

The _access_executor property stores a LokAccessExecutor that is responsible for separating the save files’ operations in a separate Thread so that they can be used asynchronously.

Method Descriptions

void set_access_strategy(LokAccessStrategy new_strategy)

The set_access_strategy method allows quickly setting the LokAccessStrategy of the _access_executor, if it is not null.

LokAccessStrategy get_access_strategy()

The get_access_strategy method allows quickly getting the LokAccessStrategy of the _access_executor.

Dictionary collect_data(LokStorageAccessor accessor, String version_number = "")

The 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 Dictionary with all the data obtained from the accessor. That Dictionary is guaranteed to have a "version" key saying what version was used to get that data IF the save_versions property is true.

Dictionary gather_data(LokStorageAccessor <LokStorageAccessor>`[] included_accessors = ``[]`, String version_number = "")

The gather_data method is the central point where the data from all LokAccessorGroup.accessors is collected using the collect_data method. If the included_accessors parameter is not empty, this method only gathers data from the LokStorageAccessor. The version_number parameter is used as the version of the LokStorageAccessor, which converts to their latest version. In the case there’s LokStorageAccessor.id conflicts in the same 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 Dictionary with all the data obtained from the :ref:`LokStorageAccessor <LokStorageAccessor>`s. It’s structure is the following: .. codeblock:

{
  "partition_1_id": {
    "accessor_1_id": {
      "version": <String> (optional),
      ...
    },
    "accessor_n_id": { ... }
  },
  "partition_n_id": { ... }
}

void distribute_result(Dictionary result, LokStorageAccessor <LokStorageAccessor>`[] included_accessors = ``[]`)

The distribute_result method is the central point where the result of loadings is distributed to all LokAccessorGroup.accessors. If the included_accessors parameter is not empty, this method only distributes data to the LokStorageAccessor. The version of the LokStorageAccessor <LokStorageAccessor>`s that receives the data is determined by the `”version”`` key of its data in the data subdictionary of the result Dictionary. If there’s no such entry, the version that receives the data is the latest available. If there are more than one LokStorageAccessor <LokStorageAccessor>`s with the same id found, the data with that id is distributed to all of these :ref:`LokStorageAccessor <LokStorageAccessor>`s. The ``result` Dictionary that this method expects should match the following pattern: .. codeblock:

{
  "result": <@GlobalScope.Error>,
  "data": {
    "accessor_1_id": {
      "version": <String>,
      ...
    },
    "accessor_n_id": { ... }
  }
}

:ref:`String <String>`[] get_saved_files_ids()

The get_saved_files_ids method returns an Array of String.

Dictionary save_data(String file_id = current_file, String version_number = current_version, LokStorageAccessor <LokStorageAccessor>`[] included_accessors = ``[]`, bool replace = false)

The save_data method is the main method for saving data using the LockerPlugin. To read more about the parameters and return of this method, see the LokStorageManager.save_data description. Note that if a file_id is passed but is an empty String, the LokStorageManager.current_file is prioritized over the empty one.

Dictionary load_data(String file_id = current_file, LokStorageAccessor <LokStorageAccessor>`[] included_accessors = ``[]`, String <String>`[] partition_ids = ``[]`, String <String>`[] version_numbers = ``[]`)

The load_data method is the main method for loading data using the LockerPlugin. To read more about the parameters and return of this method, see the LokStorageManager.load_data description. Note that if a file_id is passed but is an empty String, the LokStorageManager.current_file is prioritized over the empty one.

Dictionary read_data(String file_id = current_file, LokStorageAccessor <LokStorageAccessor>`[] included_accessors = ``[]`, String <String>`[] partition_ids = ``[]`, String <String>`[] version_numbers = ``[]`)

The read_data method is the main method for reading data using the LockerPlugin. To read more about the parameters and return of this method, see the LokStorageManager.read_data description. Note that if a file_id is passed but is an empty String, the LokStorageManager.current_file is prioritized over the empty one.

Dictionary remove_data(String file_id = current_file, LokStorageAccessor <LokStorageAccessor>`[] included_accessors = ``[]`, String <String>`[] partition_ids = ``[]`, String <String>`[] version_numbers = ``[]`)

The remove_data method is the main method for removing data using the LockerPlugin. To read more about the parameters and return of this method, see the LokStorageManager.remove_data description. Note that if a file_id is passed but is an empty String, the LokStorageManager.current_file is prioritized over the empty one.

:ref:`String <String>`[] _get_accessor_ids(:ref:`LokStorageAccessor <LokStorageAccessor>`[] from_accessors)

The _get_accessor_ids method returns an Array of String <String>`s representing the ids from the :ref:`LokStorageAccessor <LokStorageAccessor>`s received in the ``from_accessors` parameter.

String _get_file_name(String file_id)

The _get_file_name method returns a String with the name of a file that has file_id as its id. If file_id is an empty String, the file name defaults to the save_files_prefix. If that property is an empty String, then the file name equals to the file_id. If both are not empty String, then the file name equals to a nicely concatenated <save_files_prefix>_<file_id>.

String _get_file_path(String file_id)

The _get_file_path method returns a String with the path of a file that has file_id as its id. If both the save_files_prefix and the file_id are empty String to avoid that the saves_directory is used as a file.

void _push_error_no_executor()

The _push_error_no_executor method pushes an error saying that no LokAccessExecutor was found in this class.