| Total Complexity | 4 |
| Complexity/F | 1 |
| Lines of Code | 54 |
| Function Count | 4 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
| 1 | 'use strict'; |
||
| 2 | |||
| 3 | angular |
||
| 4 | .module('game') |
||
| 5 | .controller('main-loop', ['$scope', |
||
| 6 | '$interval', |
||
| 7 | '$timeout', |
||
| 8 | 'savegame', |
||
| 9 | 'achievement', |
||
| 10 | 'util', |
||
| 11 | 'format', |
||
| 12 | 'reaction', |
||
| 13 | 'data', |
||
| 14 | 'visibility', |
||
| 15 | 'state', |
||
| 16 | function($scope, $interval, $timeout, savegame, achievement, util, format, reaction, data, visibility, state) { |
||
| 17 | $scope.data = data; |
||
| 18 | $scope.achievement = achievement; |
||
| 19 | $scope.util = util; |
||
| 20 | $scope.format = format; |
||
| 21 | $scope.reaction = reaction; |
||
| 22 | $scope.visibility = visibility; |
||
| 23 | $scope.state = state; |
||
| 24 | |||
| 25 | let self = this; |
||
| 26 | let playerCopy = null; |
||
| 27 | |||
| 28 | self.update = function() { |
||
| 29 | // do the update in a copy |
||
| 30 | playerCopy = angular.copy(state.player); |
||
| 31 | achievement.checkAchievements(playerCopy); |
||
| 32 | |||
| 33 | state.update(playerCopy); |
||
| 34 | |||
| 35 | // and update all at once |
||
| 36 | state.player = playerCopy; |
||
| 37 | |||
| 38 | $timeout(self.update, 1); |
||
| 39 | }; |
||
| 40 | |||
| 41 | function save() { |
||
| 42 | localStorage.setItem('playerStoredITE', JSON.stringify(state.player)); |
||
| 43 | } |
||
| 44 | |||
| 45 | self.startup = function() { |
||
| 46 | savegame.load(); |
||
| 47 | state.loading = false; |
||
| 48 | $timeout(self.update, 1000); |
||
| 49 | $interval(save, 10000); |
||
| 50 | }; |
||
| 51 | |||
| 52 | $timeout(self.startup); |
||
| 53 | } |
||
| 54 | ]); |
||
| 55 |