import { getMaxSpeedIndex } from "@thorium/cards/Legacy/EngineControl/getMaxSpeedIndex";
import { HeatBars } from "@thorium/cards/Legacy/ReactorControl/HeatBars";
import { q } from "@thorium/context/AppContext";
import type { EngineSpeed } from "@thorium/ecs-components/shipSystems/engineSpeeds";
import { useStation } from "@thorium/routes/station/useStation";
import Button from "@thorium/ui/Button";
import { cn } from "@thorium/utils/cn";
export function LegacyEngineControl() {
const { shipId } = useStation();
const [{ warpEngines, impulseEngines }] = q.legacy.engineControl.get.useNetRequest({ shipId });
return (
{impulseEngines ? (
q.legacy.engineControl.setSpeed.netSend({
shipId,
impulseSpeedIndex: index,
})
}
/>
) : null}
{warpEngines ? (
q.legacy.engineControl.setSpeed.netSend({
shipId,
warpSpeedIndex: index + 1,
})
}
/>
) : null}
{impulseEngines ? (
<>
{impulseEngines.speeds.map((s, index) => (
))}
{typeof impulseEngines.nominalHeat !== "undefined" &&
typeof impulseEngines.maxHeat !== "undefined" ? (
) : null}
>
) : null}
{warpEngines ? (
<>
{typeof warpEngines.nominalHeat !== "undefined" &&
typeof warpEngines.maxHeat !== "undefined" ? (
) : null}
{warpEngines.speeds.map((speed, index) => (
))}
>
) : null}
);
}
function SpeedControl({
id,
name,
speeds,
speedIndex,
speedChange,
}: {
id: number;
name: string;
speeds: EngineSpeed[];
speedIndex: number;
speedChange: (index: number) => void;
}) {
const [power] = q.legacy.powerDistribution.systemPower.useNetRequest({
systemId: id,
});
const powerWidth = Math.min(
1,
Math.max(0, getMaxSpeedIndex(power.powerLevels || [], power.currentPower || 0)),
);
return (