Class: module:src/modules/Game

module:src/modules/Game

new module:src/modules/Game()

Source:
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
Source:
Returns:
Type
boolean

buildGameOver(datas) → {Promise}

buildGameOver
Parameters:
Name Type Description
datas Object the data score, start, duration
Properties
Name Type Description
score
start
duration
content_id
Source:
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
Name Type Attributes Default Description
onProgress <optional>
function() a progress function filled with the percentage
onStart <optional>
function() called on on start
onEnd <optional>
function() called when unzipped is done
Source:
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
Source:
Returns:
the gameObject with response_api_dld key
Type
Promise.<Array>

isDownloading() → {boolean}

isDownloading
Source:
Returns:
Type
boolean

isGameDownloaded(gameID) → {Promise}

isGameDownloaded
Parameters:
Name Type Description
gameID String the id of the game
Source:
Returns:
Type
Promise

list() → {Promise.<Array>}

list
Source:
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>
Source:

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
Source:
Returns:
Type
Promise

remove(gameID) → {Promise.<Array>}

remove the game directory
Parameters:
Name Type Description
gameID String the game id to delete on filesystem
Source:
Returns:
Type
Promise.<Array>

removeAll() → {Promise}

removeAll delete all games and recreate the games folder
Source:
Returns:
Type
Promise