diff --git a/server/bootstrap/express.ts b/server/bootstrap/express.ts index f20004a18..e8a5f0196 100644 --- a/server/bootstrap/express.ts +++ b/server/bootstrap/express.ts @@ -204,7 +204,7 @@ export default () => { `/import${pascalCase(exportObj.exportable)}`, upload.any(), async (req: express.Request & {files: MulterFile[]}, res) => { - console.log(`Importing ${pascalCase(exportObj.exportable)}`); + console.info(`Importing ${pascalCase(exportObj.exportable)}`); if (req.files[0]) { const importZip = await new Promise( (resolve, reject) => diff --git a/server/imports/flights/export.js b/server/imports/flights/export.js index 6243bcceb..04e344b0b 100644 --- a/server/imports/flights/export.js +++ b/server/imports/flights/export.js @@ -22,7 +22,8 @@ export default function exportFlight(id, res) { return res.end("No flight"); } const zipfile = new yazl.ZipFile(); - const data = {flight: flight, simulators: []}; + const {timeouts, ...flightData} = flight; + const data = {flight: flightData, simulators: []}; data.simulators = flight.simulators.map(simId => { const sim = App.simulators.find(s => s.id === simId); aspectList.forEach(aspect => { diff --git a/server/imports/flights/import.js b/server/imports/flights/import.js index 88661bd2e..5df2ee7ee 100644 --- a/server/imports/flights/import.js +++ b/server/imports/flights/import.js @@ -34,10 +34,14 @@ export default function ImportFlight(filepath, cb) { streamToString(readStream, str => { const data = JSON.parse(str); // Create a duplicate flight with a different ID + let name = data.flight.name; + if (App.flights.some(f => f.name === data.flight.name)) { + name = `${data.flight.name} - Imported`; + } const flight = new Classes.Flight({ ...data.flight, id: uuid.v4(), - name: `${data.flight.name} - Imported`, + name, }); flight.simulators = flight.simulators.map(s => { const newId = uuid.v4(); @@ -48,10 +52,8 @@ export default function ImportFlight(filepath, cb) { id: newId, }); - sim.stations = sim.stations.map(s => new Classes.Station(s)); - App.simulators.push(sim); - addAspects(oldSim, sim, data); + addAspects(oldSim, sim, data, true); App.handleEvent( {simulatorId: sim.id, count: sim.exocomps}, diff --git a/server/triggers/remoteAccess.ts b/server/triggers/remoteAccess.ts index 32e997821..f83ad53d1 100644 --- a/server/triggers/remoteAccess.ts +++ b/server/triggers/remoteAccess.ts @@ -1,7 +1,6 @@ import App from "../app"; export function remoteAccessSendCode({simulatorId, code}) { - console.log(simulatorId, code); return {simulatorId, code}; } @@ -16,7 +15,6 @@ export function remoteAccessUpdateCode({ }) { const simulator = App.simulators.find(s => s.id === simulatorId); const code = simulator.ship.remoteAccessCodes.find(c => c.id === codeId); - console.log(simulatorId, state, code.code); return { simulatorId, state: state === "Accepted" ? "true" : "false", diff --git a/server/typeDefs/flight.ts b/server/typeDefs/flight.ts index 5e68496ad..60898e586 100644 --- a/server/typeDefs/flight.ts +++ b/server/typeDefs/flight.ts @@ -33,9 +33,14 @@ export const aspectList = [ "taskFlows", ]; -export function addAspects(template, sim: Classes.Simulator, data = App) { +export function addAspects( + template, + sim: Classes.Simulator, + data = App, + isImport = false, +) { // Duplicate all of the other stuff attached to the simulator too. - + const aspectMap: Record = {}; aspectList.forEach(aspect => { if ( aspect === "softwarePanels" || @@ -43,14 +48,14 @@ export function addAspects(template, sim: Classes.Simulator, data = App) { aspect === "triggers" || aspect === "midiSets" || aspect === "interfaces" || - aspect === "dmxFixtures" || - aspect === "taskFlows" + aspect === "dmxFixtures" ) { return; } const filterAspect = data[aspect].filter( a => a.simulatorId === template.simulatorId, ); + filterAspect.forEach(a => { const newAspect = cloneDeep(a); newAspect.templateId = newAspect.id; @@ -124,26 +129,66 @@ export function addAspects(template, sim: Classes.Simulator, data = App) { isochip.simulatorId = sim.id; data.isochips.push(new Classes.Isochip(isochip)); } - if (newAspect.power && newAspect.power.powerLevels.length) { - newAspect.power.power = - newAspect.power.defaultLevel || newAspect.power.defaultLevel === 0 - ? newAspect.power.powerLevels[newAspect.power.defaultLevel] + if (!isImport) { + if (newAspect.power && newAspect.power.powerLevels.length) { + newAspect.power.power = + newAspect.power.defaultLevel || newAspect.power.defaultLevel === 0 ? newAspect.power.powerLevels[newAspect.power.defaultLevel] - : newAspect.power.powerLevels[0] - : newAspect.power.powerLevels[0]; - if (newAspect.power.defaultLevel === -1) newAspect.power.power = 0; - } - if (newAspect.power && !newAspect.power.powerLevels.length) { - newAspect.power.power = 0; + ? newAspect.power.powerLevels[newAspect.power.defaultLevel] + : newAspect.power.powerLevels[0] + : newAspect.power.powerLevels[0]; + if (newAspect.power.defaultLevel === -1) newAspect.power.power = 0; + } + if (newAspect.power && !newAspect.power.powerLevels.length) { + newAspect.power.power = 0; + } } if (newAspect.heat && newAspect.class === "Reactor") { newAspect.heat = 0; } } + // Teams need to reference crew + if (aspect === "teams") { + newAspect.officers = newAspect.officers.map(o => aspectMap[o]); + newAspect.location = + aspectMap[newAspect.location] || + aspectMap[newAspect.location] || + newAspect.location; + } + if (aspect === "taskReports") { + newAspect.systemId = + aspectMap[newAspect.systemId] || newAspect.systemId; + newAspect.tasks.forEach(t => { + t.id = aspectMap[t.id] || t.id; + t.systemId = aspectMap[t.systemId] || t.systemId; + t.simulatorId = sim.id; + }); + } + if (aspect === "taskFlows") { + newAspect.steps.forEach(s => { + s.activeTaskIds = s.activeTaskIds.map(t => aspectMap[t] || t); + s.tasks.forEach(t => { + t.id = aspectMap[t.id] || t.id; + t.simulatorId = sim.id; + }); + }); + } + if (aspect === "tasks") { + newAspect.simulatorId = sim.id; + newAspect.systemId = + aspectMap[newAspect.systemId] || newAspect.systemId; + newAspect.deck = aspectMap[newAspect.deck] || newAspect.deck; + newAspect.room = aspectMap[newAspect.room] || newAspect.room; + } + const classItem = new Classes[newAspect.class]( cloneDeep(newAspect), - true, + isImport ? false : true, ); + + // Set up references + aspectMap[newAspect.templateId] = classItem.id; + App[aspect].push(classItem); }); }); @@ -167,7 +212,7 @@ export function addAspects(template, sim: Classes.Simulator, data = App) { ), }), ); - data.softwarePanels.push( + App.softwarePanels.push( new Classes.SoftwarePanel({ id, templateId: panel.id, @@ -194,7 +239,7 @@ export function addAspects(template, sim: Classes.Simulator, data = App) { id, simulatorId: sim.id, }; - data.commandLine.push(new Classes.CommandLine(commandLine)); + App.commandLine.push(new Classes.CommandLine(commandLine)); return id; }) .filter(Boolean); @@ -211,7 +256,7 @@ export function addAspects(template, sim: Classes.Simulator, data = App) { id, simulatorId: sim.id, }; - data.triggerGroups.push(new Classes.Trigger(trigger)); + App.triggerGroups.push(new Classes.Trigger(trigger)); return id; }) .filter(Boolean); @@ -228,7 +273,7 @@ export function addAspects(template, sim: Classes.Simulator, data = App) { id, simulatorId: sim.id, }; - data.interfaces.push(new Classes.Interface(interfaceObj)); + App.interfaces.push(new Classes.Interface(interfaceObj)); // Update any clients assigned to this interface as a station App.clients @@ -240,6 +285,18 @@ export function addAspects(template, sim: Classes.Simulator, data = App) { .forEach(client => { client.setStation(`interface-id:${id}`); }); + + // Update any stations that have this interface as a card. + sim.stations.forEach(station => { + station.cards.forEach(card => { + if ( + card.component.match(/interface-id:.{8}-.{4}-.{4}-.{4}-.{12}/gi) + ) { + card.component = `interface-id:${interfaceObj.templateId}`; + } + }); + }); + return id; }) .filter(Boolean); diff --git a/server/typeDefs/hullPlating.ts b/server/typeDefs/hullPlating.ts index 5910a45a4..06fb40631 100644 --- a/server/typeDefs/hullPlating.ts +++ b/server/typeDefs/hullPlating.ts @@ -75,7 +75,6 @@ const resolver = { s => s.simulatorId === simulatorId, ); } - console.log(returnSystems); return returnSystems; }, subscribe: withFilter( diff --git a/src/components/layouts/cardRenderer.js b/src/components/layouts/cardRenderer.js index 8f3869e53..b81d03d31 100644 --- a/src/components/layouts/cardRenderer.js +++ b/src/components/layouts/cardRenderer.js @@ -121,6 +121,7 @@ function renderCards(props) { return { ...card, in: card.name === cardName, + component: Views.Interface, props: { ...props, interfaceId: card.component.replace("interface-id:", ""), diff --git a/src/components/views/Armory/index.js b/src/components/views/Armory/index.js index 3a8300333..cdaec51b7 100644 --- a/src/components/views/Armory/index.js +++ b/src/components/views/Armory/index.js @@ -462,8 +462,9 @@ class Armory extends Component { const TeamList = ({team, teams, crew, selectedCrew, selectCrew}) => { if (team) { return teams - .find(t => t.id === team) - .officers.map(o => crew.find(c => c.id === o.id)) + .find(t => t?.id === team) + .officers.map(o => crew.find(c => c?.id === o?.id)) + .filter(Boolean) .map(o => (

))} - +