| Conditions | 1 |
| Paths | 1 |
| Total Lines | 78 |
| Lines | 78 |
| Ratio | 100 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | View Code Duplication | 'use strict'; |
|
| 9 | function _void(state, format, visibility, data, util) { |
||
| 10 | let ct = this; |
||
| 11 | ct.state = state; |
||
| 12 | ct.visibility = visibility; |
||
| 13 | ct.data = data; |
||
| 14 | ct.util = util; |
||
| 15 | ct.format = format; |
||
| 16 | |||
| 17 | ct.darkProduction = function() { |
||
| 18 | let production = 0; |
||
| 19 | for (let element in data.elements) { |
||
| 20 | let exotic = data.elements[element].exotic; |
||
| 21 | if (!state.player.resources[exotic].unlocked) { |
||
| 22 | continue; |
||
| 23 | } |
||
| 24 | production += Math.floor(Math.max(0, Math.log(state.player.resources[exotic].number))); |
||
| 25 | } |
||
| 26 | |||
| 27 | return production; |
||
| 28 | }; |
||
| 29 | |||
| 30 | ct.darkPrestige = function() { |
||
| 31 | let resources = state.player.resources; |
||
| 32 | let production = ct.darkProduction(); |
||
| 33 | |||
| 34 | resources.dark_matter.number += production; |
||
| 35 | resources.dark_matter.unlocked = true; |
||
| 36 | |||
| 37 | for(let key in data.elements){ |
||
| 38 | let element = data.elements[key]; |
||
| 39 | if (!state.player.resources[element.exotic].unlocked) { |
||
| 40 | continue; |
||
| 41 | } |
||
| 42 | state.player.resources[element.exotic].number = 0; |
||
| 43 | |||
| 44 | for (let resource of element.includes) { |
||
| 45 | resources[resource].number = 0; |
||
| 46 | } |
||
| 47 | |||
| 48 | let upgrades = state.player.elements[key].upgrades; |
||
| 49 | for (let upgrade in upgrades) { |
||
| 50 | upgrades[upgrade] = false; |
||
| 51 | } |
||
| 52 | |||
| 53 | let exoticUpgrades = state.player.elements[key].exotic_upgrades; |
||
| 54 | for (let upgrade in exoticUpgrades) { |
||
| 55 | exoticUpgrades[upgrade] = false; |
||
| 56 | } |
||
| 57 | |||
| 58 | let generators = state.player.elements[key].generators; |
||
| 59 | for (let generator in generators) { |
||
| 60 | generators[generator] = 0; |
||
| 61 | } |
||
| 62 | |||
| 63 | let syntheses = element.syntheses; |
||
| 64 | for (let synthesis of syntheses) { |
||
| 65 | state.player.syntheses[synthesis].active = 0; |
||
| 66 | } |
||
| 67 | delete generators['0']; |
||
| 68 | let first = Object.keys(generators)[0]; |
||
| 69 | |||
| 70 | state.player.elements[key].generators[first] = 1; |
||
| 71 | } |
||
| 72 | }; |
||
| 73 | |||
| 74 | ct.buyDarkUpgrade = function(name) { |
||
| 75 | if (state.player.dark_upgrades[name]) { |
||
| 76 | return; |
||
| 77 | } |
||
| 78 | let price = data.dark_upgrades[name].price; |
||
| 79 | let currency = 'dark_matter'; |
||
| 80 | |||
| 81 | if (state.player.resources[currency].number >= price) { |
||
| 82 | state.player.resources[currency].number -= price; |
||
| 83 | state.player.dark_upgrades[name] = true; |
||
| 84 | } |
||
| 85 | }; |
||
| 86 | } |
||
| 87 |