Skip to content

Instantly share code, notes, and snippets.

@yevrah
Created August 18, 2016 00:57
Show Gist options
  • Save yevrah/b01e2d7de7c8a6e167859ab0014b8eac to your computer and use it in GitHub Desktop.
Save yevrah/b01e2d7de7c8a6e167859ab0014b8eac to your computer and use it in GitHub Desktop.
JAVSCRIPT: Angular and Phaser Integration
// Namespace declarations
var wingaru = wingaru || {};
var wingaru.auth = wingaru.auth || {};
var wingaru.games = wingaru.games || {};
var wingaru.activites = wingaru.acivities || {};
var wingaru.videos = wingaru.videos || {};
//
// Generic Helper
//
function log() {
var args = Array.prototype.slice.call(arguments);
$("#log").append( args.join() );
};
//
// Integration points for Angular-Phaser
//
// Basic Auth Properties - See https://thinkster.io/angularjs-jwt-auth
wingaru.auth.isAuthed = function () { return true; };
wingaru.auth.getUser = function () { return {'name':'John Doe', 'year':'Year 1'}; };
wingaru.auth.setToken = function (jwtToken) { $window.localStorage['jwtToken'] = token; };
wingaru.auth.getToken = function () { return $window.localStorage['jwtToken']; };
// NoSQL Storage (Firebase)
wingaru.games.getKey = function (auth, key) { return {'somekey':'somevalue'}};
wingaru.games.setKey() = function (auth, key, value) { return true; };
// Game Initialisation
winagru.games.add = function (gameId, assignmentId, startState, div) { return 'phaser_app';};
// Global Stats
wingaru.games.getConfig = function (gameId) { return {'title':'My Game'}; };
wingaru.games.getHighScore = function (gameId) { return {'score':'98'}; };
wingaru.games.getLeaderBoard = function (gameId) {return [{'name':'John Doe', 'score':'98'}]};
// User Stats
wingaru.games.getMyHighScore = function (gameId, user) { return {'score':'98'}; };
wingaru.games.getMyPreviousScores function (gameId, user) { return [{'score':'98'}]; };
//
// Integration Events
//
wingaru.games.on = wingaru.games.on || {};
// Reportable Events - these indicate items should go to the reporting database
wingaru.games.on.callStarted = function (gameId, assignmentId, user ) {};
wingaru.games.on.started = function (callback) {};
wingaru.games.on.callLeveled= function (gameId, assignmentId, user ) {};
wingaru.games.on.leveled = function (callback) {};
wingaru.games.on.callCompleted = function (gameId, assignmentId, user, score ) {};
wingaru.games.on.completed = function (callback) {};
// UX Only Events - At this stage no need to log to db
wingaru.games.on.callFlash = function (msg, type) {};
wingaru.games.on.flash = function (callback) {};
wingaru.games.on.callAchieved = function (gameId, assignmentId, user ) {};
wingaru.games.on.achieved = function (callback) {};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment