new module:src/modules/Game()
Example
var sgConf = modules: ["game"],
modules_conf: {
"game": {
"bundle_games": [
"<content_id>",
"<content_id>"
]
}
};
var afterSgInit = Stargate.initialize(sgConf);
afterSgInit
.then(function(){
return Stargate.game.download(gameObject, {onStart:function(ev){}, onEnd:function(ev){}, onProgress:function(ev){}})
})
.then(function(gameID){
Stargate.game.play(gameID);
});
Methods
abortDownload() → {boolean}
abortDownload
Returns:
- Type
- boolean
buildGameOver(datas) → {Promise}
buildGameOver
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
datas |
Object | the data score, start, duration
Properties
|
Returns:
- The promise will be filled with the gameover html {String}
- Type
- Promise
download(gameObject, callbacksopt) → {Promise.<(boolean|FileError|Number)>}
download the game and unzip it
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
gameObject |
object | The gameObject with the url of the html5game's zip | ||||||||||||||||||||||
callbacks |
object |
<optional> |
{} | an object with start-end-progress callbacks
Properties
|
Returns:
- true if all has gone good, 403 if unathorized, FileError in case can write in the folder
- Type
- Promise.<(boolean|FileError|Number)>
getBundleGameObjects() → {Promise.<Array>}
getBundleObjects
make the jsonpRequests to get the gameObjects.
This method is called only if configuration key "bundle_games" is set with an array of gameIDs
Returns:
the gameObject with response_api_dld key
- Type
- Promise.<Array>
isDownloading() → {boolean}
isDownloading
Returns:
- Type
- boolean
isGameDownloaded(gameID) → {Promise}
isGameDownloaded
Parameters:
Name | Type | Description |
---|---|---|
gameID |
String | the id of the game |
Returns:
- Type
- Promise
list() → {Promise.<Array>}
list
Returns:
- Returns an array of metainfo gameObject
- Type
- Promise.<Array>
needsUpdate(gameId)
needsUpdate
checks if there's or not a new version for the game(it makes a call to the api)
Parameters:
Name | Type | Description |
---|---|---|
gameId |
String | the gameId |
|
Promise.<Boolean> |
play(gameID) → {Promise}
play
Parameters:
Name | Type | Description |
---|---|---|
gameID |
String | the game path in gamesDir where to look for. Note:the game is launched in the same webview |
Returns:
- Type
- Promise
remove(gameID) → {Promise.<Array>}
remove the game directory
Parameters:
Name | Type | Description |
---|---|---|
gameID |
String | the game id to delete on filesystem |
Returns:
- Type
- Promise.<Array>
removeAll() → {Promise}
removeAll delete all games and recreate the games folder
Returns:
- Type
- Promise