Move more values to functions over direct variable access

This commit is contained in:
Cmdr McDonald
2016-10-29 23:32:52 +01:00
parent 2b464f34e5
commit 0df051e40f
9 changed files with 289 additions and 102 deletions

View File

@@ -27,42 +27,50 @@ export default class Module {
}
/**
* Get a value for a given modification ID
* @param {Number} modId The ID of the modification
* @return {Number} The value of the modification, as a decimal value from -1 to 1
* Get a value for a given modification
* @param {Number} name The name of the modification
* @return {Number} The value of the modification, as a decimal value from -1 to 1
*/
getModValue(modId) {
return this.mods ? this.mods[modId] / 10000 : null;
getModValue(name) {
return this.mods ? this.mods[name] / 10000 : null;
}
/**
* Set a value for a given modification ID
* @param {Number} modId The ID of the modification
* @param {Number} value The value of the modification, as a decimal value from -1 to 1
* @param {Number} name The name of the modification
* @param {Number} value The value of the modification, as a decimal value from -1 to 1
*/
setModValue(modId, value) {
setModValue(name, value) {
if (value == null || value == 0) {
delete this.mods[modId];
delete this.mods[name];
} else {
// Store value with 2dp
this.mods[modId] = Math.round(value * 10000);
this.mods[name] = Math.round(value * 10000);
}
}
/**
* Helper to obtain a modified value using standard multipliers
* @param {String} name the name of the modifier to obtain
* @return {Number} the mass of this module
*/
_getModifiedValue(name) {
let result = 0;
if (this[name]) {
result = this[name];
if (result) {
let mult = this.getModValue(name);
if (mult) { result = result * (1 + mult); }
}
}
return result;
}
/**
* Get the power generation of this module, taking in to account modifications
* @return {Number} the power generation of this module
*/
getPowerGeneration() {
let result = 0;
if (this.pGen) {
result = this.pGen;
if (result) {
let mult = this.getModValue(1);
if (mult) { result = result * (1 + mult); }
}
}
return result;
return this._getModifiedValue('pGen');
}
/**
@@ -70,15 +78,7 @@ export default class Module {
* @return {Number} the power usage of this module
*/
getPowerUsage() {
let result = 0;
if (this.power) {
result = this.power;
if (result) {
let mult = this.getModValue(2);
if (mult) { result = result * (1 + mult); }
}
}
return result;
return this._getModifiedValue('power');
}
/**
@@ -86,15 +86,7 @@ export default class Module {
* @return {Number} the integrity of this module
*/
getIntegrity() {
let result = 0;
if (this.health) {
result = this.health;
if (result) {
let mult = this.getModValue(3);
if (mult) { result = result * (1 + mult); }
}
}
return result;
return this._getModifiedValue('integrity');
}
/**
@@ -102,14 +94,206 @@ export default class Module {
* @return {Number} the mass of this module
*/
getMass() {
let result = 0;
if (this.mass) {
result = this.mass;
if (result) {
let mult = this.getModValue(4);
if (mult) { result = result * (1 + mult); }
}
}
return result;
return this._getModifiedValue('mass');
}
/**
* Get the thermal efficiency of this module, taking in to account modifications
* @return {Number} the thermal efficiency of this module
*/
getThermalEfficiency() {
return this._getModifiedValue('eff');
}
/**
* Get the maximum mass of this module, taking in to account modifications
* @return {Number} the maximum mass of this module
*/
getMaxMass() {
return this._getModifiedValue('maxmass');
}
/**
* Get the optimal mass of this module, taking in to account modifications
* @return {Number} the optimal mass of this module
*/
getOptimalMass() {
return this._getModifiedValue('optmass');
}
/**
* Get the optimal multiplier of this module, taking in to account modifications
* @return {Number} the optimal multiplier of this module
*/
getOptimalMultiplier() {
return this._getModifiedValue('optmult');
}
/**
* Get the damage per second for this module, taking in to account modifications
* @return {Number} the damage per second of this module
*/
getDamagePerSecond() {
return this._getModifiedValue('dps');
}
/**
* Get the energy per second for this module, taking in to account modifications
* @return {Number} the energy per second of this module
*/
getEnergyPerSecond() {
return this._getModifiedValue('eps');
}
/**
* Get the heat per second for this module, taking in to account modifications
* @return {Number} the heat per second of this module
*/
getHeatPerSecond() {
return this._getModifiedValue('hps');
}
/**
* Get the maximum fuel per jump for this module, taking in to account modifications
* @return {Number} the maximum fuel per jump of this module
*/
getMaxFuelPerJump() {
return this._getModifiedValue('maxfuel');
}
/**
* Get the systems capacity for this module, taking in to account modifications
* @return {Number} the systems capacity of this module
*/
getSystemsCapacity() {
return this._getModifiedValue('syscap');
}
/**
* Get the engines capacity for this module, taking in to account modifications
* @return {Number} the engines capacity of this module
*/
getEnginesCapacity() {
return this._getModifiedValue('engcap');
}
/**
* Get the weapons capacity for this module, taking in to account modifications
* @return {Number} the weapons capacity of this module
*/
getWeaponsCapacity() {
return this._getModifiedValue('wepcap');
}
/**
* Get the systems recharge rate for this module, taking in to account modifications
* @return {Number} the systems recharge rate of this module
*/
getSystemsRechargeRate() {
return this._getModifiedValue('sysrate');
}
/**
* Get the engines recharge rate for this module, taking in to account modifications
* @return {Number} the engines recharge rate of this module
*/
getEnginesRechargeRate() {
return this._getModifiedValue('engrate');
}
/**
* Get the weapons recharge rate for this module, taking in to account modifications
* @return {Number} the weapons recharge rate of this module
*/
getWeaponsRechargeRate() {
return this._getModifiedValue('weprate');
}
/**
* Get the kinetic resistance for this module, taking in to account modifications
* @return {Number} the kinetic resistance of this module
*/
getKineticResistance() {
return this._getModifiedValue('kinres');
}
/**
* Get the thermal resistance for this module, taking in to account modifications
* @return {Number} the thermal resistance of this module
*/
getThermalResistance() {
return this._getModifiedValue('thermres');
}
/**
* Get the explosive resistance for this module, taking in to account modifications
* @return {Number} the explosive resistance of this module
*/
getExplosiveResistance() {
return this._getModifiedValue('explres');
}
/**
* Get the regeneration rate for this module, taking in to account modifications
* @return {Number} the regeneration rate of this module
*/
getRegenerationRate() {
return this._getModifiedValue('regen');
}
/**
* Get the broken regeneration rate for this module, taking in to account modifications
* @return {Number} the broken regeneration rate of this module
*/
getBrokenRegenerationRate() {
return this._getModifiedValue('brokenregen');
}
/**
* Get the range rate for this module, taking in to account modifications
* @return {Number} the range rate of this module
*/
getRange() {
return this._getModifiedValue('range');
}
/**
* Get the capture arc for this module, taking in to account modifications
* @return {Number} the capture arc of this module
*/
getCaptureArc() {
return this._getModifiedValue('arc');
}
/**
* Get the armour for this module, taking in to account modifications
* @return {Number} the armour of this module
*/
getArmour() {
return this._getModifiedValue('armour');
}
/**
* Get the delay for this module, taking in to account modifications
* @return {Number} the delay of this module
*/
getDelay() {
return this._getModifiedValue('delay');
}
/**
* Get the duration for this module, taking in to account modifications
* @return {Number} the duration of this module
*/
getDuration() {
return this._getModifiedValue('duration');
}
/**
* Get the shield reinforcement for this module, taking in to account modifications
* @return {Number} the shield reinforcement of this module
*/
getShieldReinforcement() {
return this._getModifiedValue('shieldreinforcement');
}
}