The package Persistence implements the functionality to save the game score as a bookmark in the browser and to reload this game score, when the bookmark is opened.
Include this package in the page with the StorageManager after the package of the StorageManager. Include this package in the save dialog. So the save dialog can communicate with the persistence object in the StorageManager window. The package produces a grobal variable persistence with a singleton object of MacaoPersistence. Call this objects methods to use the persistence functionality.
If you include this package, the standard implementation of the controllers page optional/controllers/controllers.html will show a save symbol in the controllers menu. Don't include this package, if you don't want to use the bookmark persistence.
The persistence package is implemented in the file core/persistence.js. A compressed version of the package is available in the file core/compressed/persistence.js.
To achive a good compression, this package doesn't store the complete content of the StorageManager. But instead you need to register all pages, game events and inventory items, which may occur in the game and need to be saved. Most values, e.g. game events and inventory items, are stored only as a single bit.
The saved game score has ever the same length. So you can save numbers and strings in the score, but you need to reserve the space for the largest content. Larger content will be truncated.
This module assumes, that the game is saved in a situation where a page is just opened. When a game is reloaded, the game events and inventory items are set and the last opened page is reopened. You also get the information about the opener page. But the position or state of the objects, which are moving through the page, is not stored.
You can use the methods registerStringValue(), registerBooleanValue(), registerIntegerValue() and registerDecimalValue() to include additional values from the StorageManager. See also setStorageValue(). Before the game score is stored and before a page is left, the method store(false) is called on every object. You can override or implement this mehtod to put properties from the object to the StorageManager.
Class Summary | |
---|---|
MacaoPage |
The class MacaoPage is not a class itself, but it is used to document all the global properties and methods of the package core/persistence.js. |
MacaoPersistence |
This class is used to get the game score from the StorageManager and to open the save dialog in order to save the game score as a bookmark. It is also used to get the game score from the URL of the page, put it to the StorageManager and to restart the game. |