From fd408d677764f35f495a934856088158e64dcc93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Tue, 12 Mar 2024 17:39:46 -0500 Subject: [PATCH] fix: use initial gun pitches correctly --- .../[id]/components/Characteristics/index.tsx | 5 ++- .../[id]/components/QuickInputs/index.tsx | 43 +++++++++---------- src/core/blitzkrieg/assignDuelMember.ts | 6 ++- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/app/tools/tankopedia/[id]/components/Characteristics/index.tsx b/src/app/tools/tankopedia/[id]/components/Characteristics/index.tsx index 284d9a5c8..8a1846a10 100644 --- a/src/app/tools/tankopedia/[id]/components/Characteristics/index.tsx +++ b/src/app/tools/tankopedia/[id]/components/Characteristics/index.tsx @@ -56,6 +56,7 @@ export function Characteristics() { turretModelDefinition.boundingBox, ), ); + const gunDefaultPitch = tankModelDefinition.turretRotation?.pitch ?? 0; const weight = tank.weight + engine.weight + track.weight + turret.weight + gun.weight; const weightTons = weight / 1000; @@ -459,10 +460,12 @@ export function Characteristics() { {gunModelDefinition.pitch.max + + gunDefaultPitch + (hasImprovedVerticalStabilizer ? 3 : 0)} - {-gunModelDefinition.pitch.min + + {-gunModelDefinition.pitch.min - + gunDefaultPitch + (hasImprovedVerticalStabilizer ? 3 : 0)} {gunModelDefinition.pitch.front && ( diff --git a/src/app/tools/tankopedia/[id]/components/QuickInputs/index.tsx b/src/app/tools/tankopedia/[id]/components/QuickInputs/index.tsx index 9001f3a6f..fada3703f 100644 --- a/src/app/tools/tankopedia/[id]/components/QuickInputs/index.tsx +++ b/src/app/tools/tankopedia/[id]/components/QuickInputs/index.tsx @@ -1,5 +1,6 @@ import { Flex, TextField } from '@radix-ui/themes'; import { use, useEffect, useRef } from 'react'; +import { degToRad, radToDeg } from 'three/src/math/MathUtils'; import { applyPitchYawLimits } from '../../../../../../core/blitz/applyPitchYawLimits'; import { modelDefinitions } from '../../../../../../core/blitzkrieg/modelDefinitions'; import { modelTransformEvent } from '../../../../../../core/blitzkrieg/modelTransform'; @@ -20,22 +21,20 @@ export function RotationInputs({ isFullScreen }: RotationInputsProps) { const mode = useTankopediaPersistent((state) => state.mode); const hasCalibratedShells = useEquipment(103, true); const hasEnhancedArmor = useEquipment(110); - - useEffect(() => { - turretYawInput.current!.value = `${-Math.round( - protagonist.yaw * (180 / Math.PI), - )}`; - }, [protagonist.yaw]); - useEffect(() => { - gunPitchInput.current!.value = `${-Math.round( - protagonist.pitch * (180 / Math.PI), - )}`; - }, [protagonist.pitch]); - 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; + + useEffect(() => { + turretYawInput.current!.value = radToDeg(protagonist.yaw).toFixed(0); + }, [protagonist.yaw]); + useEffect(() => { + gunPitchInput.current!.value = ( + -radToDeg(protagonist.pitch) + initialGunPitch + ).toFixed(0); + }, [protagonist.pitch]); return ( { const [pitch, yaw] = applyPitchYawLimits( protagonist.pitch, - -Number(turretYawInput.current?.value) * (Math.PI / 180), + degToRad(Number(turretYawInput.current!.value)), gunModelDefinition.pitch, turretModelDefinition.yaw, ); @@ -81,9 +79,9 @@ export function RotationInputs({ isFullScreen }: RotationInputsProps) { state.protagonist!.pitch = pitch; state.protagonist!.yaw = yaw; }); - turretYawInput.current!.value = `${Math.round( - yaw * (180 / Math.PI), - )}`; + turretYawInput.current!.value = radToDeg(protagonist.yaw).toFixed( + 0, + ); }} onKeyDown={(event) => { if (event.key === 'Enter') { @@ -116,10 +114,11 @@ export function RotationInputs({ isFullScreen }: RotationInputsProps) { Pitch { const [pitch, yaw] = applyPitchYawLimits( - -Number(gunPitchInput.current?.value) * (Math.PI / 180), + degToRad( + -Number(gunPitchInput.current!.value) + initialGunPitch, + ), protagonist.yaw, gunModelDefinition.pitch, turretModelDefinition.yaw, @@ -129,9 +128,9 @@ export function RotationInputs({ isFullScreen }: RotationInputsProps) { state.protagonist!.pitch = pitch; state.protagonist!.yaw = yaw; }); - gunPitchInput.current!.value = `${Math.round( - pitch * (180 / Math.PI), - )}`; + gunPitchInput.current!.value = ( + -radToDeg(protagonist.pitch) + initialGunPitch + ).toFixed(0); }} onKeyDown={(event) => { if (event.key === 'Enter') { diff --git a/src/core/blitzkrieg/assignDuelMember.ts b/src/core/blitzkrieg/assignDuelMember.ts index aef3eab48..dd204dd7b 100644 --- a/src/core/blitzkrieg/assignDuelMember.ts +++ b/src/core/blitzkrieg/assignDuelMember.ts @@ -1,9 +1,11 @@ +import { degToRad } from 'three/src/math/MathUtils'; import { DuelMember, genericDefaultEquipmentMatrix, mutateDuel, } from '../../stores/duel'; import { availableProvisions } from './availableProvisions'; +import { modelDefinitions } from './modelDefinitions'; import { provisionDefinitions } from './provisionDefinitions'; import { tankDefinitions } from './tankDefinitions'; @@ -13,6 +15,8 @@ export async function assignDuelMember( ) { const awaitedTankDefinitions = await tankDefinitions; const awaitedProvisionDefinitions = await provisionDefinitions; + const awaitedModelDefinitions = await modelDefinitions; + const tankModelDefinition = awaitedModelDefinitions[id]; const tank = awaitedTankDefinitions[id]; const turret = tank.turrets.at(-1)!; const gun = turret.guns.at(-1)!; @@ -32,7 +36,7 @@ export async function assignDuelMember( shell, track, equipment: genericDefaultEquipmentMatrix, - pitch: 0, + pitch: degToRad(tankModelDefinition.turretRotation?.pitch ?? 0), yaw: 0, camouflage: true, consumables: [],