src/scripts/controllers/main-loop.js   A
last analyzed

Complexity

Total Complexity 6
Complexity/F 1.5

Size

Lines of Code 56
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 0
wmc 6
c 2
b 0
f 0
nc 1
mnd 2
bc 6
fnc 4
dl 0
loc 56
rs 10
bpm 1.5
cpm 1.5
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B angular.controller(ꞌmain-loopꞌ) 0 43 1
1
'use strict';
2
3
angular
4
  .module('game')
5
  .controller('main-loop', ['$scope',
6
    '$interval',
7
    '$timeout',
8
    'savegame',
9
    'state',
10
    'data',
11
    'util',
12
    'reaction',
13
    function($scope, $interval, $timeout, savegame, state, data, util, reaction) {
14
      $scope.state = state;
15
      $scope.data = data;
16
      $scope.util = util;
17
18
      let self = this;
19
20
      self.update = function() {
21
        state.reactions = [];
22
        state.update(state.player);
23
        reaction.processReactions(state.reactions, state.player);
24
      };
25
26
      self.updateLoop = function() {
27
        self.update();
28
        let speed = 1000;
29
        if(state.fasterTicks){
30
          speed = 1;
31
          state.player.offline--;
32
          if(state.player.offline <= 0){
33
            state.fasterTicks = 0;
34
          }
35
        }
36
        $timeout(self.updateLoop, speed);
37
      };
38
39
      self.startup = function() {
40
        savegame.load();
41
        let elapsed = Math.floor(Date.now()/1000)-state.player.last_login;
42
        let total = util.calculateValue(data.global_upgrades.offline_time.power.base,
43
            data.global_upgrades.offline_time.power,
44
            state.player.global_upgrades.offline_time);
45
        // lets limit the offline elapsed time
46
        state.player.offline = Math.min(total, state.player.offline+elapsed);
47
48
        state.loading = false;
49
        // trigger the game loop
50
        $timeout(self.updateLoop, 1000);
51
        $interval(savegame.save, 10000);
52
      };
53
54
      $timeout(self.startup);
55
    }
56
  ]);
57