LokStorageAccessor¶
Inherits:
The LokStorageAccessor is a node specialized in saving, loading and removing data.
Description¶
This class uses different versions to handle data saving and loading accross different game versions. In order to do the job of managing the data it receives, this class must have at least one LokStorageAccessorVersion set in its versions and point to it through the version_number property. Such version should define the logic of how the data is gathered to be saved and how it is used when loaded. See more about it here LokStorageAccessorVersion.
Version: 1.0.0 Author: github.com/nadjiel <github.com/nadjiel>_
Property Index¶
Type |
Name |
Default value |
|---|---|---|
String |
|
|
String |
|
|
String |
|
|
String |
|
|
:ref:`LokStorageAccessorVersion <LokStorageAccessorVersion>`[] |
|
|
Dictionary |
|
|
bool |
|
|
|
||
Method Index¶
Signal Descriptions¶
saving_started()¶
The saving_started is emitted when a save operation was started by this LokStorageAccessor.
loading_started()¶
The loading_started is emitted when a load operation was started by this LokStorageAccessor.
removing_started()¶
The removing_started is emitted when a remove operation was started by this LokStorageAccessor.
saving_finished(Dictionary result)¶
The saving_finished is emitted when a save operation was finished by this LokStorageAccessor.
This signal brings a Dictionary representing the result of the operation. This Dictionary has a "status" key, with a @GlobalScope.Error code and a "data" key, with the data saved.
loading_finished(Dictionary result)¶
The loading_finished is emitted when a load operation was finished by this LokStorageAccessor.
This signal brings a Dictionary representing the result of the operation. This Dictionary has a "status" key, with a @GlobalScope.Error code and a "data" key, with the data loaded.
removing_finished(Dictionary result)¶
The removing_finished is emitted when a remove operation was finished by this LokStorageAccessor.
This signal brings a Dictionary representing the result of the operation. This Dictionary has a "status" key, with a @GlobalScope.Error code; a "data" key, with the data removed; and a "updated_data" key, with the data that wasn’t removed.
Property Descriptions¶
String id = ""¶
The id property specifies what is the unique id of this LokStorageAccessor. You should always plan your save system to make sure your LokStorageAccessor’s ids don’t crash when saving data. If they do, there may arise data inconsistency issues or even loss of data. Multiple LokStorageAccessor is fine, though, with the load_data operation, or in the case those :ref:`LokStorageAccessor <LokStorageAccessor>`s belong to different save files.
String file = ""¶
The file property specifies from what file the data of this LokStorageAccessor belongs to. If left empty, it is considered as being the default file. This file property is only used by the operations of this LokStorageAccessor as the default file, not in general operations that include multiple :ref:`LokStorageAccessor <LokStorageAccessor>`s. This is useful when in need of implementing something like a file selection screen.
String partition = ""¶
The partition property specifies in what partition the data of this LokStorageAccessor should be stored. If left empty, it means it is stored in the default partition. The separation in partitions is useful when a LokStorageAccessor or group of :ref:`LokStorageAccessor <LokStorageAccessor>`s have data that has to be loaded often by itself, like the data from a player that needs to be loaded whenever it logs in the game.
String version_number = "1.0.0"¶
The version_number property stores a String that points to one of the versions’ LokStorageAccessorVersion.number. To work properly, this LokStorageAccessor needs to point to a version number existent in the versions list, which is already done by default if the list has at least one LokStorageAccessorVersion that hadn’t had its LokStorageAccessorVersion.number altered.
LokStorageAccessorVersion <LokStorageAccessorVersion>`[] versions = ``[]`¶
The versions property stores a list of LokStorageAccessorVersion is able to save and load data. Different versions can be useful if the game needs to change its data organization accross different versions, with the addition of features, for example. To actually do something, this LokStorageAccessor needs at least one LokStorageAccessorVersion to save and load data. In order for this LokStorageAccessor to correctly find new versions, they should be added to this Array through a new Array, so that this property’s setter gets triggered. Alternatively, you can use a method like Array.append, but make sure to call the _update_version method next.
Dictionary dependency_paths = {}¶
The dependency_paths property stores a Dictionary that helps with keeping track of dependencies that this LokStorageAccessor needs to get or send data to. This property stores keys and values that are sent to the active LokStorageAccessorVersion so that it can manipulate the data accordingly. If the keys are NodePath, the NodePath can have their references, despite it being a Resource.
bool active = true¶
The active property is a flag that tells whether this LokStorageAccessor should operate its data when its save_data, load_data or remove_data methods try to.
By default it is set to true so that this LokStorageAccessor can do its tasks as expected.
LokStorageManager _storage_manager = LokGlobalStorageManager¶
The _storage_manager property is just a reference to the LokGlobalStorageManager autoload. Its reference is stored in this property so it can be more easily mocked in unit tests. The value of this property shouldn’t be altered. Doing so may cause the saving and loading system to not work properly.
LokStorageAccessorVersion _version¶
The _version property stores the current LokStorageAccessorVersion selected by the version_number. This is the LokStorageAccessorVersion that’s used when saving and loading data through this LokStorageAccessor.
Method Descriptions¶
LokStorageAccessor create(LokStorageAccessorVersion _version_number)¶
The create method is a utility to create a new LokStorageAccessor with its properties already set to the desired values.
bool select_version(String number)¶
The select_version method looks through all the versions and sets the current _version to be the one with number matching the number parameter.
If no such version is found, false is returned and the _version is set to null, else true is returned.
Dictionary save_data(String file_id = file, String version_number = "")¶
The save_data method uses the LokStorageManager to save the data of this LokStorageAccessor.
By default, the version used is the latest, but that can be defined in the version_number parameter.
Dictionary load_data(String file_id = file)¶
The load_data method uses the LokStorageManager to load the data of this LokStorageAccessor.
Dictionary remove_data(String file_id = file)¶
The remove_data method uses the LokStorageManager to remove the data of this LokStorageAccessor.
Dictionary retrieve_data()¶
The retrieve_data method uses the LokStorageAccessorVersion._retrieve_data to collect the data that should be saved by the LokStorageAccessor.save_data method.
void consume_data(Dictionary data)¶
The consume_data method uses the LokStorageAccessorVersion._consume_data to use the data that was loaded by the LokStorageAccessor.load_data method.
LokStorageAccessorVersion _find_version(String number)¶
The _find_version method looks through all the versions and returns the one that has same LokStorageAccessorVersion.number as the passed in the number parameter.
If no such version is found, null is returned.
LokStorageAccessorVersion _find_latest_version()¶
The _find_latest_version method looks through all the versions and returns the one that has the latest LokStorageAccessorVersion.number.
If no such version is found, null is returned.
void _update_version()¶
The _update_version method serves to make the _version property properly store the current version that the version_number points to.
Dictionary _get_dependencies()¶
The _get_dependencies method returns a copy of the dependency_paths Dictionary, but with Node and LokStorageAccessorVersion._consume_data methods.
String _get_readable_name()¶
The _get_readable_name method is a way of getting a more user friendly name for this LokStorageAccessor, for use in debugging.
void _push_error_no_manager()¶
The _push_error_no_manager method pushes an error warning that there’s no _storage_manager set in this LokStorageAccessor.
void _push_error_unactive_accessor()¶
The _push_error_unactive_accessor method pushes an error warning that an operation was tried in an unactive LokStorageAccessor.