From 46ed9003dd9c8bea62bbfbe29b4eefd44e9994de Mon Sep 17 00:00:00 2001 From: Cmdr McDonald Date: Wed, 14 Dec 2016 13:31:20 +0000 Subject: [PATCH] Tidy-ups --- src/app/components/InternalSlotSection.jsx | 2 +- src/app/shipyard/Ship.js | 27 ++++++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/app/components/InternalSlotSection.jsx b/src/app/components/InternalSlotSection.jsx index 8d1b11a0..af60b841 100644 --- a/src/app/components/InternalSlotSection.jsx +++ b/src/app/components/InternalSlotSection.jsx @@ -163,7 +163,7 @@ export default class InternalSlotSection extends SlotSection { let ship = this.props.ship; ship.internal.forEach((slot) => { if ((clobber || !slot.m) && (!slot.eligible || slot.eligible.hr)) { - ship.use(slot, ModuleUtils.findInternal('hr', Math.min(slot.maxClass, 5), 'D')); // Hull reinforcements top out at 5D + ship.use(slot, ModuleUtils.findInternal('hr', Math.min(slot.maxClass, 5), 'D')); // Hull reinforcements top out at 5D } }); this.props.onChange(); diff --git a/src/app/shipyard/Ship.js b/src/app/shipyard/Ship.js index a18079f6..0bbef3dd 100755 --- a/src/app/shipyard/Ship.js +++ b/src/app/shipyard/Ship.js @@ -644,18 +644,10 @@ export default class Ship { decodeToArray(code, internal, decodeToArray(code, hardpoints, decodeToArray(code, standard, 1))); -console.log('Priorities was ' + JSON.stringify(priorities)); -console.log('Enableds was ' + JSON.stringify(enabled)); -console.log('Modifications was ' + JSON.stringify(modifications)); -console.log('Blueprints was ' + JSON.stringify(blueprints)); if (version != 2) { // Alter as required due to changes in the (build) code from one version to the next this.upgradeInternals(this.id, internal, 1 + this.standard.length + this.hardpoints.length, priorities, enabled, modifications, blueprints, version); } -console.log('Priorities is ' + JSON.stringify(priorities)); -console.log('Enableds is ' + JSON.stringify(enabled)); -console.log('Modifications is ' + JSON.stringify(modifications)); -console.log('Blueprints is ' + JSON.stringify(blueprints)); return this.buildWith( { @@ -1472,11 +1464,11 @@ console.log('Blueprints is ' + JSON.stringify(blueprints)); if (modificationId === MODIFICATION_ID_BLUEPRINT) { if (modificationValue !== 0) { blueprint = Object.assign(blueprint, _.find(Modifications.blueprints, function(o) { return o.id === modificationValue; })); - } + } } else if (modificationId === MODIFICATION_ID_GRADE) { if (modificationValue !== 0) { blueprint.grade = modificationValue; - } + } } else if (modificationId === MODIFICATION_ID_SPECIAL) { blueprint.special = _.find(Modifications.specials, function(o) { return o.id === modificationValue; }); } else { @@ -1658,18 +1650,29 @@ console.log('Blueprints is ' + JSON.stringify(blueprints)); return this; } + /** + * Upgrade information about internals with version changes + * @param {int} shipId the ID of the ship + * @param {array} internals the internals from the ship code + * @param {int} offset the offset of the internals information in the priorities etc. arrays + * @param {array} priorities the existing priorities arrray + * @param {array} enableds the existing enableds arrray + * @param {array} modifications the existing modifications arrray + * @param {array} blueprints the existing blueprints arrray + * @param {int} version the version of the information + */ upgradeInternals(shipId, internals, offset, priorities, enableds, modifications, blueprints, version) { if (version == 1) { // Version 2 reflects the addition of military slots. this means that we need to juggle the internals and their // associated information around to make holes in the appropriate places - for (var slotId = 0; slotId < this.internal.length; slotId++) { + for (let slotId = 0; slotId < this.internal.length; slotId++) { if (this.internal[slotId].eligible && this.internal[slotId].eligible.mrp) { // Found an MRP - push all of the existing items down one to compensate for the fact that they didn't exist before now internals.push.apply(internals, [0].concat(internals.splice(slotId).slice(0, -1))); const offsetSlotId = offset + slotId; - // Same for priorities etc. + // Same for priorities etc. priorities.push.apply(priorities, [0].concat(priorities.splice(offsetSlotId))); enableds.push.apply(enableds, [1].concat(enableds.splice(offsetSlotId))); modifications.push.apply(modifications, [null].concat(modifications.splice(offsetSlotId).slice(0, -1)));