fix: reset shot after tank change

This commit is contained in:
TrèsAbhi committed 2024-02-29 15:58:17 -06:00
1 parent 206ac373d2
commit 4c0f7b61e4
1 file changed
+19 -1
@@ -1,7 +1,7 @@
import { Card, Flex, Inset, Text } from '@radix-ui/themes'; import { Card, Flex, Inset, Text } from '@radix-ui/themes';
import { Html } from '@react-three/drei'; import { Html } from '@react-three/drei';
import { useFrame } from '@react-three/fiber'; import { useFrame } from '@react-three/fiber';
import { useRef } from 'react'; import { useEffect, useRef } from 'react';
import { Mesh } from 'three'; import { Mesh } from 'three';
import { radToDeg } from 'three/src/math/MathUtils'; import { radToDeg } from 'three/src/math/MathUtils';
import { isExplosive } from '../../../core/blitz/isExplosive'; import { isExplosive } from '../../../core/blitz/isExplosive';
@@ -17,6 +17,7 @@ import {
ShotLayerBase, ShotLayerBase,
ShotLayerGap, ShotLayerGap,
ShotLayerNonExternal, ShotLayerNonExternal,
mutateTankopediaTemporary,
useTankopediaTemporary, useTankopediaTemporary,
} from '../../../stores/tankopedia'; } from '../../../stores/tankopedia';
import { ArmorType } from './SpacedArmorScene'; import { ArmorType } from './SpacedArmorScene';
@@ -85,6 +86,23 @@ export function ShotDisplay() {
postMidPointTracer.current.scale.set(1, 1 - 2 * Math.abs(t2 - 0.5), 1); postMidPointTracer.current.scale.set(1, 1 - 2 * Math.abs(t2 - 0.5), 1);
}); });
useEffect(() => {
function resetShot() {
mutateTankopediaTemporary((draft) => {
draft.shot = undefined;
});
}
const unsubscribes = [
useDuel.subscribe((state) => state.protagonist?.tank, resetShot),
useDuel.subscribe((state) => state.antagonist?.tank, resetShot),
];
return () => {
unsubscribes.forEach((unsubscribe) => unsubscribe());
};
});
if (!shot) return null; if (!shot) return null;
return ( return (