fix: unify guardian system references across pact-utils, SpireSummaryTab, PactDebug, and PactDebugSection

- pact-utils.ts: Replace GUARDIANS[floor] with getGuardianForFloor() so pact multipliers work for extended guardians (floors 110+)
- SpireSummaryTab.tsx: Use getGuardianForFloor()/getAllGuardianFloors() instead of static GUARDIANS constant; update type annotations to GuardianDef
- PactDebug.tsx: Use unified guardian lookup; add null guards for getGuardianForFloor return type
- PactDebugSection.tsx: Use unified guardian lookup; add null guards for getGuardianForFloor return type
This commit is contained in:
2026-05-23 14:53:12 +02:00
parent feca7549ad
commit d7b822d965
6 changed files with 39 additions and 31 deletions
+16 -13
View File
@@ -3,7 +3,9 @@
import { useState, useEffect, useMemo } from 'react';
import { useShallow } from 'zustand/react/shallow';
import { useCombatStore, usePrestigeStore, fmt } from '@/lib/game/stores';
import { GUARDIANS, ELEMENT_OPPOSITES, FLOOR_ELEM_CYCLE } from '@/lib/game/constants';
import { ELEMENT_OPPOSITES, FLOOR_ELEM_CYCLE } from '@/lib/game/constants';
import { getGuardianForFloor, getAllGuardianFloors } from '@/lib/game/data/guardian-encounters';
import type { GuardianDef } from '@/lib/game/types';
import { Card, CardContent } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
@@ -14,9 +16,7 @@ import { Mountain } from 'lucide-react';
// ─── Guardian Data ────────────────────────────────────────────────────────────
const GUARDIAN_FLOORS = Object.keys(GUARDIANS)
.map(Number)
.sort((a, b) => a - b);
const GUARDIAN_FLOORS = getAllGuardianFloors();
// ─── Helper: Get Counter Element ─────────────────────────────────────────────
@@ -56,7 +56,7 @@ function FloorProgressBar({ maxFloor, clearedFloors }: { maxFloor: number; clear
<div key={row[0]} className="flex gap-1">
{row.map((floor) => {
const isCleared = clearedSet.has(floor);
const isGuardian = !!GUARDIANS[floor];
const isGuardian = !!getGuardianForFloor(floor);
const isCurrent = floor === maxFloor;
let bgClass = 'bg-gray-800';
@@ -76,8 +76,8 @@ function FloorProgressBar({ maxFloor, clearedFloors }: { maxFloor: number; clear
isGuardian ? 'font-bold' : ''
}`}
title={
GUARDIANS[floor]
? `Floor ${floor}${GUARDIANS[floor].name} (${GUARDIANS[floor].element})`
getGuardianForFloor(floor)
? `Floor ${floor}${getGuardianForFloor(floor)!.name} (${getGuardianForFloor(floor)!.element})`
: `Floor ${floor}${isCleared ? ' (cleared)' : ''}`
}
>
@@ -148,7 +148,7 @@ function StatCell({ value, label, color }: { value: number | string; label: stri
// ─── Next Guardian Card ──────────────────────────────────────────────────────
function NextGuardianCard({ nextGuardian, nextGuardianData }: { nextGuardian: number; nextGuardianData: (typeof GUARDIANS)[number] }) {
function NextGuardianCard({ nextGuardian, nextGuardianData }: { nextGuardian: number; nextGuardianData: GuardianDef }) {
const counterElement = getCounterElement(nextGuardianData.element);
const nextFloorElement = FLOOR_ELEM_CYCLE[(nextGuardian - 1) % FLOOR_ELEM_CYCLE.length];
@@ -244,16 +244,19 @@ function GuardianRoster({ clearedFloors }: { clearedFloors: Record<number, boole
<SectionHeader title="🏛️ Guardian Roster" />
<CardContent className="pt-0">
<div className="space-y-2">
{GUARDIAN_FLOORS.map((floor) => (
<GuardianRosterItem key={floor} floor={floor} guardian={GUARDIANS[floor]} isDefeated={!!clearedFloors[floor]} />
))}
{GUARDIAN_FLOORS.map((floor) => {
const guardian = getGuardianForFloor(floor);
return guardian ? (
<GuardianRosterItem key={floor} floor={floor} guardian={guardian} isDefeated={!!clearedFloors[floor]} />
) : null;
})}
</div>
</CardContent>
</Card>
);
}
function GuardianRosterItem({ floor, guardian, isDefeated }: { floor: number; guardian: (typeof GUARDIANS)[number]; isDefeated: boolean }) {
function GuardianRosterItem({ floor, guardian, isDefeated }: { floor: number; guardian: GuardianDef; isDefeated: boolean }) {
return (
<div
className={`flex items-center justify-between p-2 rounded border ${
@@ -338,7 +341,7 @@ export function SpireSummaryTab() {
return GUARDIAN_FLOORS.find((floor) => !clearedFloors[floor]) || null;
}, [clearedFloors]);
const nextGuardianData = nextGuardian ? GUARDIANS[nextGuardian] : null;
const nextGuardianData = nextGuardian ? getGuardianForFloor(nextGuardian) : null;
const totalFloorsCleared = useMemo(() => {
return Object.values(clearedFloors).filter(Boolean).length;