Skip to content

Commit

Permalink
feat: System heat configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderson1993 committed Jan 26, 2023
1 parent a29a65c commit c6d75a3
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 37 deletions.
168 changes: 167 additions & 1 deletion client/src/pages/Config/ShipSystems/Heat.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,169 @@
import {q} from "@client/context/AppContext";
import Input from "@thorium/ui/Input";
import {useContext, useReducer} from "react";
import {Navigate, useParams} from "react-router-dom";
import {ShipPluginIdContext} from "../Ships/ShipSystemOverrideContext";
import {OverrideResetButton} from "./OverrideResetButton";

export function Heat() {
return null;
const [rekey, setRekey] = useReducer(() => Math.random(), Math.random());

const {pluginId, systemId, shipId} = useParams() as {
pluginId: string;
systemId: string;
shipId: string;
};
const key = `${systemId}${rekey}`;
const shipPluginId = useContext(ShipPluginIdContext);

const [system] = q.plugin.systems.get.useNetRequest({
pluginId,
systemId,
shipId,
shipPluginId,
});

if (!system) return <Navigate to={`/config/${pluginId}/systems`} />;

return (
<fieldset key={key} className="flex-1 overflow-y-auto">
<div className="flex flex-wrap">
<div className="flex-1 pr-4">
<div className="pb-4 flex">
<Input
labelHidden={false}
label="Coolant Heat Transfer Rate"
helperText="The rate at which heat can transfer from the system to coolant stored the room, in Kelvin / second."
type="text"
inputMode="numeric"
pattern="[0-9]*"
defaultValue={system.coolantHeatTransferRate}
onBlur={(e: any) => {
if (isNaN(Number(e.target.value))) return;
q.plugin.systems.update.netSend({
pluginId,
systemId: systemId,
shipId,
shipPluginId,
coolantHeatTransferRate: Number(e.target.value),
});
}}
/>
<OverrideResetButton
property="coolantHeatTransferRate"
setRekey={setRekey}
className="mt-6"
/>
</div>
<div className="pb-4 flex">
<Input
labelHidden={false}
label="Heat Dissipation Rate"
helperText="A multiplier for the effectiveness of dissipating heat into space. Less than 1 = less effective, more than 1 = more effective."
type="text"
inputMode="numeric"
pattern="[0-9]*"
defaultValue={system.heatDissipationRate}
onBlur={(e: any) => {
if (isNaN(Number(e.target.value))) return;
q.plugin.systems.update.netSend({
pluginId,
systemId: systemId,
shipId,
shipPluginId,
heatDissipationRate: Number(e.target.value),
});
}}
/>
<OverrideResetButton
property="heatDissipationRate"
setRekey={setRekey}
className="mt-6"
/>
</div>

<div className="pb-4 flex">
<Input
labelHidden={false}
label="Nominal Heat"
helperText="The standard heat level in Kelvin. When plotted in a heat bar, this level represents the bottom of the bar."
type="text"
inputMode="numeric"
pattern="[0-9]*"
defaultValue={system.nominalHeat}
onBlur={(e: any) => {
if (isNaN(Number(e.target.value))) return;
q.plugin.systems.update.netSend({
pluginId,
systemId: systemId,
shipId,
shipPluginId,
nominalHeat: Number(e.target.value),
});
}}
/>
<OverrideResetButton
property="nominalHeat"
setRekey={setRekey}
className="mt-6"
/>
</div>

<div className="pb-4 flex">
<Input
labelHidden={false}
label="Max Safe Heat"
helperText="The temperature in Kelvin above which the system's efficiency starts decreasing due to overheating."
type="text"
inputMode="numeric"
pattern="[0-9]*"
defaultValue={system.maxSafeHeat}
onBlur={(e: any) => {
if (isNaN(Number(e.target.value))) return;
q.plugin.systems.update.netSend({
pluginId,
systemId: systemId,
shipId,
shipPluginId,
maxSafeHeat: Number(e.target.value),
});
}}
/>
<OverrideResetButton
property="maxSafeHeat"
setRekey={setRekey}
className="mt-6"
/>
</div>

<div className="pb-4 flex">
<Input
labelHidden={false}
label="Max Heat"
helperText="The maximum possible temperature in Kelvin. Represents the top of the heat bar graph."
type="text"
inputMode="numeric"
pattern="[0-9]*"
defaultValue={system.maxHeat}
onBlur={(e: any) => {
if (isNaN(Number(e.target.value))) return;
q.plugin.systems.update.netSend({
pluginId,
systemId: systemId,
shipId,
shipPluginId,
maxHeat: Number(e.target.value),
});
}}
/>
<OverrideResetButton
property="maxHeat"
setRekey={setRekey}
className="mt-6"
/>
</div>
</div>
</div>
</fieldset>
);
}
7 changes: 6 additions & 1 deletion client/src/pages/Config/ShipSystems/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ const SystemConfig = () => {
};
const [system] = q.plugin.systems.get.useNetRequest({pluginId, systemId});
const Comp = systemConfigs[system.type];
if (!Comp) return null;
if (!Comp)
return (
<h3 className="text-center text-xl">
No configuration for this system type.
</h3>
);
return <Comp />;
};

