From e9c34c636a2f63e8ee1ad6c469b3cdbafad48413 Mon Sep 17 00:00:00 2001 From: felixlinker Date: Fri, 28 Sep 2018 22:35:07 +0100 Subject: [PATCH 1/9] Don't filter values but map falsy ones to zero --- src/app/shipyard/Ship.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/shipyard/Ship.js b/src/app/shipyard/Ship.js index 4e47f060..4c5313ff 100755 --- a/src/app/shipyard/Ship.js +++ b/src/app/shipyard/Ship.js @@ -1187,28 +1187,28 @@ export default class Ship { // handle unladen mass unladenMass += chain(slots) .map(slot => slot.m ? slot.m.get('mass') : null) - .filter() + .map(mass => mass || 0) .reduce((sum, mass) => sum + mass) .value(); // handle fuel capacity fuelCapacity += chain(slots) .map(slot => slot.m ? slot.m.get('fuel') : null) - .filter() + .map(fuel => fuel || 0) .reduce((sum, fuel) => sum + fuel) .value(); // handle cargo capacity cargoCapacity += chain(slots) .map(slot => slot.m ? slot.m.get('cargo') : null) - .filter() + .map(cargo => cargo || 0) .reduce((sum, cargo) => sum + cargo) .value(); // handle passenger capacity passengerCapacity += chain(slots) .map(slot => slot.m ? slot.m.get('passengers') : null) - .filter() + .map(passengers => passengers || 0) .reduce((sum, passengers) => sum + passengers) .value(); From 5d52809d0d46fc12459b1b2c1033ea6007b30110 Mon Sep 17 00:00:00 2001 From: felixlinker Date: Fri, 28 Sep 2018 23:28:46 +0100 Subject: [PATCH 2/9] Catch undefined values in ship build parsing --- src/app/pages/OutfittingPage.jsx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/app/pages/OutfittingPage.jsx b/src/app/pages/OutfittingPage.jsx index d292449b..b74e56d5 100644 --- a/src/app/pages/OutfittingPage.jsx +++ b/src/app/pages/OutfittingPage.jsx @@ -198,12 +198,12 @@ export default class OutfittingPage extends Page { if (parts.length >= 5) { // We have control information in the code const control = LZString.decompressFromBase64(Utils.fromUrlSafe(parts[4])).split('/'); - sys = parseFloat(control[0]); - eng = parseFloat(control[1]); - wep = parseFloat(control[2]); + sys = parseFloat(control[0]) || sys; + eng = parseFloat(control[1]) || eng; + wep = parseFloat(control[2]) || wep; boost = control[3] == 1 ? true : false; - fuel = parseFloat(control[4]); - cargo = parseInt(control[5]); + fuel = parseFloat(control[4]) || fuel; + cargo = parseInt(control[5]) || cargo; if (control[6]) { const shipId = control[6]; opponent = new Ship(shipId, Ships[shipId].properties, Ships[shipId].slots); @@ -217,9 +217,9 @@ export default class OutfittingPage extends Page { const opponentParts = opponentCode.split('.'); if (opponentParts.length >= 5) { const opponentControl = LZString.decompressFromBase64(Utils.fromUrlSafe(opponentParts[4])).split('/'); - opponentSys = parseFloat(opponentControl[0]); - opponentEng = parseFloat(opponentControl[1]); - opponentWep = parseFloat(opponentControl[2]); + opponentSys = parseFloat(opponentControl[0]) || opponentSys; + opponentEng = parseFloat(opponentControl[1]) || opponentEng; + opponentWep = parseFloat(opponentControl[2]) || opponentWep; } } } else { @@ -227,7 +227,7 @@ export default class OutfittingPage extends Page { opponent.buildWith(Ships[shipId].defaults); } } - engagementRange = parseInt(control[8]); + engagementRange = parseInt(control[8]) || engagementRange; // Multi-crew pips were introduced later on so assign default values // because those values might not be present. From c9866c146b813c3a80e150fef43128c30a2b1912 Mon Sep 17 00:00:00 2001 From: felixlinker Date: Sat, 29 Sep 2018 00:55:37 +0100 Subject: [PATCH 3/9] Stop dividing burst two times by 100 --- src/app/shipyard/Module.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/shipyard/Module.js b/src/app/shipyard/Module.js index 4a19311c..d2827778 100755 --- a/src/app/shipyard/Module.js +++ b/src/app/shipyard/Module.js @@ -270,7 +270,7 @@ export default class Module { } else { result = result * (1 + modValue); } - } else if (name === 'burst' || name === 'burstrof') { + } else if (name === 'burstrof') { // Burst and burst rate of fire are special, as it can not exist but // have a modification result = modValue / 100; From d195b568b0895d324e142b73bef0cc16a6e08820 Mon Sep 17 00:00:00 2001 From: felixlinker Date: Sat, 29 Sep 2018 01:03:00 +0100 Subject: [PATCH 4/9] eslint indentation fixes --- src/app/shipyard/Module.js | 68 +++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/app/shipyard/Module.js b/src/app/shipyard/Module.js index d2827778..8c0a5a9f 100755 --- a/src/app/shipyard/Module.js +++ b/src/app/shipyard/Module.js @@ -81,8 +81,8 @@ export default class Module { // the amount of base resistance the hrp has. if (!isNaN(result) && this.grp === 'hr' && (name === 'kinres' || name === 'thermres' || name === 'explres')) { - let baseRes = this[name]; - result = result * (1 - baseRes); + let baseRes = this[name]; + result = result * (1 - baseRes); } // Sanitise the resultant value to 4dp equivalent @@ -180,7 +180,7 @@ export default class Module { modValue = value - baseValue; if (this.grp === 'hr' && (name === 'kinres' || name === 'thermres' || name === 'explres')) { - modValue = modValue / (1 - baseValue); + modValue = modValue / (1 - baseValue); } } else if (name === 'shieldboost' || name === 'hullboost') { modValue = (1 + value) / (1 + baseValue) - 1; @@ -192,7 +192,7 @@ export default class Module { modValue = modValue * 10000; } else if (modification.type === 'numeric' && name !== 'burst' && name !== 'burstrof') { - modValue = modValue * 100; + modValue = modValue * 100; } this.setModValue(name, modValue, valueIsWithSpecial); @@ -242,38 +242,38 @@ export default class Module { const modification = Modifications.modifications[name]; let result = this[name]; - if (modification) { - // We store percentages as decimals, so to get them back we need to divide by 10000. Otherwise - // we divide by 100. Both ways we end up with a value with two decimal places - let modValue; - if (modification.type === 'percentage') { - modValue = this.getModValue(name) / 10000; - } else if (modification.type === 'numeric') { - modValue = this.getModValue(name) / 100; - } else { - modValue = this.getModValue(name); + if (modification) { + // We store percentages as decimals, so to get them back we need to divide by 10000. Otherwise + // we divide by 100. Both ways we end up with a value with two decimal places + let modValue; + if (modification.type === 'percentage') { + modValue = this.getModValue(name) / 10000; + } else if (modification.type === 'numeric') { + modValue = this.getModValue(name) / 100; + } else { + modValue = this.getModValue(name); + } + if (modValue) { + if (!result && modification.method === 'additive') { + // If the modification is additive and no value is given by default we + // start at zero + result = 0; } - if (modValue) { - if (!result && modification.method === 'additive') { - // If the modification is additive and no value is given by default we - // start at zero - result = 0; - } - if (result !== undefined) { - if (modification.method === 'additive') { - result = result + modValue; - } else if (modification.method === 'overwrite') { - result = modValue; - } else if (name === 'shieldboost' || name === 'hullboost') { - result = (1 + result) * (1 + modValue) - 1; - } else { - result = result * (1 + modValue); - } - } else if (name === 'burstrof') { - // Burst and burst rate of fire are special, as it can not exist but - // have a modification - result = modValue / 100; + if (result !== undefined) { + if (modification.method === 'additive') { + result = result + modValue; + } else if (modification.method === 'overwrite') { + result = modValue; + } else if (name === 'shieldboost' || name === 'hullboost') { + result = (1 + result) * (1 + modValue) - 1; + } else { + result = result * (1 + modValue); + } + } else if (name === 'burstrof') { + // Burst and burst rate of fire are special, as it can not exist but + // have a modification + result = modValue / 100; } } } From 1201da181147d95958fc9ffc5e2221ac79a8573c Mon Sep 17 00:00:00 2001 From: felixlinker Date: Sat, 29 Sep 2018 16:40:36 +0100 Subject: [PATCH 5/9] Differentiate between uneditable and un-highlighted properties in the modifications menu --- src/app/components/Modification.jsx | 9 +++++++-- src/app/components/ModificationsMenu.jsx | 8 ++++---- src/less/slot.less | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/app/components/Modification.jsx b/src/app/components/Modification.jsx index 1e6dae44..b2979bb7 100644 --- a/src/app/components/Modification.jsx +++ b/src/app/components/Modification.jsx @@ -72,6 +72,11 @@ export default class Modification extends TranslatedComponent { return null; } + let inputClassNames = { + 'cb': true, + 'greyed-out': !this.props.highlight + }; + return (
{this.props.editable ? - : } diff --git a/src/app/components/ModificationsMenu.jsx b/src/app/components/ModificationsMenu.jsx index 8f0b8dcc..b68bf004 100644 --- a/src/app/components/ModificationsMenu.jsx +++ b/src/app/components/ModificationsMenu.jsx @@ -214,11 +214,11 @@ export default class ModificationsMenu extends TranslatedComponent { for (const modName of Modifications.modules[m.grp].modifications) { if (!Modifications.modifications[modName].hidden) { const key = modName + (m.getModValue(modName) / 100 || 0); - const editable = modName !== 'fallofffromrange' && - m.blueprint.grades[m.blueprint.grade].features[modName]; + const editable = modName !== 'fallofffromrange'; + const highlight = m.blueprint.grades[m.blueprint.grade].features[modName]; this.lastNeId = modName; - (editable ? modifiableModifications : modifications).push( - diff --git a/src/less/slot.less b/src/less/slot.less index e6c962f9..c6d79e6d 100755 --- a/src/less/slot.less +++ b/src/less/slot.less @@ -74,7 +74,7 @@ border-color:#fff; } - input:disabled { + input.greyed-out { border-color: #888; color: #888; } From 4368015dc0f51a16fe3b53edee48169497f9a98f Mon Sep 17 00:00:00 2001 From: felixlinker Date: Sat, 29 Sep 2018 17:45:45 +0100 Subject: [PATCH 6/9] Fixed variable assignement that should be a comparison --- src/app/utils/JournalUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/utils/JournalUtils.js b/src/app/utils/JournalUtils.js index b7078c87..6d5e0647 100644 --- a/src/app/utils/JournalUtils.js +++ b/src/app/utils/JournalUtils.js @@ -188,7 +188,7 @@ export function shipFromLoadoutJSON(json) { if (!shipTemplate.slots.internal.hasOwnProperty(i)) { continue; } - const isMilitary = isNaN(shipTemplate.slots.internal[i]) ? shipTemplate.slots.internal[i].name = 'military' : false; + const isMilitary = isNaN(shipTemplate.slots.internal[i]) ? shipTemplate.slots.internal[i].name == 'military' : false; // The internal slot might be a standard or a military slot. Military slots have a different naming system let internalSlot = null; From 7e5d52385d2f4187852a13197020779fc777e1c9 Mon Sep 17 00:00:00 2001 From: felixlinker Date: Sat, 29 Sep 2018 20:03:58 +0100 Subject: [PATCH 7/9] Fixed loops in journal style import --- src/app/utils/JournalUtils.js | 133 +++++++++++++++++----------------- 1 file changed, 65 insertions(+), 68 deletions(-) diff --git a/src/app/utils/JournalUtils.js b/src/app/utils/JournalUtils.js index 6d5e0647..7f60cd91 100644 --- a/src/app/utils/JournalUtils.js +++ b/src/app/utils/JournalUtils.js @@ -147,80 +147,77 @@ export function shipFromLoadoutJSON(json) { break; default: } - for (const module of json.Modules) { - if (module.Slot.toLowerCase().search(/hardpoint/) !== -1) { - // Add hardpoints - let hardpoint; - let hardpointClassNum = -1; - let hardpointSlotNum = -1; - let hardpointArrayNum = 0; - for (let i in shipTemplate.slots.hardpoints) { - if (shipTemplate.slots.hardpoints[i] === hardpointClassNum) { - // Another slot of the same class - hardpointSlotNum++; - } else { - // The first slot of a new class - hardpointClassNum = shipTemplate.slots.hardpoints[i]; - hardpointSlotNum = 1; - } - - // Now that we know what we're looking for, find it - const hardpointName = HARDPOINT_NUM_TO_CLASS[hardpointClassNum] + 'Hardpoint' + hardpointSlotNum; - const hardpointSlot = json.Modules.find(elem => elem.Slot.toLowerCase() === hardpointName.toLowerCase()); - if (!hardpointSlot) { - // This can happen with old imports that don't contain new hardpoints - } else if (!hardpointSlot) { - // No module - } else { - hardpoint = _moduleFromFdName(hardpointSlot.Item); - ship.use(ship.hardpoints[hardpointArrayNum], hardpoint, true); - ship.hardpoints[hardpointArrayNum].enabled = hardpointSlot.On; - ship.hardpoints[hardpointArrayNum].priority = hardpointSlot.Priority; - modsToAdd.push({ coriolisMod: hardpoint, json: hardpointSlot }); - } - hardpointArrayNum++; + if (module.Slot.toLowerCase().search(/hardpoint/) !== -1) { + // Add hardpoints + let hardpoint; + let hardpointClassNum = -1; + let hardpointSlotNum = -1; + let hardpointArrayNum = 0; + for (let i in shipTemplate.slots.hardpoints) { + if (shipTemplate.slots.hardpoints[i] === hardpointClassNum) { + // Another slot of the same class + hardpointSlotNum++; + } else { + // The first slot of a new class + hardpointClassNum = shipTemplate.slots.hardpoints[i]; + hardpointSlotNum = 1; } - } - if (module.Slot.toLowerCase().search(/slot\d/) !== -1) { - let internalSlotNum = 1; - let militarySlotNum = 1; - for (let i in shipTemplate.slots.internal) { - if (!shipTemplate.slots.internal.hasOwnProperty(i)) { - continue; - } - const isMilitary = isNaN(shipTemplate.slots.internal[i]) ? shipTemplate.slots.internal[i].name == 'military' : false; - // The internal slot might be a standard or a military slot. Military slots have a different naming system - let internalSlot = null; - if (isMilitary) { - const internalName = 'Military0' + militarySlotNum; - internalSlot = json.Modules.find(elem => elem.Slot.toLowerCase() === internalName.toLowerCase()); - militarySlotNum++; - } else { - // Slot numbers are not contiguous so handle skips. - while (internalSlot === null && internalSlotNum < 99) { - // Slot sizes have no relationship to the actual size, either, so check all possibilities - for (let slotsize = 0; slotsize < 9; slotsize++) { - const internalName = 'Slot' + (internalSlotNum <= 9 ? '0' : '0') + internalSlotNum + '_Size' + slotsize; - if (json.Modules.find(elem => elem.Slot.toLowerCase() === internalName.toLowerCase())) { - internalSlot = json.Modules.find(elem => elem.Slot.toLowerCase() === internalName.toLowerCase()); - break; - } + // Now that we know what we're looking for, find it + const hardpointName = HARDPOINT_NUM_TO_CLASS[hardpointClassNum] + 'Hardpoint' + hardpointSlotNum; + const hardpointSlot = json.Modules.find(elem => elem.Slot.toLowerCase() === hardpointName.toLowerCase()); + if (!hardpointSlot) { + // This can happen with old imports that don't contain new hardpoints + } else if (!hardpointSlot) { + // No module + } else { + hardpoint = _moduleFromFdName(hardpointSlot.Item); + ship.use(ship.hardpoints[hardpointArrayNum], hardpoint, true); + ship.hardpoints[hardpointArrayNum].enabled = hardpointSlot.On; + ship.hardpoints[hardpointArrayNum].priority = hardpointSlot.Priority; + modsToAdd.push({ coriolisMod: hardpoint, json: hardpointSlot }); + } + hardpointArrayNum++; + } + } + if (module.Slot.toLowerCase().search(/slot\d/) !== -1) { + let internalSlotNum = 1; + let militarySlotNum = 1; + for (let i in shipTemplate.slots.internal) { + if (!shipTemplate.slots.internal.hasOwnProperty(i)) { + continue; + } + const isMilitary = isNaN(shipTemplate.slots.internal[i]) ? shipTemplate.slots.internal[i].name == 'military' : false; + + // The internal slot might be a standard or a military slot. Military slots have a different naming system + let internalSlot = null; + if (isMilitary) { + const internalName = 'Military0' + militarySlotNum; + internalSlot = json.Modules.find(elem => elem.Slot.toLowerCase() === internalName.toLowerCase()); + militarySlotNum++; + } else { + // Slot numbers are not contiguous so handle skips. + for (; internalSlot === null && internalSlotNum < 99; internalSlotNum++) { + // Slot sizes have no relationship to the actual size, either, so check all possibilities + for (let slotsize = 0; slotsize < 9; slotsize++) { + const internalName = 'Slot' + (internalSlotNum <= 9 ? '0' : '0') + internalSlotNum + '_Size' + slotsize; + if (json.Modules.find(elem => elem.Slot.toLowerCase() === internalName.toLowerCase())) { + internalSlot = json.Modules.find(elem => elem.Slot.toLowerCase() === internalName.toLowerCase()); + break; } - internalSlotNum++; } } + } - if (!internalSlot) { - // This can happen with old imports that don't contain new slots - } else { - const internalJson = internalSlot; - const internal = _moduleFromFdName(internalJson.Item); - ship.use(ship.internal[i], internal, true); - ship.internal[i].enabled = internalJson.On === true; - ship.internal[i].priority = internalJson.Priority; - modsToAdd.push({ coriolisMod: internal, json: internalSlot }); - } + if (!internalSlot) { + // This can happen with old imports that don't contain new slots + } else { + const internalJson = internalSlot; + const internal = _moduleFromFdName(internalJson.Item); + ship.use(ship.internal[i], internal, true); + ship.internal[i].enabled = internalJson.On === true; + ship.internal[i].priority = internalJson.Priority; + modsToAdd.push({ coriolisMod: internal, json: internalSlot }); } } } From f3d917ccbea5b53f65f4741527aab600f60cbba4 Mon Sep 17 00:00:00 2001 From: felixlinker Date: Sat, 29 Sep 2018 20:04:40 +0100 Subject: [PATCH 8/9] Fixed trailing zero check in journal style import --- src/app/utils/JournalUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/utils/JournalUtils.js b/src/app/utils/JournalUtils.js index 7f60cd91..ad400764 100644 --- a/src/app/utils/JournalUtils.js +++ b/src/app/utils/JournalUtils.js @@ -200,7 +200,7 @@ export function shipFromLoadoutJSON(json) { for (; internalSlot === null && internalSlotNum < 99; internalSlotNum++) { // Slot sizes have no relationship to the actual size, either, so check all possibilities for (let slotsize = 0; slotsize < 9; slotsize++) { - const internalName = 'Slot' + (internalSlotNum <= 9 ? '0' : '0') + internalSlotNum + '_Size' + slotsize; + const internalName = 'Slot' + (internalSlotNum <= 9 ? '0' : '') + internalSlotNum + '_Size' + slotsize; if (json.Modules.find(elem => elem.Slot.toLowerCase() === internalName.toLowerCase())) { internalSlot = json.Modules.find(elem => elem.Slot.toLowerCase() === internalName.toLowerCase()); break; From 28a90768e4c0c2709b34d2873f210895c2e1e3c5 Mon Sep 17 00:00:00 2001 From: felixlinker Date: Sat, 29 Sep 2018 20:26:40 +0100 Subject: [PATCH 9/9] Start searching for available slots at 0 because the Type9 starts there --- src/app/utils/JournalUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/utils/JournalUtils.js b/src/app/utils/JournalUtils.js index ad400764..1cba2565 100644 --- a/src/app/utils/JournalUtils.js +++ b/src/app/utils/JournalUtils.js @@ -181,7 +181,7 @@ export function shipFromLoadoutJSON(json) { } } if (module.Slot.toLowerCase().search(/slot\d/) !== -1) { - let internalSlotNum = 1; + let internalSlotNum = 0; let militarySlotNum = 1; for (let i in shipTemplate.slots.internal) { if (!shipTemplate.slots.internal.hasOwnProperty(i)) {