From 4c0f7b61e4c1403e78b68d8876aeb879d5f17574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:58:17 -0600 Subject: [PATCH] fix: reset shot after tank change --- .../Armor/components/ShotDisplay.tsx | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/components/Armor/components/ShotDisplay.tsx b/src/components/Armor/components/ShotDisplay.tsx index eb2d692cf..6b470feb4 100644 --- a/src/components/Armor/components/ShotDisplay.tsx +++ b/src/components/Armor/components/ShotDisplay.tsx @@ -1,7 +1,7 @@ import { Card, Flex, Inset, Text } from '@radix-ui/themes'; import { Html } from '@react-three/drei'; import { useFrame } from '@react-three/fiber'; -import { useRef } from 'react'; +import { useEffect, useRef } from 'react'; import { Mesh } from 'three'; import { radToDeg } from 'three/src/math/MathUtils'; import { isExplosive } from '../../../core/blitz/isExplosive'; @@ -17,6 +17,7 @@ import { ShotLayerBase, ShotLayerGap, ShotLayerNonExternal, + mutateTankopediaTemporary, useTankopediaTemporary, } from '../../../stores/tankopedia'; import { ArmorType } from './SpacedArmorScene'; @@ -85,6 +86,23 @@ export function ShotDisplay() { 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; return (