/* 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 (
{/* Background */}
= 1 ? 1 : 0, background: 'radial-gradient(ellipse at center, rgba(100, 20, 20, 0.95) 0%, rgba(0, 0, 0, 0.98) 100%)', }} /> {/* Content */}
= 1 ? 1 : 0, transform: animationStep >= 1 ? 'scale(1)' : 'scale(0.9)', }} >
{/* Icon */}
= 1 ? 1 : 0, transform: animationStep >= 1 ? 'scale(1)' : 'scale(0.5)', }} >
💀
{/* Title */}
= 2 ? 1 : 0, transform: animationStep >= 2 ? 'translateY(0)' : 'translateY(10px)', }} >

Ship Sunk!

Your vessel has been destroyed

{/* Divider */}
= 2 ? 0.3 : 0, background: 'linear-gradient(90deg, transparent, white, transparent)', }} /> {/* Message */}
= 2 ? 1 : 0, transform: animationStep >= 2 ? 'translateY(0)' : 'translateY(10px)', }} >

Your ship was sunk by enemy fire. All your upgrades and discoveries are safe. Ready to try again?

{/* Button */}
= 3 ? 1 : 0, transform: animationStep >= 3 ? 'translateY(0)' : 'translateY(10px)', }} >
) }