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
|
|
|
|