| Conditions | 1 |
| Paths | 2 |
| Total Lines | 66 |
| Lines | 0 |
| Ratio | 0 % |
| 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 | 'use strict'; |
||
| 9 | function supernova(state, format, visibility, upgrade, 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.exoticProduction = function() { |
||
| 18 | let production = {}; |
||
| 19 | let exotic = data.elements[state.currentElement].exotic; |
||
| 20 | production[exotic] = 0; |
||
| 21 | for (let resource of data.elements[state.currentElement].includes) { |
||
| 22 | if (!state.player.resources[resource].unlocked) { |
||
| 23 | continue; |
||
| 24 | } |
||
| 25 | if (data.resources[resource].type.indexOf('molecule') !== -1) { |
||
| 26 | let multiplier = 0; |
||
| 27 | for (let key in data.resources[resource].elements) { |
||
| 28 | let number = data.resources[resource].elements[key]; |
||
| 29 | multiplier += number; |
||
| 30 | } |
||
| 31 | for (let element in data.resources[resource].elements) { |
||
| 32 | let newExotic = data.elements[element].exotic; |
||
| 33 | production[newExotic] = production[newExotic] || 0; |
||
| 34 | production[newExotic] += Math.floor(Math.max(0, Math.log(state.player.resources[resource].number))) * multiplier; |
||
| 35 | } |
||
| 36 | }else{ |
||
| 37 | production[exotic] += Math.floor(Math.max(0, Math.log(state.player.resources[resource].number))); |
||
| 38 | } |
||
| 39 | } |
||
| 40 | for (let key in production) { |
||
| 41 | // we adjust the production to start at 1e6 resources |
||
| 42 | if (production[key] >= 13) { |
||
| 43 | production[key] -= 13; |
||
| 44 | } else { |
||
| 45 | production[key] = 0; |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | return production; |
||
| 50 | }; |
||
| 51 | |||
| 52 | ct.exoticPrestige = function() { |
||
| 53 | let resources = state.player.resources; |
||
| 54 | let production = ct.exoticProduction(); |
||
| 55 | |||
| 56 | for (let key in production) { |
||
| 57 | resources[key].number += production[key]; |
||
| 58 | resources[key].unlocked = true; |
||
| 59 | } |
||
| 60 | |||
| 61 | upgrade.resetElement(state.player, state.currentElement); |
||
| 62 | }; |
||
| 63 | |||
| 64 | ct.buyExoticUpgrade = function(name, element) { |
||
| 65 | let upgrades = state.player.elements[element].exotic_upgrades; |
||
| 66 | let price = data.exotic_upgrades[name].price; |
||
| 67 | let currency = data.elements[element].exotic; |
||
| 68 | upgrade.buyUpgrade(state.player, |
||
| 69 | upgrades, |
||
| 70 | name, |
||
| 71 | price, |
||
| 72 | currency); |
||
| 73 | }; |
||
| 74 | } |
||
| 75 |