From 09cc303664159c97598de045e89d73f9d8cbd3b4 Mon Sep 17 00:00:00 2001 From: tresabhi <43380238+tresabhi@users.noreply.github.com> Date: Sat, 28 Nov 2026 17:05:58 -0600 Subject: [PATCH] fix module swapping --- .../PrimaryArmorSceneComponent/index.tsx | 8 +-- .../components/StaticArmorSceneComponent.tsx | 4 +- .../src/components/TankopediaToys/index.tsx | 62 +++++++++++-------- 3 files changed, 42 insertions(+), 32 deletions(-) diff --git a/packages/website/src/components/PrimaryArmorSceneComponent/index.tsx b/packages/website/src/components/PrimaryArmorSceneComponent/index.tsx index dc4549c0f..b1a851a21 100644 --- a/packages/website/src/components/PrimaryArmorSceneComponent/index.tsx +++ b/packages/website/src/components/PrimaryArmorSceneComponent/index.tsx @@ -73,7 +73,7 @@ export function PrimaryArmorSceneComponent({ spacedArmorBuffer: { value: null }, spacedArmorDepth: { value: null }, - opacity: { value: 0 }, + opacity: { value: transitionEvent.last! }, }, ]), }), @@ -125,7 +125,7 @@ export function PrimaryArmorSceneComponent({ equipment, ); const equalizer = - (Tankopedia.state.equalize + (Tankopedia.state.environment.equalize ? protagonist.equalizer?.armor : undefined) ?? 1; @@ -152,7 +152,7 @@ export function PrimaryArmorSceneComponent({ penetration * resolvePenetrationCoefficient( hasCalibratedShells, - Tankopedia.state.equalize, + Tankopedia.state.environment.equalize, shell.type, antagonist.equalizer, ); @@ -197,7 +197,7 @@ export function PrimaryArmorSceneComponent({ () => handleAntagonistEquipmentChange(), ), Tankopedia.on( - (state) => state.equalize, + (state) => state.environment.equalize, () => { handleProtagonistEquipmentChange(); handleAntagonistEquipmentChange(); diff --git a/packages/website/src/components/StaticArmorSceneComponent.tsx b/packages/website/src/components/StaticArmorSceneComponent.tsx index 2ea4a561f..8d5246ec7 100644 --- a/packages/website/src/components/StaticArmorSceneComponent.tsx +++ b/packages/website/src/components/StaticArmorSceneComponent.tsx @@ -149,8 +149,8 @@ export function StaticArmorSceneComponent({ color: color .clone() .multiplyScalar(props.type === ArmorType.Spaced ? 2 ** 2 : 2 ** -1), - opacity: 0, - transparent: true, + opacity: transitionEvent.last!, + transparent: transitionEvent.last! < 1, }), [hasEnhancedArmor, equalize], ); diff --git a/packages/website/src/components/TankopediaToys/index.tsx b/packages/website/src/components/TankopediaToys/index.tsx index c6bcbc84e..118708d3b 100644 --- a/packages/website/src/components/TankopediaToys/index.tsx +++ b/packages/website/src/components/TankopediaToys/index.tsx @@ -719,13 +719,41 @@ export function FlexibilityToy() { const [maxPitch, setMaxPitch] = useState(defaultMax); const container = useRef(null); - // reset when the gun or turret changes + const pitchRange = useCallback( + (yaw: number) => { + const min = applyPitchYawLimits( + -Math.PI, + yaw, + p, + y, + hasImprovedVerticalStabilizer, + hasDownImprovedVerticalStabilizer, + ); + const max = applyPitchYawLimits( + Math.PI, + yaw, + p, + y, + hasImprovedVerticalStabilizer, + hasDownImprovedVerticalStabilizer, + ); + + return [min, max] as const; + }, + [p, y, hasImprovedVerticalStabilizer, hasDownImprovedVerticalStabilizer], + ); + + // keep the current aim within the new limits when the gun or turret changes useEffect(() => { - setYaw(0); - setPitch(0); - setMinPitch(defaultMin); - setMaxPitch(defaultMax); - modelTransformEvent.dispatch({ pitch: 0, yaw: 0 }); + const [min, max] = pitchRange(modelTransformEvent.last!.yaw); + const nextYaw = min[1]; + const nextPitch = clamp(modelTransformEvent.last!.pitch, min[0], max[0]); + + setPitch(nextPitch); + setYaw(nextYaw); + setMinPitch(min[0] - initialTurretPitch); + setMaxPitch(max[0] - initialTurretPitch); + modelTransformEvent.dispatch({ pitch: nextPitch, yaw: nextYaw }); }, [protagonist.tank.id, protagonist.turret.id, protagonist.gun.id]); function outline(limit: "max" | "min") { @@ -786,26 +814,8 @@ export function FlexibilityToy() { const size = Math.min(rect.width, rect.height); const u = event.clientX - rect.left - rect.width / 2; const v = event.clientY - rect.top - rect.height / 2; - let nextYaw = Math.atan2(u, -v); - - const min = applyPitchYawLimits( - -Math.PI, - nextYaw, - p, - y, - hasImprovedVerticalStabilizer, - hasDownImprovedVerticalStabilizer, - ); - const max = applyPitchYawLimits( - Math.PI, - nextYaw, - p, - y, - hasImprovedVerticalStabilizer, - hasDownImprovedVerticalStabilizer, - ); - - nextYaw = min[1]; + const [min, max] = pitchRange(Math.atan2(u, -v)); + const nextYaw = min[1]; const distance = clamp( 2 * Math.sqrt((u / size) ** 2 + (v / size) ** 2), 0,