'use client';
import type { FloorState, EnemyState, RoomType } from '@/lib/game/types';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { Progress } from '@/components/ui/progress';
import { getSpireRoomTypeDisplay } from '@/lib/game/utils/spire-utils';
import { getModifierDisplay, getModifierDescription } from '@/lib/game/utils/enemy-generator';
import { ELEMENTS } from '@/lib/game/constants';
import { fmt } from '@/lib/game/stores';
interface RoomDisplayProps {
floorState: FloorState;
floor: number;
}
function EnemyRow({ enemy, floor }: { enemy: EnemyState; floor: number }) {
const elemDef = ELEMENTS[enemy.element];
const hpPercent = enemy.maxHP > 0 ? (enemy.hp / enemy.maxHP) * 100 : 0;
const barrierVal = enemy.barrier ?? 0;
const hasBarrier = barrierVal > 0;
const barrierPercent = hasBarrier ? barrierVal * 100 : 0;
return (
{elemDef && (
{elemDef.sym}
)}
{enemy.name}
{fmt(enemy.hp)} / {fmt(enemy.maxHP)}
{/* HP bar */}
{/* Enemy stats */}
{enemy.armor > 0 && (
⛰️ {Math.round(enemy.armor * 100)}% armor
)}
{enemy.dodgeChance > 0 && (
💨 {Math.round(enemy.dodgeChance * 100)}% dodge
)}
{hasBarrier && (
🛡️ Barrier
)}
);
}
export function RoomDisplay({ floorState, floor }: RoomDisplayProps) {
// Guard against null/undefined/stale floorState
if (!floorState || !floorState.roomType) {
return (
Loading room...
);
}
const roomDisplay = getSpireRoomTypeDisplay(floorState.roomType as RoomType);
// Handle special room types (cast to string for extended types)
const rt = floorState.roomType as string;
if (rt === 'recovery') {
const progress = floorState.recoveryProgress || 0;
const required = floorState.recoveryRequired || 1;
return (
💚 Recovery Room
Rest and recover. Spend 1 hour to gain 5x mana regen & conversion rates.
);
}
if (rt === 'library') {
return (
📚 Ancient Library
Study a random discipline at 10x XP speed (no mana cost). Spend 1 hour to gain knowledge.
);
}
if (rt === 'treasure') {
return (
💎 Treasure Room
A hidden cache of resources awaits. Claim your reward!
);
}
if (floorState.roomType === 'puzzle') {
const puzzleId = floorState.puzzleId || 'unknown';
const progress = floorState.puzzleProgress || 0;
const required = floorState.puzzleRequired || 1;
return (
🧩 Puzzle Room — {puzzleId.replace(/_/g, ' ')}
Solve the puzzle. Higher attunement levels speed up progress.
Progress: {Math.round(progress * 100)} / {Math.round(required * 100)}
);
}
// Combat rooms (combat, swarm, speed, guardian)
const enemies = floorState.enemies || [];
const isGuardian = floorState.roomType === 'guardian';
return (
{roomDisplay.icon} {roomDisplay.label}
{isGuardian && BOSS}
{enemies.length === 0 ? (
Room cleared!
) : (
enemies.map((enemy) => (
))
)}
);
}