Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderson1993 committed Aug 19, 2023
2 parents 89f6ea0 + eafa6e4 commit 0734518
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 34 deletions.
2 changes: 1 addition & 1 deletion server/bootstrap/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<yauzl.ZipFile>(
(resolve, reject) =>
Expand Down
3 changes: 2 additions & 1 deletion server/imports/flights/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
10 changes: 6 additions & 4 deletions server/imports/flights/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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},
Expand Down
2 changes: 0 additions & 2 deletions server/triggers/remoteAccess.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import App from "../app";

export function remoteAccessSendCode({simulatorId, code}) {
console.log(simulatorId, code);
return {simulatorId, code};
}

Expand All @@ -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",
Expand Down
95 changes: 76 additions & 19 deletions server/typeDefs/flight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,29 @@ 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<string, string> = {};
aspectList.forEach(aspect => {
if (
aspect === "softwarePanels" ||
aspect === "commandLines" ||
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;
Expand Down Expand Up @@ -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);
});
});
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion server/typeDefs/hullPlating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ const resolver = {
s => s.simulatorId === simulatorId,
);
}
console.log(returnSystems);
return returnSystems;
},
subscribe: withFilter(
Expand Down
1 change: 1 addition & 0 deletions src/components/layouts/cardRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ function renderCards(props) {
return {
...card,
in: card.name === cardName,
component: Views.Interface,
props: {
...props,
interfaceId: card.component.replace("interface-id:", ""),
Expand Down
5 changes: 3 additions & 2 deletions src/components/views/Armory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => (
<p
key={`crew-${o.id}`}
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/Sensors/gridCore/CoreSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const CoreSidebar = ({
</option>
))}
<option disabled>─────────</option>
<option disabled>Timed</option>
<option value="timed">Timed</option>
</Input>
<Button size="sm" color="danger" block onClick={clearContacts}>
Clear
Expand Down
20 changes: 17 additions & 3 deletions src/components/views/Sensors/gridCore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SpeedAsker from "./speedAsker";
import {useDragStart} from "./hooks/useDragStart";
import {useSensorsData} from "./hooks/useSensorData";
import {useTargeting} from "./hooks/useTargeting";
import {speeds, SENSORS_OFFSET} from "./constants";
import {speeds, SENSORS_OFFSET, distance3d} from "./constants";
import {CoreSidebar} from "./CoreSidebar";

import "./gridCore.scss";
Expand Down Expand Up @@ -61,7 +61,14 @@ const GridCore = ({
const [draggingContacts, setDraggingContacts] = React.useState([]);

const triggerUpdate = speed => {
speed = Number(speed);
let timed = false;
if (speed === "timed") {
timed = true;
speed = Number(window.prompt("How many seconds?", "10"));
if (isNaN(speed)) return;
} else {
speed = Number(speed);
}
// Delete any dragging contacts that are out of bounds
const newContacts = draggingContacts
.map(c => checkContactPosition(c, node, dimensions))
Expand All @@ -86,9 +93,16 @@ const GridCore = ({
const moveContacts = newContacts
.map(c => {
const {x = 0, y = 0, z = 0} = c.destination;
let contactSpeed = speed;

if (timed) {
const distance = distance3d({x, y, z}, c.location);
contactSpeed = (distance / speed) * 10;
}

return {
id: c.id,
speed,
speed: contactSpeed,
destination: {x, y, z},
};
})
Expand Down
1 change: 1 addition & 0 deletions src/components/views/Sensors/gridCore/speedAsker.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const SpeedAsker = ({
{s.label}
</p>
))}
<p onClick={() => triggerUpdate("timed")}>Timed</p>
<p onClick={cancelMove}>Cancel</p>
<Mutation
mutation={gql`
Expand Down

0 comments on commit 0734518

Please sign in to comment.