mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-29 04:44:23 +01:00
fix module swapping
This commit is contained in:
3 files changed
+42
-32
No files matched your search
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user