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.
Use the register methods to define the values, which are to be included in the saved game score. Use the methods setSaveDialogUrl() and openSaveDialog() to open the save dialog with the game score. Use the method closeWindowByOpener() to close the save dialog.
Use the methods getSaveDialogTitle(), getSaveDialogMessage() and getSaveDialogCloseButtonTitle() in the save dialog. This methods are providing internationalized texts, which where set by calling openSaveDialog().
Call the method openStartPage() to forward form the save dialog to the page with the StorageManager, if the save dialog is opened by a bookmark containing the game score. Call the method startGame() in the page with the StorageManager to start the game with or without a game score.
Constructor Summary |
---|
MacaoPersistence()
This constructor is used to create a MacaoPersistence object. |
Method Summary | |
---|---|
integer | calculateLengthInBits(integer positiveInteger)
Use this utility method to calculate the number of bits, which is used to store an integer of a specified value. |
void | closeWindowByOpener()
Call this method in the save dialog to close the save dialog. |
MacaoPersistence | getOpenerPersistence()
Use method in the Save Dialog to get the Persistence object of the index frame, which opened the dialog. |
String | getSaveDialogCloseButtonTitle()
Call this method in the save dialog to get the text for the close button title. |
String | getSaveDialogMessage()
Call this method in the save dialog to get the text for the dialog message. |
String | getSaveDialogTitle()
Call this method in the save dialog to get the text for the dialog title. |
void | openPage(String pageFramesetUrl, String openerPageName, Window startFrame)
This method is called while loading a game score to open the current page of the score. |
void | openSaveDialog(integer width, integer height, optional String title, optional String message, optional String closeButtonTitle, optional String popupBlockerWarning, optional Function openWindowFunction)
Call this method to open the save dialog. |
void | openStartPage(String startPageUrl)
Call this method in the save dialog, to forward to the page with the StorageManager, while a saved game is reloaded. |
void | registerBoleanValue(String valueName)
Call this method to register a storage value of type boolean. |
void | registerDecimalValue(String valueName, boolean signed, integer maxLengthInBits)
Call this method to register a number storage value, which will be put to the game score with three decimal places. |
void | registerGameEvent(String gameEvent)
Call this method to register a game event to be stored in the game score. |
void | registerIntegerValue(String valueName, boolean signed, integer maxLengthInBits)
Call this method to register a storage value of type integer. |
void | registerInventoryItem(String inventoryObjectName, String itemName, String itemTitle, String imageUrl, optional String subTitle, optional integer maxQuantity, optional boolean isDecimalQuantity)
Call this method to register an inventory item, which is to be stored in the game score. |
void | registerLanguage(String languageCode)
Call this method to register a language for inclusion in the game score. |
void | registerPage(String pageName, String pageFramesetUrl)
Call this method to register a content page for inclusion in the game score. |
void | registerStringValue(String valueName, integer maxLengthInBytes)
Call this method to register a storage value of type String. |
void | registerVersion(integer versionNumber)
Call this method to set the version of the save configuration. |
void | setSaveDialogUrl(String saveDialogUrl)
Call this method to set the location of the save dilaog page. |
void | startGame(String firstPageUrl, Window startFrame, optional boolean showConfirmDialog)
Call this method in the page with the StorageManager to start a new game or restart a game with a provided game score. |
Constructor Details |
---|
This constructor is used to create a MacaoPersistence object.
Method Details |
---|
Use this utility method to calculate the number of bits, which is used to store an integer of a specified value.
Call this method in the save dialog to close the save dialog.
In the browser, if a window was opened by another window, it is not allowed to close itself. But it must be closed from the window, which opened it. Call this method in the save dialog. It will find the owner window and will cause it to close the dialog.
Use method in the Save Dialog to get the Persistence object of the index frame, which opened the dialog.
Call this method in the save dialog to get the text for the close button title.
The title was provided calling openSaveDialog(). This way is choosen to provide the save dialog with internationalization support, because itself has no such support.
Call this method in the save dialog to get the text for the dialog message.
The message was provided calling openSaveDialog(). This way is choosen to provide the save dialog with internationalization support, because itself has no such support.
Call this method in the save dialog to get the text for the dialog title.
The title was provided calling openSaveDialog(). This way is choosen to provide the save dialog with internationalization support, because itself has no such support.
This method is called while loading a game score to open the current page of the score.
The method loads the page frameset URL to the start frame. The opener page name is added as URL parameter openerPage.
You can override this method to do something after the score is loaded but before the game is restartet.
Call this method to open the save dialog.
This method opens the save dialog. It provides the actual score of the game in the URL parameter score. So when the save dialog is bookmarked, the score is included in the bookmark.
Make sure to call the method setSaveDialogUrl() before to set the URL of the save dialog. This functionality has been separated, so the standard controllers page implementation can call this method without knowing the location of the save dialog of your game. If you have included the standard controllers page, you don't need to call this method, because it is called by the save menu item of the page.
The save dialog is opened as a new window. If the method fails to open the new window, it is probably hindered by a popup blocker. If the method detects that there is no new window, it displays a prompt dialog showing a popup blocker warning. The warning tells the user to deactivate the popup blocker in order to save the game. Currently there is NO problem with the standard popup blocker settings of the browsers. Normally a popup blocker detects unwanted windows, if there was no user interaction like a mous click before, which might have caused the opening of the window. But in our case the user has clicked in order to open the save dialog.
You can use the title and messge parameters to provide internationalized text.
If you call this method from another page than that one, which contains the persistence package, you need to provide a call back function, which opens a window. Copy the following source code to the calling page and provide the reference to the function with the last parameter. This is necessary to have a common behavior for different browser types.
function openWindow(url, name, parameters) { // open the window with the base path of the current page return window.open(getBasePath() + url, name, parameters) }
Here is an example how you can call this method providing the just defined function:
// get storage manager frame storageWindow = getStorageWindow() // open save dialog providing the callback func. storageWindow.persistence.openSaveDialog( 600, 250, null, null, null, null, openWindow )
Call this method in the save dialog, to forward to the page with the StorageManager, while a saved game is reloaded.
The method detects, if the save dialog is opened by a bookmark to reload a saved game or if it is opened by a running game to save the game score. If the save dialog is opened by a running game, the method does nothing. If it is not opened by a bookmark, it opens the page with the StorageManager and passes the game score as the URL paramter openScore. In the page with the StorageManager the method startGame() is to be called, in order to restart the game with the score.
Call this method to register a storage value of type boolean.
Call this method, if you want a boolean value to be included in the game score, which you set to the StorageManager calling setStorageValue().
Call this method to register a number storage value, which will be put to the game score with three decimal places.
Call this method, if you want a number value to be included in the game score, which you set to the StorageManager calling setStorageValue().
Call this method to register a game event to be stored in the game score.
Provide the name of the game event. Don't register game events, which are ever cleared, before a page is left. E.g. you have a game event SitsOnChair. The character has to leave the chair in order to leave the room.
See also setGameEvent() and setGameEvents().
Call this method to register a storage value of type integer.
Call this method, if you want an integer value to be included in the game score, which you set to the StorageManager calling setStorageValue().
Call this method to register an inventory item, which is to be stored in the game score.
Call this method once for every item in every inventory. A game can have more than one inventory. But the standard page optional/controllers/inventory.html does only define one inventory with the name Inventory.
Call this method to register a language for inclusion in the game score.
Call this method once for every language, which your game supports. Don't call this method, if your game is not internationalized.
Call this method to register a content page for inclusion in the game score.
Call this method once for each content page of your game. Don't call this method for frameset pages, controller pages or the top frameset page with the StorageManager.
Call this method to register a storage value of type String.
Call this method, if you want a String value to be included in the game score, which you set to the StorageManager calling setStorageValue().
Call this method to set the version of the save configuration.
The version number is saved with the game score and checked when the game score is loaded. If the version number has changed, the loading of the game score is prevented and the user gets an error message. Increase this number each time, when you change the registration.
Its recommended to start with a version number of 8. This will reserve four bits for the version number. Its no problem to exceed this number of bits by a later version number. The default value is 0, which will include no version number in the game score.
Call this method to set the location of the save dilaog page.
Call this method before calling openSaveDialog().
Because a Macao installation can have more than one game, the position of the save dialog is the information, which game is saved in the bookmark. So the save dialog has no standard location in the directory structure. You are required to copy the master save dialog from the directory optional/controllers to your application directory. Then you need to adjust the links from start dialog to StorageManager page and vice versa. Do this by calling setSaveDialogUrl() in the StorageManager page and openStartPage() in the save dialog.
Call this method in the page with the StorageManager to start a new game or restart a game with a provided game score.
The method checks the URL of the current page for the parameter openScore, which contains a game score. If it detects the parameter, it asks the user to restart the game using the score. If the user confirms, the game is restarted using the score. If the user doesn't confirm or if there is no score to be loaded, the method starts the game from the beginning using the firstPageUrl.