From 7db02aa5798cc12d52572f895db0689df87c452c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Tue, 23 Jan 2024 13:14:43 -0600 Subject: [PATCH] fix: green penetration reactivity --- .../ArmorMesh/components/Armor/index.tsx | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/components/ArmorMesh/components/Armor/index.tsx b/src/components/ArmorMesh/components/Armor/index.tsx index 327a5aeff..51939ff74 100644 --- a/src/components/ArmorMesh/components/Armor/index.tsx +++ b/src/components/ArmorMesh/components/Armor/index.tsx @@ -22,12 +22,9 @@ export function ArmorMesh({ maxThickness, ...props }: ArmorMeshProps) { - const initialEquipment = useTankopediaPersistent.getState().model.equipment; const camera = useThree((state) => state.camera); const initialShell = useDuel.getState().antagonist!.shell; - const greenPenetration = useTankopediaPersistent( - (state) => state.model.visual.greenPenetration, - ); + const initialTankopedia = useTankopediaPersistent.getState(); const material = useRef(null); const resolution = new Vector2(); const explosionCapable = isExplosive(initialShell.type); @@ -73,6 +70,14 @@ export function ArmorMesh({ (state) => state.antagonist!.shell, updateShellProperties, ), + useTankopediaPersistent.subscribe( + (state) => state.model.visual.greenPenetration, + (greenPenetration) => { + if (material.current) { + material.current.uniforms.greenPenetration.value = greenPenetration; + } + }, + ), ]; return () => { @@ -118,17 +123,21 @@ export function ArmorMesh({ projectionMatrixInverse: { value: null }, zNear: { value: camera.near }, zFar: { value: camera.far }, - greenPenetration: { value: greenPenetration }, + greenPenetration: { + value: initialTankopedia.model.visual.greenPenetration, + }, maxThickness: { value: maxThickness }, isExplosive: { value: explosionCapable }, canSplash: { value: canSplash(initialShell.type) }, thickness: { - value: thickness * (initialEquipment.enhancedArmor ? 1.04 : 1), + value: + thickness * + (initialTankopedia.model.equipment.enhancedArmor ? 1.04 : 1), }, penetration: { value: resolveNearPenetration(initialShell.penetration) * - (initialEquipment.calibratedShells + (initialTankopedia.model.equipment.calibratedShells ? explosionCapable ? 1.1 : 1.05 @@ -143,11 +152,6 @@ export function ArmorMesh({ explosionRadius: { value: initialShell.explosionRadius ?? 0 }, }} /> - {/* */} );