Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Power node system #573

Merged
merged 5 commits into from
Mar 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,33 @@
All notable changes to this project will be documented in this file. See
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [1.0.0-alpha.10](https://github.com/Thorium-Sim/thorium-nova/compare/1.0.0-alpha.9...1.0.0-alpha.10) (2023-02-23)


### Bug Fixes

* Add back in the "Reconnect to Server" dialogs ([7f34e1c](https://github.com/Thorium-Sim/thorium-nova/commit/7f34e1cfce0619209b3496c29cdba2b59f6f7915))
* Auto-claim host when first connecting. ([52b4d75](https://github.com/Thorium-Sim/thorium-nova/commit/52b4d757daac0ebd940df30d30e6c1635a019828))
* Config UX improvements. ([e5bd455](https://github.com/Thorium-Sim/thorium-nova/commit/e5bd4554fe8134dcd2a49ee30aa32860c28ea870))
* Darken the background when configuring plugins. ([d20f426](https://github.com/Thorium-Sim/thorium-nova/commit/d20f426cfb9085ac6fef40d08dbab90dc189d6b7))
* Flight Director right-click to spawn and order ships. ([4cbcb0e](https://github.com/Thorium-Sim/thorium-nova/commit/4cbcb0e33d98ea8095a687e0f580d0125257da84))
* If a ship doesn't have a theme assigned to it, only automatically assign themes marked as default. ([004c954](https://github.com/Thorium-Sim/thorium-nova/commit/004c954cd17724f212bdbf0b15f632ea713b04c6))
* Interstellar viewscreen no longer shows the Flight Director view. ([e8c9840](https://github.com/Thorium-Sim/thorium-nova/commit/e8c98403190a7674b2d5e52767226af370353bb1))
* Navigation no longer crashes when transitioning to interstellar space. ([acab5f5](https://github.com/Thorium-Sim/thorium-nova/commit/acab5f5dcf66e142037ab9afdb08c01ef4f7e248))
* Properly save flights periodically while the app is open and when it closes. ([55ca019](https://github.com/Thorium-Sim/thorium-nova/commit/55ca0199ef2c666c6f5b687f0eb5c3036373f942))
* Refactor inventory to use liters instead of cubic meters. ([6d0e95f](https://github.com/Thorium-Sim/thorium-nova/commit/6d0e95f31f14c37b0313ea674018d45a90107849))
* Resolves backend errors when visiting plugin config page. ([be8fb36](https://github.com/Thorium-Sim/thorium-nova/commit/be8fb3696e50c58ff38c1f63b477b123c75ef3ef))
* Send initial data stream when a client first requests it. ([9a94fc2](https://github.com/Thorium-Sim/thorium-nova/commit/9a94fc2c6aff13cabe34fd7e09ce92e1a208377d))
* System specific config overrides ([1bb73da](https://github.com/Thorium-Sim/thorium-nova/commit/1bb73da04059652465d859d1f5a872bf86a0622b))


### Features

* Add a button to restore the default plugin, which will also update the default plugin contents with new Thorium Nova versions. ([82388a8](https://github.com/Thorium-Sim/thorium-nova/commit/82388a8e6ca5cd4d298d0a4e200748e1b9aa1c03))
* Enable snapping network data instead of smoothly interpolating. ([2ab84d8](https://github.com/Thorium-Sim/thorium-nova/commit/2ab84d89a6c9ac6363743d9e11ec16b005e0dd55))
* Improve the behavior of autopilot rotation. ([0ca5723](https://github.com/Thorium-Sim/thorium-nova/commit/0ca57238f4a3e61d824dec5d03a355e29d2520a1))
* Randomly cycle through backgrounds. ([945dd22](https://github.com/Thorium-Sim/thorium-nova/commit/945dd2240ecefb69eed894ff95c4d13d2d615a7e))

# [1.0.0-alpha.9](https://github.com/Thorium-Sim/thorium-nova/compare/1.0.0-alpha.8...1.0.0-alpha.9) (2023-02-08)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "thorium-nova",
"version": "1.0.0-alpha.9",
"version": "1.0.0-alpha.10",
"description": "Spaceship Simulator Controls Platform",
"keywords": [],
"author": "Alex Anderson",
Expand Down
8 changes: 6 additions & 2 deletions server/src/components/power.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ export class PowerComponent extends Component {
/** The threshold of power usage for safely using this system */
maxSafePower: MegaWatt = 20;

/** The current power provided to this system, calculated every frame */
/** The current power provided to this system, calculated every frame. */
currentPower: MegaWatt = 10;

/** How much power the system is currently drawing, calculated every frame */
/**
* How much power the system is attempting to draw, calculated every frame.
* This will always be less than or equal to requested power. If the system
* isn't doing as much work, it won't draw as much power.
*/
powerDraw: MegaWatt = 0;

/** How much power is currently being requested. Could be more than the maxSafePower */
Expand Down
1 change: 0 additions & 1 deletion server/src/components/shipSystems/powerGrid/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./isBattery";
export * from "./isPowerNode";
export * from "./isReactor";
export * from "./powerConnection";
10 changes: 10 additions & 0 deletions server/src/components/shipSystems/powerGrid/isBattery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@ import {Component} from "../../utils";
export class IsBatteryComponent extends Component {
static id = "isBattery" as const;

/**
* The power nodes that are associated with this battery
*/
connectedNodes: number[] = [];

/**
* The amount of power this battery can hold. This provides
* 23 minutes of sustained power.
*/
capacity: MegaWattHour = 46;

/**
* How much power the battery is currently storing
*/
storage: MegaWattHour = 46;
/**
* How much energy the battery can use to charge. Typically
* batteries charge faster than they discharge, while capacitors
Expand Down
2 changes: 1 addition & 1 deletion server/src/components/shipSystems/powerGrid/isPowerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ export class IsPowerNodeComponent extends Component {
* - Least Need First (first fill up the systems with the smallest power requirement)
* - Most Need First (first fill up the systems with the largest power requirement)
*/
distributionMode: "evenly" | "leastFirst" | "mostFirst" = "leastFirst";
distributionMode: "evenly" | "leastFirst" | "mostFirst" = "evenly";
}
5 changes: 5 additions & 0 deletions server/src/components/shipSystems/powerGrid/isReactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import {Component} from "../../utils";
export class IsReactorComponent extends Component {
static id = "isReactor" as const;

/**
* The power nodes and batteries that are associated with this reactor
*/
connectedEntities: number[] = [];

/**
* This will be set when the ship is spawned
* based on the total power required
Expand Down
14 changes: 0 additions & 14 deletions server/src/components/shipSystems/powerGrid/powerConnection.ts

This file was deleted.

13 changes: 12 additions & 1 deletion server/src/spawners/ship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {spawnShipSystem} from "./shipSystem";
import ReactorPlugin from "@server/classes/Plugins/ShipSystems/Reactor";
import BaseShipSystemPlugin from "@server/classes/Plugins/ShipSystems/BaseSystem";
import {getInventoryTemplates} from "@server/utils/getInventoryTemplates";
import {battery} from "@client/pages/Config/data/systems/battery";

const systemCache: Record<string, BaseShipSystemPlugin> = {};
function getSystem(
Expand Down Expand Up @@ -84,7 +85,7 @@ export function spawnShip(
node.addComponent("isPowerNode", {
maxConnections: 3,
connectedSystems: [],
distributionMode: "leastFirst",
distributionMode: "evenly",
});
powerNodes[name] = {entity: node, count: 0};
systemEntities.push(node);
Expand All @@ -102,6 +103,16 @@ export function spawnShip(
// Reactors are special, so take care of them later.

break;
case "battery": {
const entity = spawnShipSystem(systemPlugin, system.overrides);
if (entity.components.isBattery) {
entity.components.isBattery.storage =
entity.components.isBattery.capacity;
}
systemEntities.push(entity);

break;
}
default: {
const entity = spawnShipSystem(systemPlugin, system.overrides);
systemEntities.push(entity);
Expand Down
Loading