fix module swapping

This commit is contained in:
tresabhi committed 2026-11-28 17:05:58 -06:00
1 parent 63117b8369
commit 09cc303664
3 files changed
+42 -32

No files matched your search

@@ -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();
@@ -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],
);
@@ -719,13 +719,41 @@ export function FlexibilityToy() {
const [maxPitch, setMaxPitch] = useState(defaultMax);
const container = useRef<HTMLDivElement>(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,