diff --git a/README.md b/README.md
index 9b239e9..5f0f1ce 100644
--- a/README.md
+++ b/README.md
@@ -13,43 +13,43 @@
### Battle service (not hooked to view model, will not have UI manifestation)
```javascript
- bt.services.execute('battleService', function(service) {
+ bt.services.execute('BattleService', function(service) {
service.getUsername(
function(data) { console.log("Success:"); console.log(data); },
function(data) { console.log("Fail:"); console.log(data); }
);
});
- bt.services.execute('battleService', function(service) {
+ bt.services.execute('BattleService', function(service) {
service.timeLeft(
function(data) { console.log("Success:"); console.log(data); },
function(data) { console.log("Fail:"); console.log(data); }
);
});
- bt.services.execute('battleService', function(service) {
+ bt.services.execute('BattleService', function(service) {
service.initialState(
function(data) { console.log("Success:"); console.log(data); },
function(data) { console.log("Fail:"); console.log(data); }
);
});
- bt.services.execute('battleService', function(service) {
+ bt.services.execute('BattleService', function(service) {
service.lastResult(
function(data) { console.log("Success:"); console.log(data); },
function(data) { console.log("Fail:"); console.log(data); }
);
});
- bt.services.execute('battleService', function(service) {
+ bt.services.execute('BattleService', function(service) {
service.getStates(
function(data) { console.log("Success:"); console.log(data); },
function(data) { console.log("Fail:"); console.log(data); }
);
});
- bt.services.execute('battleService', function(service) {
+ bt.services.execute('BattleService', function(service) {
service.getLastState(
function(data) { console.log("Success:"); console.log(data); },
function(data) { console.log("Fail:"); console.log(data); }
);
});
- bt.services.execute('battleService', function(service) {
+ bt.services.execute('BattleService', function(service) {
service.processAction(
'action type',
function(data) { console.log("Success:"); console.log(data); },
diff --git a/index.html b/index.html
index 5181fe7..aaa5398 100644
--- a/index.html
+++ b/index.html
@@ -8,18 +8,21 @@
-
+
-
+
+
-
-
@@ -28,7 +31,8 @@
-
+
+
diff --git a/res/css/main.css b/res/css/main.css
index a957916..a1a94e0 100644
--- a/res/css/main.css
+++ b/res/css/main.css
@@ -96,3 +96,39 @@ div.section {
font-size: 11px;
color: c6ff00;
}
+
+/* Page markup (TEMP)
+ * ---------------------------------------------------------------------------------------------------------------------- */
+
+div.menu {
+ clear: both;
+ float: left;
+ margin: 10px 0px 0px 0px;
+ padding: 4px;
+}
+div.menu div.link {
+ float: left;
+ margin: 0px 4px 0px 0px;
+}
+div.menu div.link a {
+ padding: 5px;
+ cursor: pointer;
+ border: 1px solid #444444;
+}
+div.menu div.link:hover a {
+ padding: 4px;
+ border: 2px solid #444444;
+}
+
+/* Battle view markup (TEMP)
+ * ---------------------------------------------------------------------------------------------------------------------- */
+
+div.timers {
+ float: right;
+ margin: 4px 10px 4px 10px;
+ padding: 4px;
+ border: 1px solid #444444;
+}
+div.timer {
+ color: #990000;
+}
\ No newline at end of file
diff --git a/res/js/bt_authentication.js b/res/js/bt_authentication.js
new file mode 100644
index 0000000..5c12ff2
--- /dev/null
+++ b/res/js/bt_authentication.js
@@ -0,0 +1,122 @@
+"use strict";
+
+ /* =====================================================================================================================
+ * Binary tactics: Authentication
+ * ================================================================================================================== */
+
+
+// Services
+// ---------------------------------------------------------------------------------------------------------------------
+
+// Authentication service
+/*
+ Console call syntax example:
+
+ bt.services.execute('authService', function(service) {
+ service.authenticate( 'atkr', 'atkr2', function() { alert("Success"); }, function() { alert("Fail!"); } );
+ });
+*/
+bt.services.authenticationService = app.factory('AuthenticationService', function ($http) {
+ return {
+
+ // Authenticate method, takes onSuccess and onFail callback functions
+ // Calls authentication service and trys authenticating user
+ authenticate : function(username, password, onSuccess, onFail, onError) {
+ // Check if authentication in progress
+ if (bt.game.authentication.login._isAuthenticating) return false;
+ // Update username and password
+ if (username != null) bt.game.authentication.login.username = username;
+ if (password != null) bt.game.authentication.login.password = password;
+ // Prompt authenticating
+ // Set authenticating username and status
+ bt.game.authentication.login._isAuthenticating = true;
+ bt.game.authentication.login._authUsername = bt.game.authentication.login.username
+ $http({
+
+ // Service call configuration
+ method: 'POST',
+ url: '/auth/login',
+ params : { u : bt.game.authentication.login.username, p : bt.game.authentication.login.password}
+
+ }).success(function(data, status, headers, config) {
+
+ // Handle response: Success / Check response
+ if (data.login == "successful") {
+ // Authenticate
+ bt.game.authentication.isAuthenticated = true;
+ bt.game.authentication.username = bt.game.authentication.login._authUsername;
+ // Execute callback
+ if (onSuccess) onSuccess(data, status, headers(), config);
+ // Fire event
+ bt.services.authenticationService.authenticationSuccessfull.dispatch( 'Authentication successfull.' );
+ } else {
+ // De-Authenticate
+ bt.game.authentication.isAuthenticated = false;
+ bt.game.authentication.username = '';
+ // Execute callback
+ if (onFail) onFail(data, status, headers(), config);
+ // Fire event
+ bt.services.authenticationService.authenticationFailed.dispatch( 'Authentication failed.' );
+ }
+ // Set authenticating status
+ bt.game.authentication.login._isAuthenticating = false;
+
+ }).error(function(data, status, headers, config) {
+
+ // De-Authenticate
+ bt.game.authentication.isAuthenticated = false;
+ bt.game.authentication.username = '';
+ // Execute callback
+ if (onError) onError(data, status, headers(), config);
+ if (onFail) onFail(data, status, headers(), config);
+ // Fire event
+ bt.services.authenticationService.authenticationError.dispatch( 'Authentication error!' );
+ // Set authenticating status
+ bt.game.authentication.login._isAuthenticating = false;
+
+ });
+ // Return 'started authentication'
+ return true;
+ }
+
+ }
+ });
+
+
+// Initialize common game functionality
+// ---------------------------------------------------------------------------------------------------------------------
+bt.game.authentication = {
+
+ // Holds authentication status
+ isAuthenticated : false,
+ // Holds user's username
+ username : '',
+
+ // Login functionality namespace
+ login : {
+
+ _isAuthenticating : false,
+ // Currently authenticating username
+ _authUsername : '',
+
+ // Holds user's username
+ username : 'atkr',
+ // Holds user's password
+ password : 'atkr'
+
+ },
+
+}
+
+
+// Custom events definitions
+// ---------------------------------------------------------------------------------------------------------------------
+
+// @ bt.services.authService
+
+// "Authentication successfull" event
+bt.events.define(bt.services.authenticationService, 'authenticationSuccessfull');
+// "Authentication failed" event (Fired when server invalidates authentication)
+bt.events.define(bt.services.authenticationService, 'authenticationFailed');
+// "Authentication error" event (Fired on authentication request error)
+bt.events.define(bt.services.authenticationService, 'authenticationError');
diff --git a/res/js/bt_config.js b/res/js/bt_config.js
index 6dee9d6..3f6dc7d 100644
--- a/res/js/bt_config.js
+++ b/res/js/bt_config.js
@@ -15,17 +15,8 @@ bt.config.urls = {
servicesUrl : '/battle/'
}
-// Add public views
-bt.config.views.addView('frontpage', {
- id : 'bt.game.common',
- name : 'frontpage',
- url : 'res/partials/views/frontpage.html',
- depth : 0,
- verify : function() { return true; },
- onLoad : function() { console.log('> Loading frontpage view!'); },
- onUnload : function() { console.log('> Unloading frontpage view!'); }
- });
-bt.navigation.selectView( bt.config.views.viewsByName.frontpage );
+// Set poling
+bt.config.poling.minimalIntervalBetweenPolls = 2000;
// Set debugging options
-bt.debugging.events.pushToConsole = true;
+bt.debugging.events.publishToConsole = true;
diff --git a/res/js/bt_game.js b/res/js/bt_game.js
deleted file mode 100644
index 99cdeda..0000000
--- a/res/js/bt_game.js
+++ /dev/null
@@ -1,152 +0,0 @@
-"use strict";
-
- /* =====================================================================================================================
- * Binary tactics: Common game functionalities
- * ================================================================================================================== */
-
-
-// Services
-// ---------------------------------------------------------------------------------------------------------------------
-
-// Authentication service
-/*
- Console call syntax example:
-
- bt.services.execute('authService', function(service) {
- service.authenticate( 'atkr', 'atkr2', function() { alert("Success"); }, function() { alert("Fail!"); } );
- });
-*/
-bt.services.authService = app.factory('authService', function ($http) {
- return {
-
- // Authenticate method, takes onSuccess and onFail callback functions
- // Calls authentication service and trys authenticating user
- authenticate : function(username, password, onSuccess, onFail, onError) {
- // Check if authentication in progress
- if (bt.game.common.user.login._isAuthenticating) return false;
- // Update username and password
- if (username != null) bt.game.common.user.login.username = username;
- if (password != null) bt.game.common.user.login.password = password;
- // Prompt authenticating
- // Set authenticating username and status
- bt.game.common.user.login._isAuthenticating = true;
- bt.game.common.user.login._authUsername = bt.game.common.user.login.username
- $http({
-
- // Service call configuration
- method: 'POST',
- url: '/auth/login',
- params : { u : bt.game.common.user.login.username, p : bt.game.common.user.login.password}
-
- }).success(function(data, status, headers, config) {
-
- // Handle response: Success / Check response
- if (data.login == "successful") {
- // Authenticate
- bt.game.common.user.username = bt.game.common.user.login._authUsername;
- // Execute callback
- if (onSuccess) onSuccess(data, status, headers(), config);
- // Fire event
- bt.services.authService.authSuccess.dispatch({
- detail: {
- message:'Authentication successfull.',
- time: new Date(),
- },
-
- });
- } else {
- // Execute callback
- if (onFail) onFail(data, status, headers(), config);
- // Fire event
- bt.services.authService.authFail.dispatch({
- detail: {
- message:'Authentication failed.',
- time: new Date(),
- },
-
- });
- }
- // Set authenticating status
- bt.game.common.user.login._isAuthenticating = false;
-
- }).error(function(data, status, headers, config) {
-
- // Execute callback
- if (onError) onError(data, status, headers(), config);
- if (onFail) onFail(data, status, headers(), config);
- // Fire event
- bt.services.authService.authError.dispatch({
- detail: {
- message:'Authentication error!',
- time: new Date(),
- },
-
- });
- // Set authenticating status
- bt.game.common.user.login._isAuthenticating = false;
-
- });
- // Return 'started authentication'
- return true;
- }
-
- }
- });
-
-
-// Initialize common game functionality
-// ---------------------------------------------------------------------------------------------------------------------
-bt.game.common = {
-
- // Game common, angular references namespace
- ng : {
-
- // Reference to 'game common' controller
- controller : app.controller('bt.game.common.ng.controller', function($scope, authService) {
- // Set controller name (for scope detection/testing)
- $scope.controllerName = "bt.game.common.ng.controller";
- // Set reference to app namespace
- $scope.bt = bt;
- // Set reference to services
- $scope.services = {
- auth : authService
- };
- }).controller
-
- },
-
- // User namespace
- user : {
-
- // Holds user's username
- username : '',
-
- // Login functionality namespace
- login : {
-
- _isAuthenticating : false,
- // Currently authenticating username
- _authUsername : '',
-
- // Holds user's username
- username : 'atkr',
- // Holds user's password
- password : 'atkr'
-
- },
-
- }
-
-}
-
-// Custom events definitions
-// ---------------------------------------------------------------------------------------------------------------------
-
-// @ bt.services.authService
-
-// "Authentication successfull" event
-bt.events.define(bt.services.authService, 'authSuccess');
-// "Authentication failed" event (Fired when server invalidates authentication)
-bt.events.define(bt.services.authService, 'authFail');
-// "Authentication error" event (Fired on authentication request error)
-bt.events.define(bt.services.authService, 'authError');
diff --git a/res/js/bt_game_battle.js b/res/js/bt_game_battle.js
index 923ed1e..3dc728b 100644
--- a/res/js/bt_game_battle.js
+++ b/res/js/bt_game_battle.js
@@ -7,15 +7,15 @@
// Initialize battle view
// ---------------------------------------------------------------------------------------------------------------------
-bt.config.views.addView('battleView', {
- id : 'bt.game.battle',
- name : 'battle view ( ... must login first )',
- url : 'res/partials/views/battle.html',
- depth : 2,
- verify : function() { return (bt.game.common.user.username != null) && (bt.game.common.user.username.length > 0); },
- onLoad : function() { console.log('> Loading battle view!'); },
- onUnload : function() { console.log('> Unloading battle view!'); }
- });
+bt.config.views.addView('battle', {
+ id : 'bt.game.battle',
+ name : 'BATTLE',
+ url : 'res/partials/views/battle.html',
+ depth : 2,
+ isPublic : false,
+ onLoad : function() { bt.game.battle.view.onLoad(); },
+ onUnload : function() { bt.game.battle.view.onUnload(); }
+ }, false, true);
// Services
@@ -25,14 +25,14 @@ bt.config.views.addView('battleView', {
/*
Console call syntax example:
- bt.services.execute('battleService', function(service) {
+ bt.services.execute('BattleService', function(service) {
service.getUsername(
function(data) { console.log("Success:"); console.log(data); },
function(data) { console.log("Fail:"); console.log(data); }
);
});
*/
-bt.services.battleService = app.factory('battleService', function (jsonRpc) {
+bt.services.battleService = app.factory('BattleService', function (jsonRpc) {
// Settup service
jsonRpc.setup( { 'url': bt.config.urls.servicesUrl } );
// Map service
@@ -63,17 +63,137 @@ bt.game.battle = {
ng : {
// Reference to 'game common' controller
- controller : app.controller('bt.game.battle.ng.controller', function($scope, battleService) {
+ controller : app.controller('bt.game.battle.ng.controller', function($scope, BattleService) {
// Set controller name (for scope detection/testing)
$scope.controllerName = "bt.game.battle.ng.controller";
// Set reference to app namespace
$scope.bt = bt;
// Set reference to services
$scope.services = {
- battle : battleService
+ battle : BattleService
};
}).controller
+ },
+
+ // View manipulation namespace
+ view : {
+ // On view load
+ onLoad : function() {
+ // Query server time
+ bt.game.battle.timers.query();
+ // Start timer interval
+ if (bt.game.battle.timers._interval) clearInterval(bt.game.battle.timers._interval);
+ bt.game.battle.timers._interval = setInterval(bt.game.battle.timers.update, 1000);
+ },
+ // On view unload
+ onUnload : function() {
+ // Stop timer interval
+ if (bt.game.battle.timers._interval) clearInterval(bt.game.battle.timers._interval);
+ },
+ },
+
+ // Battle timers namespace
+ timers : {
+
+ // Holds refreshing interval reference
+ _interval : null,
+
+ // Holds time of last timers query with battle service
+ _lastQueryTime : null,
+ // Holds last queryed remaining battle time
+ _battleTime : null,
+ // Holds last queryed remaining play (turn) time
+ _playTime : null,
+
+ // Holds remaining battle time
+ battleTime : null,
+ // Holds remaining play (turn) time
+ playTime : null,
+
+ // Parses server timer format to milliseconds
+ _parseServerTime : function(time) {
+ var parsed = time.split(':');
+ return 1000 * ((parseFloat(parsed[0]) * 3600) + (parseFloat(parsed[1]) * 60) + parseFloat(parsed[2]));
+ },
+
+ // Querys timers with battle service
+ query : function() {
+ // Check time since last query
+ if ((new Date() - bt.game.battle.timers._lastQueryTime) > bt.config.poling.minimalIntervalBetweenPolls) {
+ // Query timers from service
+ bt.services.execute('BattleService', function(service) {
+ service.timeLeft(
+ // Success callback
+ function(data) {
+ // Set data
+ if ((data) && (data.battle) && (data.ply)) {
+ bt.game.battle.timers._battleTime = bt.game.battle.timers._parseServerTime(data.battle);
+ bt.game.battle.timers._playTime = bt.game.battle.timers._parseServerTime(data.ply);
+ bt.game.battle.timers._lastQueryTime = new Date();
+ // Fire event
+ bt.services.battleService.Called.dispatch({
+ message: 'Response from "BattleService.timeLeft()".',
+ data : data
+ });
+ // Update timers
+ bt.game.battle.timers.update();
+ } else {
+ // Fire event
+ bt.services.battleService.Error.dispatch({
+ message: 'Error calling "BattleService.timeLeft()"!',
+ data : data
+ });
+ }
+ },
+ // Fail callback
+ function(data) {
+ // Fire event
+ bt.services.battleService.Error.dispatch({
+ message: 'Error calling "BattleService.timeLeft()"!',
+ data : data
+ });
+ }
+ );
+ });
+ }
+ },
+
+ // Updates timers based on last queryed values (calls query if no values)
+ update : function() {
+ // Check for last queryed values
+ if (!bt.game.battle.timers._lastQueryTime) {
+ // Query values
+ bt.game.battle.timers.query();
+ } else {
+ // Recalculate values
+ var diff = (new Date()) - bt.game.battle.timers._lastQueryTime;
+ bt.services.execute('BattleService', function(service) {
+ var battleTime = (bt.game.battle.timers._battleTime - diff) / 1000;
+ bt.game.battle.timers.battleTime = Math.floor(battleTime / 3600) + ' : ' + Math.floor((battleTime % 3600) / 60) + ' : ' + Math.floor(battleTime % 60);
+ var playTime = (bt.game.battle.timers._playTime - diff) / 1000;
+ bt.game.battle.timers.playTime = Math.floor(playTime / 3600) + ' : ' + Math.floor((playTime % 3600) / 60) + ' : ' + Math.floor(playTime % 60);
+ });
+ // Fire event
+ bt.services.battleService.Updated.dispatch({
+ message: 'Updated "BattleService" timers',
+ });
+ }
+ }
+
}
}
+
+
+// Custom events definitions
+// ---------------------------------------------------------------------------------------------------------------------
+
+// @ bt.services.battleService
+
+// "Service call successfull" event
+bt.events.define(bt.services.battleService, 'Called');
+// "Service call error" event
+bt.events.define(bt.services.battleService, 'Error');
+// "Service call successfull" event
+bt.events.define(bt.services.battleService, 'Updated');
diff --git a/res/js/bt_game_equanimity.js b/res/js/bt_game_equanimity.js
index d632fbb..f56c110 100644
--- a/res/js/bt_game_equanimity.js
+++ b/res/js/bt_game_equanimity.js
@@ -7,12 +7,12 @@
// Initialize equanimity view
// ---------------------------------------------------------------------------------------------------------------------
-bt.config.views.addView('equanimityView', {
+bt.config.views.addView('equanimity', {
id : 'bt.game.equanimity',
- name : 'equanimity view ( ... must login first )',
+ name : 'EQUANIMITY',
url : 'res/partials/views/equanimity.html',
depth : 2,
- verify : function() { return (bt.game.common.user.username != null) && (bt.game.common.user.username.length > 0); },
+ isPublic : false,
onLoad : function() { console.log('> Loading equanimity view!'); },
onUnload : function() { console.log('> Unloading equanimity view!'); }
});
diff --git a/res/js/bt_game_equipment.js b/res/js/bt_game_equipment.js
index ecf44b9..7e0b315 100644
--- a/res/js/bt_game_equipment.js
+++ b/res/js/bt_game_equipment.js
@@ -7,12 +7,12 @@
// Initialize battle view
// ---------------------------------------------------------------------------------------------------------------------
-bt.config.views.addView('equipmentView', {
+bt.config.views.addView('equipment', {
id : 'bt.game.equipment',
- name : 'equipment view ( ... must login first )',
+ name : 'EQUIPMENT',
url : 'res/partials/views/equipment.html',
depth : 2,
- verify : function() { return (bt.game.common.user.username != null) && (bt.game.common.user.username.length > 0); },
+ isPublic : false,
onLoad : function() { console.log('> Loading equipment view!'); },
onUnload : function() { console.log('> Unloading equipment view!'); }
});
diff --git a/res/js/bt_game_frontpage.js b/res/js/bt_game_frontpage.js
new file mode 100644
index 0000000..d1bb10e
--- /dev/null
+++ b/res/js/bt_game_frontpage.js
@@ -0,0 +1,43 @@
+"use strict";
+
+ /* =====================================================================================================================
+ * Binary tactics: Frontpage game functionalities
+ * ================================================================================================================== */
+
+
+// Initialize battle view
+// ---------------------------------------------------------------------------------------------------------------------
+
+bt.config.views.addView('frontpage', {
+ id : 'bt.game.frontpage',
+ name : 'Frontpage',
+ url : 'res/partials/views/frontpage.html',
+ depth : 0,
+ isPublic : true,
+ onLoad : function() { console.log('> Loading frontpage view!'); },
+ onUnload : function() { console.log('> Unloading frontpage view!'); }
+ }, true, false);
+
+
+// Initialize frontpage game functionality
+// ---------------------------------------------------------------------------------------------------------------------
+bt.game.frontpage = {
+
+ // Game common, angular references namespace
+ ng : {
+
+ // Reference to 'game common' controller
+ controller : app.controller('bt.game.frontpage.ng.controller', function($scope, AuthenticationService) {
+ // Set controller name (for scope detection/testing)
+ $scope.controllerName = "bt.game.frontpage.ng.controller";
+ // Set reference to app namespace
+ $scope.bt = bt;
+ // Set reference to services
+ $scope.services = {
+ authenticationService : AuthenticationService
+ };
+ }).controller
+
+ }
+
+}
\ No newline at end of file
diff --git a/res/js/bt_init.js b/res/js/bt_init.js
index 970bbb8..0f29570 100644
--- a/res/js/bt_init.js
+++ b/res/js/bt_init.js
@@ -13,7 +13,7 @@
var btView = function(obj) {
// Inherits from passed object
if ((obj !== null) && (typeof obj == 'object')) {
- this.extend(obj);
+ angular.extend(this, obj);
}
// Set uninherited properties
if (this.id == null) this.id = '';
@@ -21,9 +21,14 @@ var btView = function(obj) {
if (this.url == null) this.url = '';
if (this.depth == null) this.depth = 0;
// Set uninherited methods
- if (this.verify == null) this.verify = function() { return true; };
+ if (this.isPublic == null) this.isPublic = true;
if (this.onLoad == null) this.onLoad = null;
if (this.onUnload == null) this.onUnload = null;
+
+ // Validate method: checks if view can be loaded
+ if (this.validate == null) this.validate = function() {
+ return ((this.isPublic) || ((bt.game) && (bt.game.authentication) && (bt.game.authentication.isAuthenticated)));
+ }
}
@@ -61,80 +66,41 @@ var bt = {
// Holds dictionary of avaliable views by name
viewsByName : { /* Filled implicitly from other JS scripts */ },
+ // Holds reference to currently selected view
+ _currentView : null,
+ // Holds default public (unauthenticated) view
+ _defaultPublicView : null,
+ // Holds default private (authenticated) view
+ _defaultPrivateView : null,
+
// Adds new view
- addView : function(name, view) {
+ addView : function(name, view, isDefaultPublic, isDefaultAuthenticated) {
+ // Wrap view as btView object
+ view = new btView(view);
+ // Check defaults
+ if (isDefaultPublic) bt.config.views._defaultPublicView = view;
+ if (isDefaultAuthenticated) bt.config.views._defaultPrivateView = view;
+ // Set ordering properties
+ view._index = bt.config.views.viewsArray.length;
+ view._key = name;
+ // Add view to registry
bt.config.views.viewsArray.push(view);
bt.config.views.viewsByName[name] = view;
+ // Set route
+ app.config(['$routeProvider', function($routeProvider) {
+ // Set route to view
+ $routeProvider .when('/' + view._key, { templateUrl: view.url })
+ .otherwise('/');
+ }]);
}
- }
-
- },
-
- // Navigation (between views) namespace
- navigation : {
+ },
- // Holds reference to the selected view
- selectedView : null,
- // Holds reference to next view
- nextView : null,
- // Selects passed view
- selectView : function(view) {
- // Get next view
- if (view == null) {
- // Already got next view
- } else if (typeof view == 'object') {
- // Set view object
- bt.navigation.nextView = view;
- } else {
- // Get object by name
- for (var i in bt.config.views) {
- if (bt.config.views[i].name == view) {
- bt.navigation.nextView = bt.config.views[i];
- break;
- }
- }
- }
- // Check next view
- if ((bt.navigation.nextView != null)) {
- // Verify view available
- if (bt.navigation.nextView.verify()) {
- // Select transition effect
- bt.effects.viewChange = ((bt.navigation.selectedView == null) || (bt.navigation.nextView.depth > bt.navigation.selectedView.depth) ? bt.effects.viewChangeIn : bt.effects.viewChangeOut);
- // Run onLoad and onUnload callbacks
- if ((bt.navigation.selectedView != null) && (bt.navigation.selectedView.onUnload != null)) bt.navigation.selectedView.onUnload();
- if ((bt.navigation.nextView != null) && (bt.navigation.nextView.onLoad != null)) bt.navigation.nextView.onLoad();
- // Select view
- bt.navigation.selectedView = bt.navigation.nextView;
- // Fire event
- bt.navigation.viewChanged.dispatch({
- detail: {
- message:'View "' + bt.navigation.nextView.name + '" selected.',
- time: new Date(),
- }
- });
- } else {
- // Fire event
- bt.navigation.viewRejected.dispatch({
- detail: {
- message:'View "' + bt.navigation.nextView.name + '" verification rejected.',
- time: new Date(),
- }
- });
- // Clean up
- bt.navigation.nextView = bt.navigation.selectedView;
- }
- } else {
- // Fire event
- bt.navigation.viewError.dispatch({
- detail: {
- message:'Failed loading view!',
- time: new Date(),
- }
- });
- // Clean up
- bt.navigation.nextView = bt.navigation.selectedView;
- }
+ // Server poling namespace
+ poling : {
+
+ // Holds value for minimal time interval between polling same service in [ms]
+ minimalIntervalBetweenPolls : 2000
}
@@ -184,7 +150,7 @@ var bt = {
events : {
// Toggles events push to console
- _pushToConsole : true,
+ publishToConsole : true,
// Holds event listeners
_listeners : [ ],
@@ -218,10 +184,13 @@ var bt = {
},
// Dispatch event for target
dispatch : function(target, eventName, event) {
+ // Format event
+ if (typeof event == 'string') event = { message : event, time : new Date() };
// Check if pushing to console
if (bt.debugging.events.publishToConsole) {
- console.log('Event "' + eventName + '" dispatched to ' + (target[eventName]._bt_event_subscribed ? target[eventName]._bt_event_subscribed.length : '0') + ' listeners! Event fired by:');
+ console.log('>>> Event "' + eventName + '" dispatched to ' + (target[eventName]._bt_event_subscribed ? target[eventName]._bt_event_subscribed.length : '0') + ' listeners! Folowing event / target:');
console.log(target);
+ console.log(event);
}
// Process event listeners
if (target[eventName]._bt_event_subscribed) {
@@ -253,16 +222,75 @@ var bt = {
// @ bt.navigation
// "View changed" event
-bt.events.define(bt.navigation, 'viewChanged');
+bt.events.define(bt.config.views, 'viewAccepted');
// 'View rejected' event (Fired when view verification fails)
-bt.events.define(bt.navigation, 'viewRejected');
+bt.events.define(bt.config.views, 'viewPrevented');
+// 'View rejected' event (Fired when view verification fails)
+bt.events.define(bt.config.views, 'viewChanged');
// 'View error' event (Fired when view loading fails)
-bt.events.define(bt.navigation, 'viewError');
+bt.events.define(bt.config.views, 'viewFailed');
// Startup
// ---------------------------------------------------------------------------------------------------------------------
+// Handle route changes and view verification
+app.run( function($rootScope, $location) {
+
+ // Handle route changing event
+ $rootScope.$on( "$routeChangeStart", function(event, next, current) {
+ // Find and validate route/view
+ if (next.templateUrl) {
+ for (var name in bt.config.views.viewsByName) {
+ var view = bt.config.views.viewsByName[name];
+ if ((next.templateUrl == view.url) && (view.validate())) {
+ // Selected view validated
+ if (view != bt.config.views._currentView) {
+ if (bt.config.views._currentView) bt.config.views._currentView.onUnload();
+ view.onLoad();
+ bt.config.views._currentView = view;
+ }
+ bt.config.views.viewAccepted.dispatch( 'View "' + next.templateUrl + '" selected.' );
+ return;
+ }
+ }
+ }
+ // Prevent route
+ event.preventDefault();
+ bt.config.views.viewPrevented.dispatch( 'View "' + next.templateUrl + '" prevented.' );
+ // Fallback to default route
+ if (bt.config.views._defaultPrivateView.validate()) {
+ next.templateUrl = bt.config.views._defaultPrivateView.url;
+ if (view != bt.config.views._currentView) {
+ if (bt.config.views._currentView) bt.config.views._currentView.onUnload();
+ bt.config.views._defaultPrivateView.onLoad();
+ bt.config.views._currentView = bt.config.views._defaultPrivateView;
+ }
+ $location.path('/' + bt.config.views._defaultPrivateView._key);
+ } else {
+ next.templateUrl = bt.config.views._defaultPublicView.url;
+ if (view != bt.config.views._currentView) {
+ if (bt.config.views._currentView) bt.config.views._currentView.onUnload();
+ bt.config.views._defaultPublicView.onLoad();
+ bt.config.views._currentView = bt.config.views._defaultPublicView;
+ }
+ $location.path('/' + bt.config.views._defaultPublicView._key);
+ }
+ });
+
+ // Handle route changed or failed events
+ $rootScope.$on( "$routeChangeSuccess", function(event, next, current) {
+ // Selected view validated
+ bt.config.views.viewChanged.dispatch( 'View "' + next.templateUrl + '" changed.' );
+ });
+ $rootScope.$on( "$routeChangeError", function(event, next, current) {
+ // Selected view validated
+ bt.config.views.viewFailed.dispatch( 'View "' + next.templateUrl + '" failed.' );
+ });
+
+ });
+
+// On loaded
window.addEventListener('load', function() {
// Nothing so far ...
diff --git a/res/partials/views/battle.html b/res/partials/views/battle.html
index e450940..1eaa2a6 100644
--- a/res/partials/views/battle.html
+++ b/res/partials/views/battle.html
@@ -1,8 +1,14 @@
-
+
BATTLE VIEW !!!
Controller: {{ controllerName }}
+
+
Timers:
+
{{ bt.game.battle.timers.battleTime }}
+
{{ bt.game.battle.timers.playTime }}
+
+
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
diff --git a/res/partials/views/frontpage.html b/res/partials/views/frontpage.html
index 59c6f28..485ece4 100644
--- a/res/partials/views/frontpage.html
+++ b/res/partials/views/frontpage.html
@@ -1,11 +1,11 @@
-