/* eslint-disable react-hooks/set-state-in-effect -- game animation state sync */ import { useSelector } from '@tanstack/react-store' import { useEffect, useState } from 'react' import { gameStore } from '../hooks/useGameStore' export function GameOverOverlay() { const phase = useSelector(gameStore, (s) => s.phase) const { restartBattle, addDeath } = gameStore.actions const [animationStep, setAnimationStep] = useState(0) const [deathCounted, setDeathCounted] = useState(false) useEffect(() => { if (phase !== 'gameover') { setAnimationStep(0) setDeathCounted(false) return } // Count the death once when game over starts if (!deathCounted) { addDeath() setDeathCounted(true) } const timers = [ setTimeout(() => setAnimationStep(1), 300), setTimeout(() => setAnimationStep(2), 800), setTimeout(() => setAnimationStep(3), 1300), ] return () => timers.forEach(clearTimeout) }, [phase, deathCounted, addDeath]) if (phase !== 'gameover') return null return (
Your vessel has been destroyed
Your ship was sunk by enemy fire. All your upgrades and discoveries are safe. Ready to try again?