Completed
Push — master ( cb546c...aa32d1 )
by Andres
26s
created

angular.controller(ꞌct_upgradesꞌ)   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
dl 0
loc 31
rs 8.8571
nop 4

4 Functions

Rating   Name   Duplication   Size   Complexity  
A ��) 0 3 1
A ��) 0 10 1
A ��) 0 3 1
A ��) 0 4 1
1
/**
2
 upgrades
3
 Component that handles upgrades.
4
5
 @namespace Components
6
 */
7
'use strict';
8
9
angular.module('game').component('upgrades', {
10
  templateUrl: 'views/upgrades.html',
11
  controller: 'ct_upgrades',
12
  controllerAs: 'ct'
13
});
14
15
angular.module('game').controller('ct_upgrades', ['state', 'visibility', 'upgrade', 'data',
16
function(state, visibility, upgradeService, data) {
17
  let ct = this;
18
  ct.state = state;
19
  ct.data = data;
20
  ct.upgradeService = upgradeService;
21
  let sortFunc = upgradeService.sortFunctions(data.upgrades);
22
23
  ct.buyUpgrade = function (name, slot, player) {
24
    let price = data.upgrades[name].price;
25
    let currency = data.elements[slot.element].main;
26
    upgradeService.buyUpgrade(player,
27
      slot.upgrades,
28
      data.upgrades[name],
29
      name,
30
      price,
31
      currency);
32
  };
33
34
  ct.visibleUpgrades = function(slot, player) {
35
    return visibility.visible(data.upgrades, isBasicUpgradeVisible, slot, sortFunc[player.options.sortIndex], player);
36
  };
37
38
  function isBasicUpgradeVisible(name, slot, player) {
39
    let isVisible = visibility.isUpgradeVisible(name, slot, data.upgrades[name], player);
40
    return isVisible && (!player.options.hideBought || !slot.upgrades[name]);
41
  }
42
43
  ct.visibleGlobalUpgrades = function() {
44
    return visibility.visible(data.global_upgrades, upgradeService.filterByTag('global'));
45
  };
46
}
47
]);
48