src/scripts/services/visibility.js   A
last analyzed

Complexity

Total Complexity 14
Complexity/F 3.5

Size

Lines of Code 47
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
wmc 14
nc 6
mnd 3
bc 13
fnc 4
dl 0
loc 47
rs 10
bpm 3.25
cpm 3.5
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B angular.service(ꞌvisibilityꞌ) 0 41 1
1
/**
2
 visibility
3
 Service that holds all functions that determine which elements are visible.
4
5
 @namespace Services
6
 */
7
'use strict';
8
9
angular
10
  .module('game')
11
  .service('visibility', [
12
    function() {
13
      this.visible = function(items, func, currentElement, sortFunc, player) {
14
        let visibles = [];
15
        for (let i in items) {
16
          // if it is an array, we need to extract the item from the index
17
          let item = Array.isArray(items) ? items[i] : i;
18
          if (func(item, currentElement, player)) {
19
            visibles.push(item);
20
          }
21
        }
22
        if(sortFunc){
23
          visibles.sort(sortFunc);
24
        }
25
        return visibles;
26
      };
27
28
      this.isUpgradeVisible = function(name, slot, upgrade, player) {
29
        if (upgrade.tiers) {
30
          for (let tier of upgrade.tiers) {
31
            if (slot.generators[tier] === 0) {
32
              return false;
33
            }
34
          }
35
        }
36
        return meetDependencies(slot.upgrades, upgrade.deps) &&
37
          meetDependencies(player.exotic_upgrades[slot.element], upgrade.exotic_deps) &&
38
          meetDependencies(player.dark_upgrades, upgrade.dark_deps);
39
      };
40
41
      function meetDependencies(upgrades, dependencies) {
42
        if(!dependencies){
43
          return true;
44
        }
45
        for (let dep of dependencies) {
46
          if (!upgrades[dep]) {
47
            return false;
48
          }
49
        }
50
        return true;
51
      }
52
    }
53
  ]);
54