-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Configure power settings on ship systems.
- Loading branch information
1 parent
2d74f20
commit 186ca25
Showing
7 changed files
with
162 additions
and
10 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,115 @@ | ||
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 Power() { | ||
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="Required Power" | ||
helperText="The minimum amount of power required to make this system operate in MegaWatts." | ||
type="text" | ||
inputMode="numeric" | ||
pattern="[0-9]*" | ||
defaultValue={system.requiredPower} | ||
onBlur={(e: any) => { | ||
if (isNaN(Number(e.target.value))) return; | ||
q.plugin.systems.update.netSend({ | ||
pluginId, | ||
systemId: systemId, | ||
shipId, | ||
shipPluginId, | ||
requiredPower: Number(e.target.value), | ||
}); | ||
}} | ||
/> | ||
<OverrideResetButton | ||
property="requiredPower" | ||
setRekey={setRekey} | ||
className="mt-6" | ||
/> | ||
</div> | ||
|
||
<div className="pb-4 flex"> | ||
<Input | ||
labelHidden={false} | ||
label="Default Power" | ||
helperText="The normal amount of power this system will request in MegaWatts." | ||
type="text" | ||
inputMode="numeric" | ||
pattern="[0-9]*" | ||
defaultValue={system.defaultPower} | ||
onBlur={(e: any) => { | ||
if (isNaN(Number(e.target.value))) return; | ||
q.plugin.systems.update.netSend({ | ||
pluginId, | ||
systemId: systemId, | ||
shipId, | ||
shipPluginId, | ||
defaultPower: Number(e.target.value), | ||
}); | ||
}} | ||
/> | ||
<OverrideResetButton | ||
property="defaultPower" | ||
setRekey={setRekey} | ||
className="mt-6" | ||
/> | ||
</div> | ||
<div className="pb-4 flex"> | ||
<Input | ||
labelHidden={false} | ||
label="Max Safe Power" | ||
helperText="The maximum recommended amount of power for this system in MegaWatts. Any additional power consumption will cause the system to sustain damage." | ||
type="text" | ||
inputMode="numeric" | ||
pattern="[0-9]*" | ||
defaultValue={system.maxSafePower} | ||
onBlur={(e: any) => { | ||
if (isNaN(Number(e.target.value))) return; | ||
q.plugin.systems.update.netSend({ | ||
pluginId, | ||
systemId: systemId, | ||
shipId, | ||
shipPluginId, | ||
maxSafePower: Number(e.target.value), | ||
}); | ||
}} | ||
/> | ||
<OverrideResetButton | ||
property="maxSafePower" | ||
setRekey={setRekey} | ||
className="mt-6" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</fieldset> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,5 @@ const links = { | |
basic: "Basic", | ||
system: "System", | ||
power: "Power", | ||
efficiency: "Efficiency", | ||
heat: "Heat", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,24 @@ | ||
import {KiloWatt, MegaWatt} from "@server/utils/unitTypes"; | ||
import {Component} from "./utils"; | ||
|
||
export class PowerComponent extends Component { | ||
static id = "power" as const; | ||
|
||
/** TODO April 27 2022 - Implement this */ | ||
value: number = 0; | ||
/** The minimum amount of power required to make this system operate */ | ||
requiredPower: MegaWatt = 5; | ||
|
||
/** The normal amount of power this system will request */ | ||
defaultPower: MegaWatt = 10; | ||
|
||
/** The threshold of power usage for safely using this system */ | ||
maxSafePower: MegaWatt = 20; | ||
|
||
/** The current power provided to this system, calculated every frame */ | ||
currentPower: MegaWatt = 10; | ||
|
||
/** How much power the system is currently drawing, calculated every frame */ | ||
powerDraw: MegaWatt = 0; | ||
|
||
/** How much power is currently being requested. Could be more than the maxSafePower */ | ||
requestedPower: MegaWatt = 10; | ||
} |