(function () {
var app = angular.module('main-app', ['AutoFont', 'VAligner', 'network-app']);
app.factory('ViewService', function () {
var obj = function () {
var _currentViewName = 'accounts';
this.__defineGetter__('currentViewName', function () {
return _currentViewName;
});
this.__defineSetter__('currentViewName', function (name) {
_currentViewName = name;
triggerAll();
});
var listeners = [];
this.addListener = function (listener) {
listeners.push(listener);
};
var triggerAll = function () {
for (var i = 0; i < listeners.length; i++) {
if (typeof(listeners[i]) === 'function') {
listeners[i]();
}
}
}
};
return new obj();
});
app.value('AppData', {
userInfo: {}
});
app.controller('MainController', ['$scope', 'ViewService', 'AppData', function ($scope, ViewService, AppData) {
$scope.getCurrentViewName = function () {
return ViewService.currentViewName;
};
$scope.getLogin = function () {
return AppData.login;
}
}]);
app.controller('GameController', ['$scope', 'NetworkService', 'ViewService', function ($scope, NetworkService, ViewService) {
this.gameData = {};
var self = this;
NetworkService.addTagListener('GameData', function (data) {
for (var key in data.data) {
if (!data.data.hasOwnProperty(key)) {
continue;
}
self.gameData[key] = data.data[key];
}
if (data.game_status == 'started') {
ViewService.currentViewName = 'round';
}
$scope.$apply();
});
this.remainingWaiting = 10;
this.costs = [100, 200, 300, 400, 500, 600, 700, 800].reverse();
this.currentCostId = 3;
this.bank = {
value: 1000,
enabled: false
};
this.players = [];
this.currentPlayer = this.players[1];
this.currentQuestion = {
quest: 'This is question',
answers: ['answer1', 'answer2', 'answer3'],
selected: 0,
correct: 1
};
this.myTurn = false;
this.me = this.players[0];
this.timer = {
round: 100
};
this.final = {
finalists: [this.players[0], this.players[1]],
checks: [[0, 0], [0, 1], [1, 0], [1, 1]]
}
}]);
app.controller('AccountsController', ['$scope', '$timeout', 'AppData', 'ViewService', 'NetworkService',
function ($scope, $timeout, AppData, ViewService, NetworkService) {
this.accounts = ['1', '2', '3', '4', '5', '6'];
this.setAccount = function(login) {
ViewService.currentViewName = 'menu';
NetworkService.addTagListener('UserInfo', function (data) {
console.log('userInfo');
console.log(data.data);
AppData.userInfo = data.data;
});
NetworkService.handshake('sivsais');//login);
};
}]);
app.controller('MenuController', ['$scope', 'ViewService', 'AppData', 'NetworkService',
function ($scope, ViewService, AppData, NetworkService) {
$scope.setCurrentViewName = function (name) {
ViewService.currentViewName = name;
};
this.soundEnabled = true;
this.onButtonClicked = function (id) {
if (id == 0) {
ViewService.currentViewName = 'waiting';
NetworkService.send(AppData.userInfo.ID, 'C_Misc', 'C_PLAY', {});
}
}
}]);
app.directive('view', ['ViewService', function (ViewService) {
return {
restrict: 'E',
link: function (scope, elem, attrs) {
scope.currentUrl = 'views/' + ViewService.currentViewName + '/' + ViewService.currentViewName + '.html';
ViewService.addListener(function () {
scope.currentUrl = 'views/' + ViewService.currentViewName + '/' + ViewService.currentViewName + '.html';
});
},
template: '<div ng-include="currentUrl"></div>'//,
}
}]);
})();