Expand Down
21 changes: 21 additions & 0 deletions client/src/pages/Config/data/systems/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ export const systems = t.router({
name: z.string().optional(),
description: z.string().optional(),
tags: z.string().array().optional(),
coolantHeatTransferRate: z.number().optional(),
heatDissipationRate: z.number().optional(),
nominalHeat: z.number().optional(),
maxSafeHeat: z.number().optional(),
maxHeat: z.number().optional(),
})
)
.send(async ({ctx, input}) => {
Expand Down Expand Up @@ -135,6 +140,22 @@ export const systems = t.router({
shipId: input.shipId,
});
}

if (typeof input.coolantHeatTransferRate === "number") {
shipSystem.coolantHeatTransferRate = input.coolantHeatTransferRate;
}
if (typeof input.heatDissipationRate === "number") {
shipSystem.heatDissipationRate = input.heatDissipationRate;
}
if (typeof input.nominalHeat === "number") {
shipSystem.nominalHeat = input.nominalHeat;
}
if (typeof input.maxSafeHeat === "number") {
shipSystem.maxSafeHeat = input.maxSafeHeat;
}
if (typeof input.maxHeat === "number") {
shipSystem.maxHeat = input.maxHeat;
}
pubsub.publish.plugin.systems.all({pluginId: input.pluginId});
pubsub.publish.plugin.systems.get({
pluginId: input.pluginId,
Expand Down
12 changes: 11 additions & 1 deletion server/src/classes/Plugins/ShipSystems/BaseSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ export default class BaseShipSystemPlugin extends Aspect {
* The rate at which heat can transfer in or out.
* Heat generated by this entity isn't bound by this number
*/
heatRate: KelvinPerSecond = 10;
coolantHeatTransferRate: KelvinPerSecond = 10;

/**
* The effectiveness of transferring heat into space. A multiplier
* for the equation P = A * a * T5
*/
heatDissipationRate: number = 1;

/**
* The standard heat level. When plotted, this
Expand Down Expand Up @@ -61,5 +67,9 @@ export default class BaseShipSystemPlugin extends Aspect {
this.assets = params.assets || {
soundEffects: [],
};
this.coolantHeatTransferRate = params.coolantHeatTransferRate || 10;
this.nominalHeat = params.nominalHeat || 295.37;
this.maxSafeHeat = params.maxSafeHeat || 1000;
this.maxHeat = params.maxHeat || 2500;
}
}
34 changes: 0 additions & 34 deletions server/src/components/heat.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,6 @@
import {Kelvin, KelvinPerSecond} from "../utils/unitTypes";
import {Component} from "./utils";

/**
* http://www.projectrho.com/public_html/rocket/heatrad.php#dullred
* Heat is radiated out based on this equation:
* P = A * σ * T4
* Where P is watts, A is the area of the radiator, σ is the constant below
* and T4 is the temperature of the radiator raised to the fourth power
*
* This is untenable for the power we're dealing with, and very boring in a
* sci-fi setting. Therefore, I'm adjusting the formula just a little bit.
*
* P = A * a * T5
*
* We can hand-wave the explanation as using some kind of warp field to
* change the speed of light value used in the Stefan-Boltzmann constant
*
* We'll assume each heat radiator is 1 meter square
*
* We can also use this formula for converting heat into watts and vice versa
*
* (J / specific heat capacity) / mass (of the heated object)
*
* A few possible mediums for transferring heat, in J/gK:
* - Ammonia Gas: 2.061
* - Ammonia Liquid: 4.7
* - Water Vapor: 1.865
* - Water Liquid: 4.18
* - Steel: .475
* - Titanium: .52
* - Aluminum: .904
*/

// https://en.wikipedia.org/wiki/Stefan–Boltzmann_constant
const StephanBoltzmannConstant = 5.670373 * 1e-8;

export class HeatComponent extends Component {
static id = "heat" as const;

Expand Down
3 changes: 3 additions & 0 deletions server/src/utils/unitTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,6 @@ export type MegaWattHour = Flavor<number, "megawatthour">;
export type MegaWatt = Flavor<number, "megawatt">;
export type GigaWattHour = Flavor<number, "gigawatthour">;
export type GigaWatt = Flavor<number, "gigawatt">;

// https://en.wikipedia.org/wiki/Stefan–Boltzmann_constant
const StephanBoltzmannConstant = 5.670373 * 1e-8;

0 comments on commit c6d75a3

Please sign in to comment.