Completed
Push — master ( f5e321...3d05ad )
by Andres
31s
created

src/scripts/component/fusion-select.js   A

Complexity

Total Complexity 7
Complexity/F 1.75

Size

Lines of Code 41
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 7
c 1
b 0
f 0
nc 2
mnd 2
bc 6
fnc 4
dl 0
loc 41
rs 10
bpm 1.5
cpm 1.75
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B angular.controller(ꞌct_fusion_selectꞌ) 0 27 1
1
/**
2
 fusion
3
 Component that handles the fusion of isotopes to create new ones.
4
5
 @namespace Components
6
 */
7
'use strict';
8
9
angular.module('game').component('fusionSelect', {
10
  templateUrl: 'views/fusion-select.html',
11
  controller:  'ct_fusion_select',
12
  controllerAs: 'ct',
13
  bindings: {
14
    source: '@',
15
    getCapacity: '&'
16
  }
17
});
18
19
angular.module('game').controller('ct_fusion_select', ['state', 'data',
20
  function (state, data) {
21
    let ct = this;
22
    ct.state = state;
23
    ct.data = data;
24
25
    ct.availableIsotopes = function(player){
26
      let result = [];
27
      for(let resource in data.resources){
28
        if(data.resources[resource].type.indexOf('isotope') !== -1 &&
29
           player.resources[resource].unlocked){
30
             result.push(resource);
31
           }
32
      }
33
      return result;
34
    };
35
36
    ct.setPercentage = function(percentage, player) {
37
      state[ct.source].number = Math.floor(player.resources[state[ct.source].name].number*(percentage/100));
38
      ct.fixNumber(player);
39
    };
40
41
    ct.fixNumber = function(player) {
42
      let resourceNumber = player.resources[state[ct.source].name].number;
43
      let capacity = ct.getCapacity({resource: state[ct.source].name, player:player});
44
      state[ct.source].number = Math.max(0, Math.min(resourceNumber, state[ct.source].number, capacity));
45
    };
46
  }
47
]);
48