antagonist controls

This commit is contained in:
tresabhi committed 2026-11-10 14:54:22 -06:00
1 parent f74b66dd5f
commit f071a77fc0
18 files changed
+316 -259

No files matched your search

@@ -1,8 +0,0 @@
.quick-inputs {
left: -5rem;
}
.quick-inputs:focus-within,
.tank-sandbox-container:hover .quick-inputs {
left: 1rem;
}
@@ -1,160 +0,0 @@
import { HeightIcon, WidthIcon } from "@radix-ui/react-icons";
import { Flex, TextField } from "@radix-ui/themes";
import type { QuicklimeEvent } from "quicklime";
import { useEffect, useRef } from "react";
import { degToRad, radToDeg } from "three/src/math/MathUtils.js";
import { useTankModelDefinition } from "../../../../../../../hooks/useTankModelDefinition";
import { Duel } from "../../../../../../../stores/duel";
import { applyPitchYawLimits } from "../../../../core/blitz/applyPitchYawLimits";
import {
type ModelTransformEventData,
modelTransformEvent,
} from "../../../../core/blitzkit/modelTransform";
import { useEquipment } from "../../../../hooks/useEquipment";
import "./index.css";
export function QuickInputs() {
const protagonist = Duel.use((state) => state.protagonist);
const yawInput = useRef<HTMLInputElement>(null);
const pitchInput = useRef<HTMLInputElement>(null);
const tankModelDefinition = useTankModelDefinition();
const turretModelDefinition =
tankModelDefinition.turrets[protagonist.turret.id];
const gunModelDefinition = turretModelDefinition.guns[protagonist.gun.id];
const initialTurretPitch =
tankModelDefinition.initial_turret_rotation?.pitch ?? 0;
const hasImprovedVerticalStabilizer = useEquipment("protagonist", 122);
const hasDownImprovedVerticalStabilizer = useEquipment("protagonist", 124);
function displayPitch(pitch: number) {
return radToDeg(pitch) - initialTurretPitch;
}
useEffect(() => {
function syncInputValues(data: ModelTransformEventData) {
if (!pitchInput.current || !yawInput.current) return;
pitchInput.current.value = displayPitch(data.pitch).toFixed(1);
yawInput.current.value = radToDeg(data.yaw).toFixed(1);
}
function handleTransformEvent(
event: QuicklimeEvent<ModelTransformEventData>,
) {
syncInputValues(event.data);
}
modelTransformEvent.on(handleTransformEvent);
syncInputValues(modelTransformEvent.last!);
return () => {
modelTransformEvent.off(handleTransformEvent);
};
}, [initialTurretPitch]);
return (
<Flex
align="center"
gap="2"
width="4rem"
direction="column"
style={{
pointerEvents: "auto",
position: "absolute",
top: "50%",
transform: "translateY(-50%)",
transitionDuration: "0.2s",
}}
className="quick-inputs"
>
<TextField.Root
variant="classic"
size="1"
radius="full"
style={{ flex: 1, textAlign: "right" }}
defaultValue={radToDeg(modelTransformEvent.last!.yaw).toFixed(1)}
onBlur={() => {
const value = Number(yawInput.current!.value);
if (isNaN(value)) {
yawInput.current!.value = radToDeg(
modelTransformEvent.last!.yaw,
).toFixed(1);
return;
}
const [pitch, yaw] = applyPitchYawLimits(
modelTransformEvent.last!.pitch,
degToRad(value),
gunModelDefinition.pitch!,
turretModelDefinition.yaw,
hasImprovedVerticalStabilizer,
hasDownImprovedVerticalStabilizer,
);
modelTransformEvent.dispatch({ pitch, yaw });
yawInput.current!.value = radToDeg(
modelTransformEvent.last!.yaw,
).toFixed(1);
}}
onKeyDown={(event) => {
if (event.key === "Enter") {
yawInput.current?.blur();
}
}}
onFocus={() => yawInput.current?.focus()}
ref={yawInput}
>
<TextField.Slot style={{ userSelect: "none" }}>
<WidthIcon />
</TextField.Slot>
<TextField.Slot />
</TextField.Root>
<TextField.Root
variant="classic"
size="1"
radius="full"
style={{ flex: 1, textAlign: "right" }}
defaultValue={displayPitch(modelTransformEvent.last!.pitch).toFixed(1)}
onBlur={() => {
const value = Number(pitchInput.current!.value);
if (isNaN(value)) {
pitchInput.current!.value = displayPitch(
modelTransformEvent.last!.pitch,
).toFixed(1);
return;
}
const [pitch, yaw] = applyPitchYawLimits(
degToRad(value + initialTurretPitch),
modelTransformEvent.last!.yaw,
gunModelDefinition.pitch!,
turretModelDefinition.yaw,
hasImprovedVerticalStabilizer,
hasDownImprovedVerticalStabilizer,
);
modelTransformEvent.dispatch({ pitch, yaw });
pitchInput.current!.value = displayPitch(
modelTransformEvent.last!.pitch,
).toFixed(1);
}}
onKeyDown={(event) => {
if (event.key === "Enter") {
pitchInput.current?.blur();
}
}}
onFocus={() => pitchInput.current?.focus()}
ref={pitchInput}
>
<TextField.Slot
style={{
userSelect: "none",
}}
>
<HeightIcon />
</TextField.Slot>
<TextField.Slot />
</TextField.Root>
</Flex>
);
}