Merge pull request #404 from EDCD/feature/fix-imports

Fix journal import
This commit is contained in:
William
2018-10-02 10:14:02 +10:00
committed by GitHub

View File

@@ -180,47 +180,46 @@ export function shipFromLoadoutJSON(json) {
hardpointArrayNum++; hardpointArrayNum++;
} }
} }
if (module.Slot.toLowerCase().search(/slot\d/) !== -1) { }
let internalSlotNum = 0;
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 internalSlotNum = 0;
let internalSlot = null; let militarySlotNum = 1;
if (isMilitary) { for (let i in shipTemplate.slots.internal) {
const internalName = 'Military0' + militarySlotNum; if (!shipTemplate.slots.internal.hasOwnProperty(i)) {
internalSlot = json.Modules.find(elem => elem.Slot.toLowerCase() === internalName.toLowerCase()); continue;
militarySlotNum++; }
} else { const isMilitary = isNaN(shipTemplate.slots.internal[i]) ? shipTemplate.slots.internal[i].name == 'Military' : false;
// Slot numbers are not contiguous so handle skips.
for (; internalSlot === null && internalSlotNum < 99; internalSlotNum++) { // The internal slot might be a standard or a military slot. Military slots have a different naming system
// Slot sizes have no relationship to the actual size, either, so check all possibilities let internalSlot = null;
for (let slotsize = 0; slotsize < 9; slotsize++) { if (isMilitary) {
const internalName = 'Slot' + (internalSlotNum <= 9 ? '0' : '') + internalSlotNum + '_Size' + slotsize; const internalName = 'Military0' + militarySlotNum;
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()); militarySlotNum++;
break; } 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' : '') + internalSlotNum + '_Size' + slotsize;
if (json.Modules.find(elem => elem.Slot.toLowerCase() === internalName.toLowerCase())) {
internalSlot = json.Modules.find(elem => elem.Slot.toLowerCase() === internalName.toLowerCase());
break;
} }
} }
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 });
}
} }
for (const i of modsToAdd) { for (const i of modsToAdd) {