Skip to content

Commit

Permalink
Merge pull request #2828 from Thorium-Sim/develop
Browse files Browse the repository at this point in the history
2.6.3
  • Loading branch information
alexanderson1993 committed Mar 7, 2020
2 parents a06e34d + 292c8ab commit f8a26ef
Show file tree
Hide file tree
Showing 60 changed files with 2,616 additions and 1,245 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "thorium",
"version": "2.6.1",
"version": "2.6.2-beta1",
"description": "Starship Simulator Controls",
"private": true,
"repository": {
Expand Down Expand Up @@ -225,14 +225,14 @@
"fuse.js": "^3.4.5",
"googleapis": "^44.0.0",
"graphql": "^14.5.8",
"graphql-bigint": "^1.0.0",
"graphql-type-json": "^0.3.0",
"graphql.macro": "^1.4.2",
"immer": "^5.3.6",
"lodash": "^4.17.15",
"lodash.clonedeep": "^4.5.0",
"lodash.flowright": "^3.5.0",
"lodash.merge": "^4.6.2",
"logrocket": "^1.0.6",
"luxon": "^1.19.3",
"mkdirp": "^0.5.1",
"motu-control": "1.0.4",
Expand Down
1 change: 0 additions & 1 deletion public/electron/helpers/freakout.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// var robot = require("robotjs");
// //console.log(process.version);
// module.exports = function() {
// var screenSize = robot.getScreenSize();
// var height = screenSize.height;
Expand Down
22 changes: 20 additions & 2 deletions server/classes/Countermeasure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ export class Countermeasures extends System {

// Remove all of the unused materials from the countermeasure modules
countermeasure.modules.forEach(m => {
const usedMaterialValue = m.buildProgress;
// Half the build progress so at least some materials are recycled.
const usedMaterialValue = m.buildProgress * 0.5;
Object.entries(m.resourceRequirements).forEach(([key, value]) => {
this.storedMaterials[key] = Math.round(
this.storedMaterials[key] - usedMaterialValue * value,
Expand Down Expand Up @@ -310,6 +311,15 @@ export class Countermeasures extends System {
configureCountermeasureModule(slot, id, config) {
this.slots[slot]?.configureModule(id, config);
}
setSlotActivation(slot, active) {
this.slots[slot]?.setActive(active);
}
setFDNote(id, note) {
const cm =
this.launched.find(l => l.id === id) ||
Object.values(this.slots).find(s => s?.id === id);
cm?.setNote(note);
}
}

interface CountermeasureParams {
Expand All @@ -320,6 +330,7 @@ interface CountermeasureParams {
active?: boolean;
building?: boolean;
totalPowerUsed?: number;
note?: string;
}
class Countermeasure {
id: string;
Expand All @@ -329,6 +340,7 @@ class Countermeasure {
active: boolean;
building: boolean;
totalPowerUsed: number;
note: string;
constructor(params: CountermeasureParams) {
this.id = params.id || uuid.v4();
this.name = params.name || "Countermeasure";
Expand All @@ -340,6 +352,7 @@ class Countermeasure {
this.active = params.active || false;
this.building = params.building || false;
this.totalPowerUsed = params.totalPowerUsed || 0;
this.note = params.note || "";
}

get readyToLaunch() {
Expand Down Expand Up @@ -384,7 +397,9 @@ class Countermeasure {
build() {
this.building = true;
}

setActive(tf) {
this.active = tf;
}
addModule(moduleType) {
if (!this.building) {
const mod = moduleTypes.find(
Expand All @@ -410,4 +425,7 @@ class Countermeasure {
activateModule(id) {
this.modules.find(m => m.id === id)?.activate();
}
setNote(note) {
this.note = note;
}
}
22 changes: 18 additions & 4 deletions server/classes/targeting.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,35 @@ class TargetClass {
this.id = params.id || uuid.v4();
this.systemId = systemId || params.systemId || "";
this.name = params.name || "Target";
this.size = params.size || 1;
this.size = params.size ?? 1;
this.icon = params.icon || "/Sensor Contacts/Icons/Default.svg";
this.picture = params.picture || "/Sensor Contacts/Pictures/Default.png";
this.speed = params.speed || 1;
this.moving = params.moving || true;
this.speed = params.speed ?? 1;
this.moving = params.moving ?? true;
this.clickToTarget = params.clickToTarget || false;
this.quadrant = params.quadrant || 1;
}
update({name, size, system, icon, picture, speed, quadrant, moving, count}) {
update({
name,
size,
system,
icon,
picture,
speed,
quadrant,
moving,
clickToTarget,
count,
}) {
if (name) this.name = name;
if (size) this.size = size;
if (system) this.system = system;
if (icon) this.icon = icon;
if (picture) this.picture = picture;
if (speed) this.speed = speed;
if (moving || moving === false) this.moving = moving;
if (clickToTarget || clickToTarget === false)
this.clickToTarget = clickToTarget;
if (quadrant) this.quadrant = quadrant;
}
}
Expand Down
18 changes: 17 additions & 1 deletion server/classes/universe/components/appearance.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
import {registerComponent} from "../component";
import {immerable} from "immer";

enum MeshTypeEnum {
sphere = "sphere",
cube = "cube",
model = "model",
sprite = "sprite",
}
export class Appearance {
[immerable] = true;
static class = "Appearance";
class = "Appearance";
color: string;
meshType: MeshTypeEnum;
modelAsset: string;
constructor({modelAsset}) {
materialMapAsset: string;
scale: number;

constructor({meshType, modelAsset, materialMapAsset, color, scale = 1}) {
this.meshType = meshType;
this.modelAsset = modelAsset;
this.materialMapAsset = materialMapAsset;
this.color = color;
this.scale = scale;
}
}

Expand Down
16 changes: 16 additions & 0 deletions server/events/Countermeasures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ App.on("countermeasuresLaunchCountermeasure", ({id, slot}) => {
sys.launchCountermeasure(slot);
});
});
App.on("countermeasuresActivateCountermeasure", ({id, slot}) => {
performAction(id, sys => {
sys.setSlotActivation(slot, true);
});
});
App.on("countermeasuresDeactivateCountermeasure", ({id, slot}) => {
performAction(id, sys => {
sys.setSlotActivation(slot, false);
});
});
App.on("countermeasuresSetFDNote", ({id, countermeasureId, note}) => {
performAction(id, sys => {
sys.setFDNote(countermeasureId, note);
});
});

App.on("countermeasuresLaunchUnlockedCountermeasures", ({id}) => {
performAction(id, sys => {
let count = 0;
Expand Down
1 change: 0 additions & 1 deletion server/events/simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ App.on("triggerMacros", ({simulatorId, macros}) => {
if (!noCancelOnReset) flight.timeouts.push(timeout);
},
);
pubsub.publish("simulatorsUpdate", App.simulators);
});

App.on("autoAdvance", ({simulatorId, prev}) => {
Expand Down
3 changes: 2 additions & 1 deletion server/imports/missions/import/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export default function ImportMission(filepath, cb) {
console.log("Importing mission");
yauzl.open(filepath, {lazyEntries: true}, function(err, importZip) {
if (err) {
throw err;
//Eat the error
return;
}
importZip.on("close", function() {
cb(null);
Expand Down
8 changes: 4 additions & 4 deletions server/processes/crew.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ function moveCrew() {
// Start with moving team members
const teamCrewNeedingMoving = teams.reduce((prev, next) => {
const location =
App.rooms.find(d => d.id === next.location) ||
App.decks.find(d => d.id === next.location);
App.rooms.find(d => d.id === next?.location) ||
App.decks.find(d => d.id === next?.location);
const deck = App.decks.find(
d => d.id === (location ? location.deckId : next.location),
d => d.id === (location ? location.deckId : next?.location),
);
if (!deck) return prev;
if (allowedDecks.indexOf(deck.id) === -1) return prev;
next.officers.forEach(o => {
const c = crew.find(cc => cc.id === o);
if (c.location !== deck.id) {
if (c?.location !== deck.id) {
prev.push({deck: deck.id, officer: c});
}
});
Expand Down
14 changes: 7 additions & 7 deletions server/processes/crm.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ function crmContactMove() {
};

// Check collisions
if (t.destroyed) return;
if (t?.destroyed) return;
const collisions = allFighters.filter(f => {
return (
!f.destroyed &&
!f?.destroyed &&
t.fighterId !== f.id &&
distance3d(f.position, t.position) < 5
);
Expand All @@ -110,7 +110,7 @@ function crmContactMove() {
f.hit(t.strength * crm[strengthKey]);
pubsub.publish("crmFighterUpdate", f);

if (f.destroyed) {
if (f?.destroyed) {
triggerUpdate = true;
// Get the fighter that fired it
fragFighter.frags += 1;
Expand All @@ -128,14 +128,14 @@ function crmContactMove() {

if (f.phaserLevel > 0) {
const t = allFighters.find(e => e.id === f.phaserTarget);
if (!t.destroyed && distance3d(f.position, t.position) < 150) {
if (!t?.destroyed && distance3d(f.position, t.position) < 150) {
const strengthKey =
f.type === "fighter" ? "fighterStrength" : "enemyStrength";
t.hit(f.phaserStrength * crm[strengthKey]);
if (tick % 10 === 0) {
pubsub.publish("crmFighterUpdate", t);
}
if (t.destroyed) {
if (t?.destroyed) {
f.frags += 1;
triggerUpdate = true;
}
Expand Down Expand Up @@ -172,7 +172,7 @@ function crmEnemyDogfight() {
if (e.shieldRaise === false && e.shield > 0) {
e.setShield(true);
}
if (!crm.attacking || e.destroyed) return;
if (!crm.attacking || e?.destroyed) return;
// Enemies can perform four actions
// 1. Charge Phasers
// 2. Load a torpedo
Expand All @@ -190,7 +190,7 @@ function crmEnemyDogfight() {
actions.push("loadTorpedo");
const targets = crm.fighters.filter(
f =>
!f.destroyed &&
!f?.destroyed &&
!f.docked &&
distance3d(e.position, f.position) < 100,
);
Expand Down
14 changes: 14 additions & 0 deletions server/typeDefs/countermeasures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const schema = gql`
powerUsage: Float!
availablePower: Float!
buildPercentage: Float!
note: String!
}
type CountermeasureResources {
copper: Float!
Expand Down Expand Up @@ -99,6 +100,14 @@ const schema = gql`
id: ID!
slot: CountermeasureSlotEnum!
): String
countermeasuresActivateCountermeasure(
id: ID!
slot: CountermeasureSlotEnum!
): String
countermeasuresDeactivateCountermeasure(
id: ID!
slot: CountermeasureSlotEnum!
): String
countermeasuresLaunchUnlockedCountermeasures(id: ID!): String
countermeasuresBuildCountermeasure(
id: ID!
Expand All @@ -125,6 +134,11 @@ const schema = gql`
resource: String!
value: Float!
): String
countermeasuresSetFDNote(
id: ID!
countermeasureId: ID!
note: String!
): String
}
extend type Subscription {
countermeasuresUpdate(simulatorId: ID!): Countermeasures
Expand Down
4 changes: 3 additions & 1 deletion server/typeDefs/scalars.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import App from "../app";
import {gql} from "apollo-server-express";
import GraphQLJSON from "graphql-type-json";

import BigInt from "graphql-bigint";
// We define a schema that encompasses all of the types
// necessary for the functionality in this file.
const schema = gql`
scalar JSON
scalar BigInt
extend type Mutation {
snapshot: String
test(key: String): String
Expand All @@ -14,6 +15,7 @@ const schema = gql`

const resolver = {
JSON: GraphQLJSON,
BigInt: BigInt,
Mutation: {
snapshot() {
App.snapshot(true);
Expand Down
6 changes: 6 additions & 0 deletions server/typeDefs/targeting.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const schema = gql`
speed: Float
quadrant: Int
moving: Boolean
clickToTarget: Boolean
}
input TargetClassInput {
Expand All @@ -59,6 +60,7 @@ const schema = gql`
speed: Float
quadrant: Int
moving: Boolean
clickToTarget: Boolean
}
type TargetingContact {
Expand All @@ -74,6 +76,7 @@ const schema = gql`
quadrant: Int
destroyed: Boolean
moving: Boolean
clickToTarget: Boolean
}
extend type Query {
targeting(id: ID, simulatorId: ID): [Targeting]
Expand Down Expand Up @@ -177,6 +180,9 @@ const resolver = {
moving(rootValue) {
return getClassValue({...rootValue, key: "moving"});
},
clickToTarget(rootValue) {
return getClassValue({...rootValue, key: "clickToTarget"});
},
},
Query: {
targeting(root, {id, simulatorId}) {
Expand Down
12 changes: 6 additions & 6 deletions server/typeDefs/thrusters.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ const schema = gql`
movementSpeed: Float
}
type Coordinates {
x: Float!
y: Float!
z: Float!
x: Float
y: Float
z: Float
}
input CoordinatesInput {
x: Float!
y: Float!
z: Float!
x: Float
y: Float
z: Float
}
type Rotation {
yaw: Float
Expand Down

0 comments on commit f8a26ef

Please sign in to comment.