1
|
|
|
/** |
2
|
|
|
fusion |
3
|
|
|
Component that handles the fusion of isotopes to create new ones. |
4
|
|
|
|
5
|
|
|
@namespace Components |
6
|
|
|
*/ |
7
|
|
|
'use strict'; |
8
|
|
|
|
9
|
|
|
angular.module('game').component('fusionSelect', { |
10
|
|
|
templateUrl: 'views/fusion-select.html', |
11
|
|
|
controller: 'ct_fusion_select', |
12
|
|
|
controllerAs: 'ct', |
13
|
|
|
bindings: { |
14
|
|
|
source: '@', |
15
|
|
|
getCapacity: '&' |
16
|
|
|
} |
17
|
|
|
}); |
18
|
|
|
|
19
|
|
|
angular.module('game').controller('ct_fusion_select', ['state', 'data','$scope', |
20
|
|
|
function (state, data, $scope) { |
21
|
|
|
let ct = this; |
22
|
|
|
ct.state = state; |
23
|
|
|
ct.data = data; |
24
|
|
|
|
25
|
|
|
ct.availableIsotopes = function(player){ |
26
|
|
|
let result = []; |
27
|
|
|
for(let resource in data.resources){ |
28
|
|
|
let value = data.resources[resource]; |
29
|
|
|
for(let element in player.statistics.exotic_run){ |
30
|
|
|
let currentRun = player.statistics.exotic_run[element]; |
31
|
|
|
if(value.type.indexOf('isotope') !== -1 && |
32
|
|
|
currentRun[resource]){ |
33
|
|
|
result.push(resource); |
34
|
|
|
break; |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
return result; |
39
|
|
|
}; |
40
|
|
|
|
41
|
|
|
ct.setPercentage = function(percentage, player) { |
42
|
|
|
let fragment = player.fusion[0][ct.source]; |
43
|
|
|
fragment.number = Math.floor(player.resources[fragment.name].number*(percentage/100)); |
44
|
|
|
ct.fixNumber(player); |
45
|
|
|
}; |
46
|
|
|
|
47
|
|
|
ct.fixNumber = function(player) { |
48
|
|
|
let fragment = player.fusion[0][ct.source]; |
49
|
|
|
let resourceNumber = player.resources[fragment.name].number; |
50
|
|
|
let capacity = ct.getCapacity({resource: fragment.name, player:player}); |
51
|
|
|
fragment.number = Math.max(0, Math.min(resourceNumber, fragment.number, capacity)); |
52
|
|
|
}; |
53
|
|
|
|
54
|
|
|
// we watch for changes in the area to adjust the numbers if it goes down |
55
|
|
|
ct.listener = $scope.$watch('ct.state.player.global_upgrades_current.fusion_area', function(){ |
56
|
|
|
ct.fixNumber(state.player); |
57
|
|
|
}); |
58
|
|
|
} |
59
|
|
|
]); |
60
|
|
|
|