Creates a new instance of the game class.
Compresses the given game data to a base64-encoded using lz-string.
The game data to be compressed. Defaults to the current game data.
The compressed game data and a hash as a base64-encoded string to use for saving.
Compiles the given game data to a tuple containing the compressed game data and a hash.
The game data to be compressed. Defaults to the current game data.
[hash, data] - The compressed game data and a hash as a base64-encoded string to use for saving.
Decompiles the data stored in localStorage and returns the corresponding object.
Optional
data: null | stringThe data to decompile. If not provided, it will be fetched from localStorage using the key ${game.config.name.id}-data
.
The decompiled object, or null if the data is empty or invalid.
Compiles the game data and prompts the user to download it as a text file using window.prompt. If you want to implement a custom data export, use compileData instead.
Gets the data for the given key.
The key to get the data for.
The data for the given key.
Set the return value of setData to a variable instead, as that is a getter and provides type checking.
Gets the static data for the given key.
The key to get the static data for.
The static data for the given key.
Set the return value of setStatic to a variable instead, as that is a getter and provides type checking. Also, static data is basically useless and should not be used. Use variables in local scope instead.
Loads game data and processes it.
The data to load. If not provided, it will be fetched from localStorage using decompileData.
Returns null if the data is empty or invalid, or false if the data is tampered with. Otherwise, returns true.
Loads game data and processes it.
The data to load. If not provided, it will be fetched from localStorage using decompileData.
Whether to merge the loaded data with the normal data. Defaults to true
.
Warning: If set to false
, the loaded data may have missing properties and may cause errors.
The loaded data.
Saves the game data to local storage under the key ${game.config.name.id}-data
.
If you don't want to save to local storage, use compileData instead.
The data to save. If not provided, it will be fetched from localStorage using compileData.
Sets the data for the given key. The getter is a work in progress.
An object with a single entry of the name of the key and the value of the data. This is a getter and setter.
Sets the static data for the given key. This data is not affected by data loading and saving, and is mainly used internally.
The key to set the static data for.
The value to set the static data to.
A getter for the static data.
Validates the given data using a hashing algorithm (md5)
[hash, data] The data to validate.
Whether the data is valid / unchanged. False means that the data has been tampered with / save edited.
A class that manages game data, including saving, loading, and exporting data.
The main methods are: DataManager.saveData, DataManager.loadData, and DataManager.exportData. The other methods are used internally, but can be used for more advanced functionality / customization.