|
1
|
|
|
/** |
|
2
|
|
|
elementSelect |
|
3
|
|
|
Simple component to display the element selection list. |
|
4
|
|
|
|
|
5
|
|
|
@namespace Components |
|
6
|
|
|
*/ |
|
7
|
|
|
'use strict'; |
|
8
|
|
|
|
|
9
|
|
|
angular.module('game').component('elementSelect', { |
|
10
|
|
|
templateUrl: 'views/element-select.html', |
|
11
|
|
|
controller: 'ct_element_select', |
|
12
|
|
|
controllerAs: 'ct', |
|
13
|
|
|
bindings: { |
|
14
|
|
|
index: '<' |
|
15
|
|
|
} |
|
16
|
|
|
}); |
|
17
|
|
|
|
|
18
|
|
|
angular.module('game').controller('ct_element_select', ['state', 'visibility', 'data', |
|
19
|
|
|
function (state, visibility, data) { |
|
20
|
|
|
let ct = this; |
|
21
|
|
|
ct.state = state; |
|
22
|
|
|
ct.data = data; |
|
23
|
|
|
|
|
24
|
|
|
ct.selectElement = function(element, index, player) { |
|
25
|
|
|
let slot = {}; |
|
26
|
|
|
for(let key in data.element_slot){ |
|
27
|
|
|
slot[key] = angular.copy(data.element_slot[key]); |
|
28
|
|
|
} |
|
29
|
|
|
let first = Object.keys(data.generators)[0]; |
|
30
|
|
|
slot.generators[first] = 1; |
|
31
|
|
|
slot.element = element; |
|
32
|
|
|
player.element_slots[index] = slot; |
|
33
|
|
|
|
|
34
|
|
|
let cachedReactions = state.reactionsCache[slot.element]; |
|
35
|
|
|
if(cachedReactions){ |
|
36
|
|
|
slot.reactions = cachedReactions; |
|
37
|
|
|
} |
|
38
|
|
|
let cachedRedoxes = state.redoxesCache[slot.element]; |
|
39
|
|
|
if(cachedRedoxes){ |
|
40
|
|
|
slot.redoxes = cachedRedoxes; |
|
41
|
|
|
} |
|
42
|
|
|
}; |
|
43
|
|
|
|
|
44
|
|
|
ct.isElementSelected = function(name, player) { |
|
45
|
|
|
for(let slot of player.element_slots){ |
|
46
|
|
|
if(slot && slot.element === name){ |
|
47
|
|
|
return true; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
return false; |
|
51
|
|
|
}; |
|
52
|
|
|
|
|
53
|
|
|
ct.visibleElements = function(player) { |
|
54
|
|
|
return visibility.visible(data.elements, isElementVisible, null, null, player); |
|
55
|
|
|
}; |
|
56
|
|
|
|
|
57
|
|
|
function isElementVisible(element, _, player) { |
|
58
|
|
|
return player.elements[element]; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
]); |
|
62
|
|
|
|