API Docs for:
Show:

gs.GameStorage Class

Extends gs.EventEmitter

The GameStorage helps to store different kind of game data permanentely like a save-game or the game settings. The way how the data is stored depends on the platform. For example: If the game runs in a web-browser the data is stored the internal local storage of the web-browser but if the game runs locally the data is stored on disk.

All object are stored as JSON so it is imported that the object to store can be serialized to JSON and doesn't contain any circular references. Except for the methods gs.GameStorage.setData and gs.GameStorage.getData since that methods dealing with a regular string.

Constructor

gs.GameStorage

() static

Item Index

Methods

Methods

clear

() static

Clears the game storage. All data will be lost.

exists

() Boolean static

Checks if data already exists for the specified id/key.

Returns:

Boolean:

If true then there is already existing data for the id/key. Otherwise false

getData

(
  • id
)
String static

Gets a stored string for the specified id/key.

Parameters:

  • id String
    • The id/key of the string/data to get.

Returns:

String:

The string/data or null if no data exists for the specified id/key.

getObject

(
  • id
)
Object static

Gets a stored object for the specified id/key.

Parameters:

  • id String
    • The id/key of the object to get.

Returns:

Object:

The object or null if no object exists for the specified id/key.

initialize

() static

Initializes the game storage. Needs to be called once when the game starts. It initializes the storage depending on platform. In case of cloud-storage, it will connect to the cloud-server to get the storage data.

This method is asynchronous and fires a "finishInitialize" event when it is done.

remove

() String static

Deletes the data stored under the specified id/key.

Returns:

String:

id - The id/key where the data should be deleted.

setData

(
  • id
  • data
)
static

Stores a string under the specified id/key.

Parameters:

  • id String
    • The id/key where the data should be stored.
  • data String
    • The string to store.

setObject

(
  • id
  • object
)
static

Stores an object under the specified id/key. The object will be serialized to JSON so its important that the object doesn't contain any circular references.

Parameters:

  • id String
    • The id/key where the object should be stored.
  • object Object
    • The object to store.

storagePath

() static

The path where the data is stored. The result depends on the platform. For example: For a web-game the result is an empty string but for a local running game the result is the file-path to the configured storage-directory of the game.