'use strict'; (function() { var game = new Game.Game(); game.load(); var lab = game.lab; var research = game.research; var workers = game.workers; var upgrades = game.upgrades; var achievements = game.achievements; UI.validateVersion(lab.version); var app = angular.module('particleClicker', []); app.filter('niceNumber', ['$filter', function($filter) { return Helpers.formatNumberPostfix; }]); app.filter('currency', ['$filter', function($filter) { return function(input) { return 'JTN ' + $filter('niceNumber')(input); }; }]); app.filter('reverse', ['$filter', function($filter) { return function(items) { return items.slice().reverse(); }; }]); app.controller('DetectorController', function() { this.click = function() { lab.acquireData(lab.state.detector); detector.addEvent(); UI.showUpdateValue("#update-data", lab.state.detector); return false; }; }); app.controller('LabController', ['$interval', function($interval) { this.lab = lab; this.showDetectorInfo = function() { if (!this._detectorInfo) { this._detectorInfo = Helpers.loadFile('html/detector.html'); } UI.showModal('Detector', this._detectorInfo); }; $interval(function() { // one tick var grant = lab.getGrant(); UI.showUpdateValue("#update-funding", grant); var sum = 0; for (var i = 0; i < workers.length; i++) { sum += workers[i].state.hired * workers[i].state.rate; } if (sum > 0) { lab.acquireData(sum); UI.showUpdateValue("#update-data", sum); detector.addEventExternal(workers.map(function(w) { return w.state.hired; }).reduce(function(a, b){return a + b}, 0)); } }, 1000); }]); app.controller('ResearchController', ['$compile', function($compile) { this.research = research; this.isVisible = function(item) { return item.isVisible(lab); }; this.isAvailable = function(item) { return item.isAvailable(lab); }; this.doResearch = function(item) { var cost = item.research(lab); if (cost > 0) { UI.showUpdateValue("#update-data", -cost); UI.showUpdateValue("#update-reputation", item.reputation); } }; this.showInfo = function(r) { UI.showModal(r.name, r.getInfo()); UI.showLevels(r.level); }; }]); app.controller('HRController', function() { this.workers = workers; this.isVisible = function(worker) { return worker.isVisible(lab); }; this.isAvailable = function(worker) { return worker.isAvailable(lab); }; this.hire = function(worker) { var cost = worker.hire(lab); if (cost > 0) { UI.showUpdateValue("#update-funding", -cost); } }; }); app.controller('UpgradesController', function() { this.upgrades = upgrades; this.isVisible = function(upgrade) { return upgrade.isVisible(lab); }; this.isAvailable = function(upgrade) { return upgrade.isAvailable(lab); }; this.upgrade = function(upgrade) { if (upgrade.buy(lab)) { UI.showUpdateValue("#update-funding", upgrade.cost); } } }); app.controller('AchievementsController', function($scope) { $scope.achievements = achievements; $scope.progress = function() { return achievements.filter(function(a) { a.isAchieved(); }).length; }; }); app.controller('SaveController', ['$scope', '$interval', function($scope, $interval) { $scope.lastSaved = new Date(); $scope.saveNow = function() { game.save(); $scope.lastSaved = new Date(); }; $scope.restart = function() { if (window.confirm( 'Do you really want to restart the game? All progress will be lost.' )) { ObjectStorage.clear(); window.location.reload(true); } }; $interval($scope.saveNow, 10000); }]); analytics.init(); analytics.sendScreen(analytics.screens.main); })();