a couple fixes on /import

This commit is contained in:
willyb321
2018-07-02 06:41:01 +10:00
parent 0ee9ce2958
commit 62cac15222

View File

@@ -70,7 +70,7 @@ export function shipFromLoadoutJSON(json) {
let ship = new Ship(shipModel, shipTemplate.properties, shipTemplate.slots); let ship = new Ship(shipModel, shipTemplate.properties, shipTemplate.slots);
ship.buildWith(null); ship.buildWith(null);
// Initial Ship building, don't do engineering yet. // Initial Ship building, don't do engineering yet.
let opts = []; let modsToAdd = [];
for (const module of json.Modules) { for (const module of json.Modules) {
switch (module.Slot.toLowerCase()) { switch (module.Slot.toLowerCase()) {
@@ -176,7 +176,7 @@ export function shipFromLoadoutJSON(json) {
ship.use(ship.hardpoints[hardpointArrayNum], hardpoint, true); ship.use(ship.hardpoints[hardpointArrayNum], hardpoint, true);
ship.hardpoints[hardpointArrayNum].enabled = hardpointSlot.On; ship.hardpoints[hardpointArrayNum].enabled = hardpointSlot.On;
ship.hardpoints[hardpointArrayNum].priority = hardpointSlot.Priority; ship.hardpoints[hardpointArrayNum].priority = hardpointSlot.Priority;
opts.push({ coriolisMod: hardpoint, json: hardpointSlot }); modsToAdd.push({ coriolisMod: hardpoint, json: hardpointSlot });
} }
hardpointArrayNum++; hardpointArrayNum++;
} }
@@ -185,6 +185,9 @@ export function shipFromLoadoutJSON(json) {
let internalSlotNum = 1; let internalSlotNum = 1;
let militarySlotNum = 1; let militarySlotNum = 1;
for (let i in shipTemplate.slots.internal) { 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; 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 // The internal slot might be a standard or a military slot. Military slots have a different naming system
@@ -198,7 +201,7 @@ export function shipFromLoadoutJSON(json) {
while (internalSlot === null && internalSlotNum < 99) { while (internalSlot === null && internalSlotNum < 99) {
// Slot sizes have no relationship to the actual size, either, so check all possibilities // Slot sizes have no relationship to the actual size, either, so check all possibilities
for (let slotsize = 0; slotsize < 9; slotsize++) { for (let slotsize = 0; slotsize < 9; slotsize++) {
const internalName = 'Slot' + (internalSlotNum <= 9 ? '0' : '') + internalSlotNum + '_Size' + slotsize; const internalName = 'Slot' + (internalSlotNum <= 9 ? '0' : '0') + internalSlotNum + '_Size' + slotsize;
if (json.Modules.find(elem => elem.Slot.toLowerCase() === internalName.toLowerCase())) { if (json.Modules.find(elem => elem.Slot.toLowerCase() === internalName.toLowerCase())) {
internalSlot = json.Modules.find(elem => elem.Slot.toLowerCase() === internalName.toLowerCase()); internalSlot = json.Modules.find(elem => elem.Slot.toLowerCase() === internalName.toLowerCase());
break; break;
@@ -210,23 +213,23 @@ export function shipFromLoadoutJSON(json) {
if (!internalSlot) { if (!internalSlot) {
// This can happen with old imports that don't contain new slots // This can happen with old imports that don't contain new slots
} else if (!internalSlot) {
// No module
} else { } else {
const internalJson = internalSlot; const internalJson = internalSlot;
const internal = _moduleFromFdName(internalJson.Item); const internal = _moduleFromFdName(internalJson.Item);
ship.use(ship.internal[i], internal, true); ship.use(ship.internal[i], internal, true);
ship.internal[i].enabled = internalJson.On === true; ship.internal[i].enabled = internalJson.On === true;
ship.internal[i].priority = internalJson.Priority; ship.internal[i].priority = internalJson.Priority;
opts.push({ coriolisMod: internal, json: internalSlot }); modsToAdd.push({ coriolisMod: internal, json: internalSlot });
} }
} }
} }
} }
} }
for (const i of opts) { for (const i of modsToAdd) {
if (i.json.Engineering) _addModifications(i.coriolisMod, i.json.Engineering.Modifiers, i.json.Engineering.BlueprintName, i.json.Engineering.Level, i.json.Engineering.ExperimentalEffect); if (i.json.Engineering) {
_addModifications(i.coriolisMod, i.json.Engineering.Modifiers, i.json.Engineering.BlueprintName, i.json.Engineering.Level, i.json.Engineering.ExperimentalEffect);
}
} }
// We don't have any information on it so guess it's priority 5 and disabled // We don't have any information on it so guess it's priority 5 and disabled
if (!ship.cargoHatch) { if (!ship.cargoHatch) {