Total Complexity | 11 |
Complexity/F | 2.2 |
Lines of Code | 54 |
Function Count | 5 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | /** |
||
7 | 'use strict'; |
||
8 | |||
9 | angular.module('game').component('elementSelect', { |
||
10 | templateUrl: 'views/element-select.html', |
||
11 | controller: ['state', 'visibility', 'data', elementSelect |
||
12 | ], |
||
13 | controllerAs: 'ct', |
||
14 | bindings: { |
||
15 | index: '<' |
||
16 | } |
||
17 | }); |
||
18 | |||
19 | function elementSelect (state, visibility, data) { |
||
20 | let ct = this; |
||
21 | ct.state = state; |
||
22 | ct.data = data; |
||
23 | |||
24 | ct.selectElement = function(element, index) { |
||
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 | state.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() { |
||
54 | return visibility.visible(data.elements, isElementVisible); |
||
55 | }; |
||
56 | |||
57 | function isElementVisible(element) { |
||
58 | return state.player.elements[element]; |
||
59 | } |
||
60 | } |
||
61 |