From a099df51330fdd608f7fe0d88085e59e2cfce514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Sat, 4 May 2024 17:14:08 -0500 Subject: [PATCH] feat: rotation inputs --- .../[id]/components/Model/HeroSection.tsx | 1 + .../components/Model/components/Options.tsx | 3 + .../[id]/components/QuickInputs/index.css.ts | 11 + .../[id]/components/QuickInputs/index.tsx | 240 ++++++++---------- 4 files changed, 118 insertions(+), 137 deletions(-) create mode 100644 src/app/tools/tankopedia/[id]/components/QuickInputs/index.css.ts diff --git a/src/app/tools/tankopedia/[id]/components/Model/HeroSection.tsx b/src/app/tools/tankopedia/[id]/components/Model/HeroSection.tsx index a34a9edaa..fc6c6a155 100644 --- a/src/app/tools/tankopedia/[id]/components/Model/HeroSection.tsx +++ b/src/app/tools/tankopedia/[id]/components/Model/HeroSection.tsx @@ -88,6 +88,7 @@ export function HeroSection() {
state.mode); @@ -73,6 +74,8 @@ export function Options() { return ( <> + + {mode === 'armor' && ( state.protagonist!); const awaitedModelDefinitions = use(modelDefinitions); const turretYawInput = useRef(null); const gunPitchInput = useRef(null); - const mode = useTankopediaPersistent((state) => state.mode); - const hasCalibratedShells = useEquipment(103, true); - const hasEnhancedArmor = useEquipment(110); const tankModelDefinition = awaitedModelDefinitions[protagonist.tank.id]; const turretModelDefinition = tankModelDefinition.turrets[protagonist.turret.id]; const gunModelDefinition = turretModelDefinition.guns[protagonist.gun.id]; const initialGunPitch = tankModelDefinition.turretRotation?.pitch ?? 0; const hasImprovedVerticalStabilizer = useEquipment(122); + const isFullScreen = useFullScreen(); useEffect(() => { turretYawInput.current!.value = radToDeg(protagonist.yaw).toFixed(1); @@ -39,147 +34,118 @@ export function RotationInputs({ isFullScreen }: RotationInputsProps) { return ( - - { - const value = Number(turretYawInput.current!.value); - if (isNaN(value)) { - turretYawInput.current!.value = radToDeg(protagonist.yaw).toFixed( - 1, - ); - return; - } - const [pitch, yaw] = applyPitchYawLimits( - protagonist.pitch, - degToRad(value), - gunModelDefinition.pitch, - turretModelDefinition.yaw, - hasImprovedVerticalStabilizer, - ); - modelTransformEvent.emit({ pitch, yaw }); - mutateDuel((state) => { - state.protagonist!.pitch = pitch; - state.protagonist!.yaw = yaw; - }); + { + const value = Number(turretYawInput.current!.value); + if (isNaN(value)) { turretYawInput.current!.value = radToDeg(protagonist.yaw).toFixed( 1, ); - }} - onKeyDown={(event) => { - if (event.key === 'Enter') { - turretYawInput.current?.blur(); - } - }} - onFocus={() => turretYawInput.current?.focus()} - ref={turretYawInput} - > - - Yaw - - ° - - - { + state.protagonist!.pitch = pitch; + state.protagonist!.yaw = yaw; + }); + turretYawInput.current!.value = radToDeg(protagonist.yaw).toFixed(1); + }} + onKeyDown={(event) => { + if (event.key === 'Enter') { + turretYawInput.current?.blur(); + } + }} + onFocus={() => turretYawInput.current?.focus()} + ref={turretYawInput} + > + { - const value = Number(gunPitchInput.current!.value); - if (isNaN(value)) { - gunPitchInput.current!.value = ( - -radToDeg(protagonist.pitch) + initialGunPitch - ).toFixed(1); - return; - } - const [pitch, yaw] = applyPitchYawLimits( - degToRad(-value + initialGunPitch), - protagonist.yaw, - gunModelDefinition.pitch, - turretModelDefinition.yaw, - hasImprovedVerticalStabilizer, - ); - modelTransformEvent.emit({ pitch, yaw }); - mutateDuel((state) => { - state.protagonist!.pitch = pitch; - state.protagonist!.yaw = yaw; - }); + > + + + ° + + + { + const value = Number(gunPitchInput.current!.value); + if (isNaN(value)) { gunPitchInput.current!.value = ( -radToDeg(protagonist.pitch) + initialGunPitch ).toFixed(1); + return; + } + const [pitch, yaw] = applyPitchYawLimits( + degToRad(-value + initialGunPitch), + protagonist.yaw, + gunModelDefinition.pitch, + turretModelDefinition.yaw, + hasImprovedVerticalStabilizer, + ); + modelTransformEvent.emit({ pitch, yaw }); + mutateDuel((state) => { + state.protagonist!.pitch = pitch; + state.protagonist!.yaw = yaw; + }); + gunPitchInput.current!.value = ( + -radToDeg(protagonist.pitch) + initialGunPitch + ).toFixed(1); + }} + onKeyDown={(event) => { + if (event.key === 'Enter') { + gunPitchInput.current?.blur(); + } + }} + onFocus={() => gunPitchInput.current?.focus()} + ref={gunPitchInput} + > + { - if (event.key === 'Enter') { - gunPitchInput.current?.blur(); - } - }} - onFocus={() => gunPitchInput.current?.focus()} - ref={gunPitchInput} > - - Pitch - - - ° - - - - - {mode === 'armor' && ( - - { - mutateDuel((draft) => { - draft.antagonist!.equipmentMatrix[0][0] = hasCalibratedShells - ? 0 - : 1; - }); - }} - /> - { - mutateDuel((draft) => { - draft.protagonist!.equipmentMatrix[1][1] = hasEnhancedArmor - ? 0 - : -1; - }); - }} - /> - - )} + + + + ° + + ); }