Total Complexity | 7 |
Complexity/F | 1.75 |
Lines of Code | 41 |
Function Count | 4 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | /** |
||
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 |