Total Complexity | 14 |
Complexity/F | 3.5 |
Lines of Code | 47 |
Function Count | 4 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | /** |
||
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 |