Skip to content

Commit

Permalink
Merge pull request #2669 from Thorium-Sim/station-transfer
Browse files Browse the repository at this point in the history
Station transfer
  • Loading branch information
alexanderson1993 committed Dec 23, 2019
2 parents 948eb13 + 3ac5d63 commit 9c44619
Show file tree
Hide file tree
Showing 38 changed files with 614 additions and 195 deletions.
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ server/build
.cache
locales
src/models
packages
packages
tempServer
temp
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ build
dist
locales
coverage
packages
packages
tempServer
temp
5 changes: 5 additions & 0 deletions public/cardIcons/StationControl.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions server/bootstrap/apollo.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export default (app, SERVER_PORT) => {
introspection: true,
playground: true,
uploads: false,
context: ({req}) => ({
clientId: req && req.headers.clientid,
core: req && req.headers.core,
context: ({req, connection}) => ({
clientId: req?.headers.clientid || connection?.context.clientId,
core: req?.headers.core,
}),
};
const apollo = new ApolloServer(graphqlOptions);
Expand Down
29 changes: 29 additions & 0 deletions server/classes/simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ export default class Simulator {
this.midiSets = params.midiSets || [];

this.crackedClients = params.crackedClients || {};
// The name of the current card which each
// station is on.
this.clientCards = params.clientCards || {};

// Cards assigned to another station from a different station.
this.stationAssignedCards = params.stationAssignedCards || {};

this.flipped = params.flipped || false;
// Set up the teams
if (params.teams) {
Expand Down Expand Up @@ -256,6 +263,28 @@ export default class Simulator {
setLayout(layout) {
this.layout = layout;
}
setClientCard(client, cardName) {
this.clientCards[client] = cardName;
}
addStationAssignedCard(station, card) {
const stationCards = this.stationAssignedCards[station];
this.stationAssignedCards[station] = stationCards
? stationCards.concat(card)
: [card];
}
removeStationAssignedCard(cardName) {
const stationEntry = Object.entries(
this.stationAssignedCards,
).find(([key, value]) => value.find(c => c.name === cardName));
const station = stationEntry?.[0];
if (!station) return;

const stationCards = this.stationAssignedCards[station];
this.stationAssignedCards[station] = stationCards
? stationCards.filter(c => c.name !== cardName)
: [];
}

setTimelineStep(step, timelineId) {
if (timelineId) {
this.setAuxTimelineStep(timelineId, step);
Expand Down
7 changes: 7 additions & 0 deletions server/events/clients.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ App.on("clientSetStation", ({client, stationName, cb}) => {
}
cb && cb();
});
App.on("clientSetCard", ({id, card}) => {
const clientObj = App.clients.find(c => c.id === id);
const {simulatorId} = clientObj;
const simulator = App.simulators.find(s => s.id === simulatorId);
simulator.setClientCard(id, card);
pubsub.publish("clientChanged", App.clients);
});
App.on("clientLogin", ({client, loginName}) => {
const clientObj = App.clients.find(c => c.id === client);
clientObj.login(loginName);
Expand Down
19 changes: 19 additions & 0 deletions server/events/simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,22 @@ App.on("flipSimulator", ({simulatorId, flip}) => {

pubsub.publish("simulatorsUpdate", App.simulators);
});
App.on("stationAssignCard", ({simulatorId, assignedToStation, cardName}) => {
const simulator = App.simulators.find(s => s.id === simulatorId);
const card = simulator.stations
.reduce((acc, next) => acc.concat(next.cards), [])
.find(c => c.name === cardName);

// Remove it so it isn't double-assigned
simulator.removeStationAssignedCard(cardName);

simulator.addStationAssignedCard(assignedToStation, card);
pubsub.publish("simulatorsUpdate", App.simulators);
pubsub.publish("clientChanged", App.clients);
});
App.on("stationUnassignCard", ({simulatorId, cardName}) => {
const simulator = App.simulators.find(s => s.id === simulatorId);
simulator.removeStationAssignedCard(cardName);
pubsub.publish("simulatorsUpdate", App.simulators);
pubsub.publish("clientChanged", App.clients);
});
28 changes: 28 additions & 0 deletions server/typeDefs/clients.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const schema = gql`
cracked: Boolean
commandLineOutput: [String]
commandLineFeedback: [CommandLineFeedback]
currentCard: Card
# Space EdVentures
token: String
email: String
Expand Down Expand Up @@ -176,6 +178,7 @@ const schema = gql`
): String
setClientOverlay(id: ID!, overlay: Boolean!): String
clientCrack(id: ID!, crack: Boolean!): String
clientSetCard(id: ID!, card: String!): String
setKeypadCode(id: ID!, code: [Int]): String
setKeypadEnteredCode(id: ID!, code: [Int!]): String
Expand Down Expand Up @@ -282,6 +285,31 @@ const resolver = {
mobile(client) {
return Boolean(client.mobile);
},
currentCard(client) {
const simulator = App.simulators.find(s => s.id === client.simulatorId);
if (!simulator) return null;
const station = StationResolver(client);
if (!station) return null;

// Get any assigned cards
const {stationAssignedCards = {}} = simulator;
const assignedCardList = Object.values(stationAssignedCards)
.reduce((acc, next) => acc.concat(next), [])
.map(c => c.name)
.filter(Boolean);

const concatCards = stationAssignedCards[station.name] || [];
let cards = station.cards
.map(c => ({...c, assigned: assignedCardList.includes(c.name)}))
.concat(concatCards.map(c => ({...c, newStation: true})))
.filter(Boolean);

const card = cards
.filter(c => !c.hidden)
.find(c => c.name === simulator.clientCards[client.id]);

return card || cards[0];
},
},
Keypad: {
giveHints(client) {
Expand Down
8 changes: 8 additions & 0 deletions server/typeDefs/simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ const schema = gql`
Macro: Station: Unhide Card
"""
unhideSimulatorCard(simulatorId: ID!, cardName: String!): String
stationAssignCard(
simulatorId: ID!
assignedToStation: String!
cardName: String!
): String
stationUnassignCard(simulatorId: ID!, cardName: String!): String
"""
Macro: Simulator: Flip Simulator
"""
Expand Down
35 changes: 32 additions & 3 deletions server/typeDefs/station.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ const schema = gql`
name: String
component: String
hidden: Boolean
# Whether this card is assigned to another station
assigned: Boolean
# Whether this card is assigned to a station
# it doesn't belong to
newStation: Boolean
}
input CardInput {
name: String
component: String
}
extend type Simulator {
stationSets: [StationSet]
Expand Down Expand Up @@ -120,9 +130,28 @@ const resolver = {
},
},
Station: {
cards(station, {showHidden}) {
if (showHidden) return station.cards;
return station.cards.filter(c => !c.hidden);
cards(station, {showHidden}, context) {
let simulator = context.simulator;
if (!simulator) {
const clientObj = App.clients.find(c => c.id === context.clientId);
simulator = App.simulators.find(s => s.id === clientObj?.simulatorId);
context.simulator = simulator;
}
const {stationAssignedCards = {}} = simulator || {};

const assignedCardList = Object.values(stationAssignedCards)
.reduce((acc, next) => acc.concat(next), [])
.map(c => c.name)
.filter(Boolean);
const concatCards = stationAssignedCards[station.name] || [];
let cards = station.cards
.map(c => ({...c, assigned: assignedCardList.includes(c.name)}))
.concat(concatCards.map(c => ({...c, newStation: true})))
.filter(Boolean);

// Indicate cards assigned to other stations
if (showHidden) return cards;
return cards.filter(c => !c.hidden);
},
},
Query: {
Expand Down
Loading

0 comments on commit 9c44619

Please sign in to comment.