From beff5e32651651f3b6eaceafb377aa3d82ab8e38 Mon Sep 17 00:00:00 2001 From: neru Date: Mon, 1 Jun 2026 15:38:04 -0300 Subject: [PATCH] feat: rely on state mgr instead of hardcoded loop count --- src/app/fear/scene-components/creature.tsx | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/app/fear/scene-components/creature.tsx b/src/app/fear/scene-components/creature.tsx index cabe933..c3d206d 100644 --- a/src/app/fear/scene-components/creature.tsx +++ b/src/app/fear/scene-components/creature.tsx @@ -15,30 +15,29 @@ export default function TheCreature() { const [isSpawned, setIsSpawned] = useState(false); const globalDistance = useRef(32); - const [currentLoop, setCurrentLoop] = useState(fearState.loopCount); + const [finaleTriggered, setFinaleTriggered] = useState(fearState.finaleTriggered); const audioPlaying = useRef(false); useEffect(() => { const unsubscribe = fearState.subscribe(() => { - setCurrentLoop(fearState.loopCount); + setFinaleTriggered(fearState.finaleTriggered); - if (fearState.loopCount < 4) { + if (!fearState.finaleTriggered) { setIsSpawned(false); setHasTriggered(false); globalDistance.current = 32; audioPlaying.current = false; - if (audioRef.current && audioRef.current.isPlaying) { + if (audioRef.current && audioRef.current.isPlaying) audioRef.current.stop(); - } } }); return () => unsubscribe(); }, []); useFrame((state, delta) => { - if (fearState.loopCount < 4) return; + if (!fearState.finaleTriggered) return; const creature = meshRef.current; if (!creature) return; @@ -88,7 +87,7 @@ export default function TheCreature() { return ( = 4} + visible={finaleTriggered} > - {currentLoop >= 4 && ( + {finaleTriggered && (