From 1a0f05511b5a326333b55693029a47e1251bb20b Mon Sep 17 00:00:00 2001 From: Cmdr McDonald Date: Mon, 31 Oct 2016 21:08:15 +0000 Subject: [PATCH] Various bug fixes --- src/app/components/HardpointSlot.jsx | 2 +- src/app/components/InternalSlot.jsx | 3 ++- src/app/components/ModificationsMenu.jsx | 10 ++++++--- src/app/components/ShipSummaryTable.jsx | 21 +++++++++--------- src/app/components/Slot.jsx | 5 ++++- src/app/components/StandardSlot.jsx | 27 +++++++++++++++--------- src/app/i18n/Language.jsx | 1 + src/app/shipyard/Calculations.js | 4 ++-- src/app/shipyard/ModuleUtils.js | 2 +- src/app/shipyard/Ship.js | 1 - src/app/utils/SlotFunctions.js | 4 ++-- 11 files changed, 47 insertions(+), 33 deletions(-) diff --git a/src/app/components/HardpointSlot.jsx b/src/app/components/HardpointSlot.jsx index 18f35d36..e2589d5d 100644 --- a/src/app/components/HardpointSlot.jsx +++ b/src/app/components/HardpointSlot.jsx @@ -53,7 +53,7 @@ export default class HardpointSlot extends Slot { {m.type && m.type == 'KT' ? : ''} {m.type && m.type == 'E' ? : ''} {classRating} {translate(m.name || m.grp)} -
{m.getMass()}{u.T}
+
{formats.round1(m.getMass())}{u.T}
{ m.getDps() ?
{translate('DPS')}: {formats.round1(m.getDps())} { m.getClip() ? ({formats.round1((m.getClip() * m.getDps() / m.getRoF()) / ((m.getClip() / m.getRoF()) + m.getReload())) }) : null }
: null } diff --git a/src/app/components/InternalSlot.jsx b/src/app/components/InternalSlot.jsx index 19b5b0c2..a5467b01 100644 --- a/src/app/components/InternalSlot.jsx +++ b/src/app/components/InternalSlot.jsx @@ -27,7 +27,7 @@ export default class InternalSlot extends Slot { return
{classRating} {translate(m.name || m.grp)}
-
{m.getMass() || m.cargo || m.fuel || 0}{u.T}
+
{formats.round1(m.getMass()) || m.cargo || m.fuel || 0}{u.T}
{ m.getOptMass() ?
{translate('optimal mass')}: {m.getOptMass()}{u.T}
: null } @@ -48,6 +48,7 @@ export default class InternalSlot extends Slot { { m.armouradd ?
+{m.armouradd} {translate('armour')}
: null } { m.passengers ?
{translate('passengers')}: {m.passengers}
: null } { m && validMods.length > 0 ?
: null } +
; } else { diff --git a/src/app/components/ModificationsMenu.jsx b/src/app/components/ModificationsMenu.jsx index 9be631ac..a70de410 100644 --- a/src/app/components/ModificationsMenu.jsx +++ b/src/app/components/ModificationsMenu.jsx @@ -50,7 +50,6 @@ export default class ModificationsMenu extends TranslatedComponent {
); } - // return { list, values }; } @@ -64,6 +63,12 @@ export default class ModificationsMenu extends TranslatedComponent { this.setState(this._initState(nextProps, nextContext)); } + /** + * Get the locally stored value of the modifier + * @param {string} name the name of the value to obtain + * @param {Number} defaultValue the value to use if none is held locally + * @return {Number} the value + */ _getValue(name, defaultValue) { let values = this.state ? this.state.values : null; return values ? values[name] : defaultValue; @@ -75,7 +80,6 @@ export default class ModificationsMenu extends TranslatedComponent { * @param {Number} value The value to set, in the range [0,1] */ _updateValue(name, value) { - let values = this.state.values; values[name] = value; @@ -87,7 +91,7 @@ export default class ModificationsMenu extends TranslatedComponent { ship.setModification(m, name, scaledValue); } this.props.onChange(); - this.setState({values}); + this.setState({ values }); } /** diff --git a/src/app/components/ShipSummaryTable.jsx b/src/app/components/ShipSummaryTable.jsx index 84aee6b8..1b01c28c 100644 --- a/src/app/components/ShipSummaryTable.jsx +++ b/src/app/components/ShipSummaryTable.jsx @@ -23,8 +23,7 @@ export default class ShipSummaryTable extends TranslatedComponent { let translate = language.translate; let u = language.units; let formats = language.formats; - let round = formats.round; - let { time, int } = formats; + let { time, int, round, f1, f2 } = formats; let armourDetails = null; let sgClassNames = cn({ warning: ship.sgSlot && !ship.shieldStrength, muted: !ship.sgSlot }); let sgRecover = '-'; @@ -84,9 +83,9 @@ export default class ShipSummaryTable extends TranslatedComponent { {ship.agility}/10 { ship.canThrust() ? {int(ship.topSpeed)} {u['m/s']} : 0 } { ship.canBoost() ? {int(ship.topBoost)} {u['m/s']} : 0 } - {round(ship.totalDps)} - {round(ship.totalEps)} - {round(ship.totalHps)} + {f1(ship.totalDps)} + {f1(ship.totalEps)} + {f1(ship.totalHps)} {int(ship.armour)} {armourDetails} {int(ship.shieldStrength)} {u.MJ} { ship.shieldMultiplier > 1 && ship.shieldStrength > 0 ? ({formats.rPct(ship.shieldMultiplier)}) : null } {sgRecover} @@ -96,12 +95,12 @@ export default class ShipSummaryTable extends TranslatedComponent { {int(ship.ladenMass)} {u.T} {round(ship.cargoCapacity)} {u.T} {round(ship.fuelCapacity)} {u.T} - {round(ship.unladenRange)} {u.LY} - {round(ship.fullTankRange)} {u.LY} - {round(ship.ladenRange)} {u.LY} - {round(ship.maxJumpCount)} - {round(ship.unladenFastestRange)} {u.LY} - {round(ship.ladenFastestRange)} {u.LY} + {f2(ship.unladenRange)} {u.LY} + {f2(ship.fullTankRange)} {u.LY} + {f2(ship.ladenRange)} {u.LY} + {int(ship.maxJumpCount)} + {f2(ship.unladenFastestRange)} {u.LY} + {f2(ship.ladenFastestRange)} {u.LY} {ship.masslock} diff --git a/src/app/components/Slot.jsx b/src/app/components/Slot.jsx index 7df6808a..f15bfaf4 100644 --- a/src/app/components/Slot.jsx +++ b/src/app/components/Slot.jsx @@ -130,7 +130,10 @@ export default class Slot extends TranslatedComponent { ); } - _toggleModifications(event) { + /** + * Toggle the modifications flag when selecting the modifications icon + */ + _toggleModifications() { this._modificationsSelected = !this._modificationsSelected; } } diff --git a/src/app/components/StandardSlot.jsx b/src/app/components/StandardSlot.jsx index 83492b90..98771aca 100644 --- a/src/app/components/StandardSlot.jsx +++ b/src/app/components/StandardSlot.jsx @@ -25,6 +25,10 @@ export default class StandardSlot extends TranslatedComponent { warning: React.PropTypes.func, }; + /** + * Construct the slot + * @param {object} props Object properties + */ constructor(props) { super(props); this._modificationsSelected = false; @@ -75,20 +79,20 @@ export default class StandardSlot extends TranslatedComponent {
{slot.maxClass}
{classRating} {translate(m.grp == 'bh' ? m.grp : m.name || m.grp)}
-
{formats.round(m.getMass()) || m.fuel || 0}{units.T}
+
{formats.round1(m.getMass()) || m.fuel || 0}{units.T}
{ m.grp == 'bh' && m.name ?
{translate(m.name)}
: null } - { m.getOptimalMass() ?
{translate('optimal mass')}: {formats.round(m.getOptimalMass())}{units.T}
: null } - { m.getMaxMass() ?
{translate('max mass')}: {formats.round(m.getMaxMass())}{units.T}
: null } - { m.getRange() ?
{translate('range')}: {formats.round(m.getRange())}{units.km}
: null } + { m.getOptimalMass() ?
{translate('optimal mass')}: {formats.int(m.getOptimalMass())}{units.T}
: null } + { m.getMaxMass() ?
{translate('max mass')}: {formats.int(m.getMaxMass())}{units.T}
: null } + { m.getRange() ?
{translate('range')}: {formats.f2(m.getRange())}{units.km}
: null } { m.time ?
{translate('time')}: {formats.time(m.time)}
: null } - { m.getThermalEfficiency() ?
{translate('efficiency')}: {formats.round(m.getThermalEfficiency())}
: null } - { m.getPowerGeneration() > 0 ?
{translate('pGen')}: {formats.round(m.getPowerGeneration())}{units.MW}
: null } - { m.getMaxFuelPerJump() ?
{translate('max')} {translate('fuel')}: {formats.round(m.getMaxFuelPerJump())}{units.T}
: null } - { m.getWeaponsCapacity() ?
{translate('WEP')}: {formats.round(m.getWeaponsCapacity())}{units.MJ} / {formats.round(m.getWeaponsRechargeRate())}{units.MW}
: null } - { m.getSystemsCapacity() ?
{translate('SYS')}: {formats.round(m.getSystemsCapacity())}{units.MJ} / {formats.round(m.getSystemsRechargeRate())}{units.MW}
: null } - { m.getEnginesCapacity() ?
{translate('ENG')}: {formats.round(m.getEnginesCapacity())}{units.MJ} / {formats.round(m.getEnginesRechargeRate())}{units.MW}
: null } + { m.getThermalEfficiency() ?
{translate('efficiency')}: {formats.f1(m.getThermalEfficiency())}
: null } + { m.getPowerGeneration() > 0 ?
{translate('pGen')}: {formats.f1(m.getPowerGeneration())}{units.MW}
: null } + { m.getMaxFuelPerJump() ?
{translate('max')} {translate('fuel')}: {formats.f1(m.getMaxFuelPerJump())}{units.T}
: null } + { m.getWeaponsCapacity() ?
{translate('WEP')}: {formats.f1(m.getWeaponsCapacity())}{units.MJ} / {formats.f1(m.getWeaponsRechargeRate())}{units.MW}
: null } + { m.getSystemsCapacity() ?
{translate('SYS')}: {formats.f1(m.getSystemsCapacity())}{units.MJ} / {formats.f1(m.getSystemsRechargeRate())}{units.MW}
: null } + { m.getEnginesCapacity() ?
{translate('ENG')}: {formats.f1(m.getEnginesCapacity())}{units.MJ} / {formats.f1(m.getEnginesRechargeRate())}{units.MW}
: null } { validMods.length > 0 ?
: null }
@@ -99,6 +103,9 @@ export default class StandardSlot extends TranslatedComponent { ); } + /** + * Toggle the modifications flag when selecting the modifications icon + */ _toggleModifications() { this._modificationsSelected = !this._modificationsSelected; } diff --git a/src/app/i18n/Language.jsx b/src/app/i18n/Language.jsx index 6d4d21a8..fb4ea958 100644 --- a/src/app/i18n/Language.jsx +++ b/src/app/i18n/Language.jsx @@ -46,6 +46,7 @@ export function getLanguage(langCode) { s2: d3Locale.numberFormat('.2s'), // SI Format to 2 decimal places (.e.g 1.1k) pct: d3Locale.numberFormat('.2%'), // % to 2 decimal places (.e.g 5.40%) pct1: d3Locale.numberFormat('.1%'), // % to 1 decimal places (.e.g 5.4%) + r1: d3Locale.numberFormat('.1r'), // Rounded to 1 significant number (.e.g 512 => 500, 4.122 => 4) r2: d3Locale.numberFormat('.2r'), // Rounded to 2 significant numbers (.e.g 512 => 510, 4.122 => 4.1) rPct: d3.format('%'), // % to 0 decimal places (.e.g 5%) round1: (d) => gen(d3.round(d, 1)), // Rounded to 0-1 decimal places (.e.g 5.1, 4) diff --git a/src/app/shipyard/Calculations.js b/src/app/shipyard/Calculations.js index 21d818d6..96c7b0fe 100644 --- a/src/app/shipyard/Calculations.js +++ b/src/app/shipyard/Calculations.js @@ -57,7 +57,7 @@ export function shieldStrength(mass, baseShield, sg, multiplier) { let maxMul = sg instanceof Module ? sg.getMaxMul() : sg.maxmul; let xnorm = Math.min(1, (maxMass - mass) / (maxMass - minMass)); - let exponent = Math.log((optMul - minMul) / (maxMul - minMul)) / Math.log(Math.min(1, (maxMass - optMass) / (maxMass - minMass))) + let exponent = Math.log((optMul - minMul) / (maxMul - minMul)) / Math.log(Math.min(1, (maxMass - optMass) / (maxMass - minMass))); let ynorm = Math.pow(xnorm, exponent); let mul = minMul + ynorm * (maxMul - minMul); @@ -84,7 +84,7 @@ export function speed(mass, baseSpeed, baseBoost, thrusters, pipSpeed) { let maxMul = thrusters instanceof Module ? thrusters.getMaxMul() : thrusters.maxmul; let xnorm = Math.min(1, (maxMass - mass) / (maxMass - minMass)); - let exponent = Math.log((optMul - minMul) / (maxMul - minMul)) / Math.log(Math.min(1, (maxMass - optMass) / (maxMass - minMass))) + let exponent = Math.log((optMul - minMul) / (maxMul - minMul)) / Math.log(Math.min(1, (maxMass - optMass) / (maxMass - minMass))); let ynorm = Math.pow(xnorm, exponent); let mul = minMul + ynorm * (maxMul - minMul); let speed = baseSpeed * mul; diff --git a/src/app/shipyard/ModuleUtils.js b/src/app/shipyard/ModuleUtils.js index d2066c61..dc0b95e6 100755 --- a/src/app/shipyard/ModuleUtils.js +++ b/src/app/shipyard/ModuleUtils.js @@ -98,7 +98,7 @@ export function internal(id) { let group = Modules.internal[n]; for (let i = 0; i < group.length; i++) { if (group[i].id == id) { - return group[i]; + return new Module({ template: group[i] }); } } } diff --git a/src/app/shipyard/Ship.js b/src/app/shipyard/Ship.js index 6d1720dd..9367f689 100755 --- a/src/app/shipyard/Ship.js +++ b/src/app/shipyard/Ship.js @@ -495,7 +495,6 @@ export default class Ship { bands[this.cargoHatch.priority].retracted += this.cargoHatch.m.getPowerUsage(); } - for (i = 0; i < cl; i++) { standard[i].cat = 0; standard[i].enabled = enabled ? enabled[i + 1] * 1 : true; diff --git a/src/app/utils/SlotFunctions.js b/src/app/utils/SlotFunctions.js index 6309f04e..647d8ef7 100644 --- a/src/app/utils/SlotFunctions.js +++ b/src/app/utils/SlotFunctions.js @@ -252,7 +252,7 @@ export function diffDetails(language, m, mm) { } } else { // Old module must be a shield booster - newShield = this.calcShieldStrengthWith(null, -mm.getShieldMul()); + newShield = this.calcShieldStrengthWith(null, -mm.getShieldMul()); } let sgDiffClass = Math.round((newShield - shield) * 100) / 100 == 0 ? 'muted' : (newShield > shield ? 'secondary' : 'warning'); @@ -283,7 +283,7 @@ export function diffDetails(language, m, mm) { let massDiff = mMass - mmMass; let mCap = m.fuel || m.cargo || 0; - let mmCap = mm? mm.fuel || mm.cargo || 0 : 0; + let mmCap = mm ? mm.fuel || mm.cargo || 0 : 0; let capDiff = mCap - mmCap; if (m.grp == 'fsd' || massDiff || capDiff) { let fsd = m.grp == 'fsd' ? m : null;