Completed
Push — master ( 98e91a...5e1a95 )
by Andres
41s
created

reaction-table.js ➔ ... ➔ ct.visibleSyntheses   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
dl 0
loc 3
rs 10
nop 1
1
/**
2
 reactionTable
3
 Component for the table of reactions in the Reactor tab.
4
5
 @namespace Components
6
 */
7
'use strict';
8
9
angular.module('game').component('reactionTable', {
10
  templateUrl: 'views/reactionTable.html',
11
  controller: ['util', 'format', 'visibility', 'data', 'state', reactionTable],
12
  controllerAs: 'ct',
13
  bindings: {
14
    reactor: '<',
15
    element: '<',
16
    title: '<'
17
  }
18
});
19
20
function reactionTable(util, format, visibility, data, state) {
21
  let ct = this;
22
  ct.util = util;
23
  ct.format = format;
24
  ct.data = data;
25
  ct.state = state;
26
27
  ct.visibleSyntheses = function(currentElement) {
28
    return visibility.visible(data.reactions, isSynthesisVisible, currentElement);
29
  };
30
31
  function isSynthesisVisible(key, currentElement) {
32
    let entry = data.reactions[key];
33
    for (let reactant in entry.reactant) {
34
      if (!state.player.resources[reactant].unlocked) {
35
        return false;
36
      }
37
    }
38
39
    // for misc reactions
40
    if(entry.elements.length === 0 &&
41
       currentElement === ''){
42
         return true;
43
    }
44
45
    for (let element in entry.elements) {
46
      if (currentElement === entry.elements[element]) {
47
        return true;
48
      }
49
    }
50
51
    return false;
52
  }
53
}
54