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:
@@ -4,7 +4,8 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Bug } from 'lucide-react';
|
||||
import { usePrestigeStore, useManaStore, useUIStore, useGameStore } from '@/lib/game/stores';
|
||||
import { GUARDIANS, ELEMENTS } from '@/lib/game/constants';
|
||||
import { ELEMENTS } from '@/lib/game/constants';
|
||||
import { getGuardianForFloor, getAllGuardianFloors } from '@/lib/game/data/guardian-encounters';
|
||||
|
||||
// ─── Guardian Pact Row ───────────────────────────────────────────────────────
|
||||
|
||||
@@ -14,7 +15,8 @@ function GuardianPactRow({ floor, isSigned, onForceSign, onRemove }: {
|
||||
onForceSign: () => void;
|
||||
onRemove: () => void;
|
||||
}) {
|
||||
const guardian = GUARDIANS[floor];
|
||||
const guardian = getGuardianForFloor(floor);
|
||||
if (!guardian) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -56,7 +58,7 @@ function GuardianPactList({ signedPacts, onForceSign, onRemove }: {
|
||||
onForceSign: (floor: number) => void;
|
||||
onRemove: (floor: number) => void;
|
||||
}) {
|
||||
const guardianFloors = Object.keys(GUARDIANS || {}).map(Number).sort((a, b) => a - b);
|
||||
const guardianFloors = getAllGuardianFloors();
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-2">
|
||||
@@ -90,11 +92,11 @@ export function PactDebug() {
|
||||
const addLog = useUIStore((s) => s.addLog);
|
||||
|
||||
const forcePact = (floor: number) => {
|
||||
const guardian = GUARDIANS[floor];
|
||||
const guardian = getGuardianForFloor(floor);
|
||||
if (!guardian) return;
|
||||
|
||||
if (signedPacts.includes(floor)) {
|
||||
addLog(`⚠️ Already signed pact with ${guardian.name}!`);
|
||||
addLog(`\u26a0\ufe0f Already signed pact with ${guardian.name}!`);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -121,7 +123,7 @@ export function PactDebug() {
|
||||
};
|
||||
|
||||
const removePactHandler = (floor: number) => {
|
||||
const guardian = GUARDIANS[floor];
|
||||
const guardian = getGuardianForFloor(floor);
|
||||
|
||||
removePact(floor);
|
||||
|
||||
@@ -129,7 +131,7 @@ export function PactDebug() {
|
||||
delete newSignedPactDetails[floor];
|
||||
debugSetPactDetails(newSignedPactDetails);
|
||||
|
||||
addLog(`📜 DEBUG: Removed pact with ${guardian?.name || 'Unknown'}!`);
|
||||
addLog(`\ud83d\udcdc DEBUG: Removed pact with ${guardian ? guardian.name : 'Unknown'}!`);
|
||||
};
|
||||
|
||||
const clearAllPacts = () => {
|
||||
|
||||
@@ -4,7 +4,8 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Bug } from 'lucide-react';
|
||||
import { usePrestigeStore, useManaStore, useUIStore, useGameStore } from '@/lib/game/stores';
|
||||
import { GUARDIANS, ELEMENTS } from '@/lib/game/constants';
|
||||
import { ELEMENTS } from '@/lib/game/constants';
|
||||
import { getGuardianForFloor, getAllGuardianFloors } from '@/lib/game/data/guardian-encounters';
|
||||
|
||||
// ─── Guardian Pact Row ───────────────────────────────────────────────────────
|
||||
|
||||
@@ -14,7 +15,8 @@ function GuardianPactRow({ floor, isSigned, onForceSign, onRemove }: {
|
||||
onForceSign: () => void;
|
||||
onRemove: () => void;
|
||||
}) {
|
||||
const guardian = GUARDIANS[floor];
|
||||
const guardian = getGuardianForFloor(floor);
|
||||
if (!guardian) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -65,10 +67,10 @@ export function PactDebugSection() {
|
||||
|
||||
const addLog = useUIStore((s) => s.addLog);
|
||||
|
||||
const guardianFloors = Object.keys(GUARDIANS || {}).map(Number).sort((a, b) => a - b);
|
||||
const guardianFloors = getAllGuardianFloors();
|
||||
|
||||
const forcePact = (floor: number) => {
|
||||
const guardian = GUARDIANS[floor];
|
||||
const guardian = getGuardianForFloor(floor);
|
||||
if (!guardian) return;
|
||||
|
||||
if (signedPacts.includes(floor)) {
|
||||
@@ -99,7 +101,7 @@ export function PactDebugSection() {
|
||||
};
|
||||
|
||||
const removePactHandler = (floor: number) => {
|
||||
const guardian = GUARDIANS[floor];
|
||||
const guardian = getGuardianForFloor(floor);
|
||||
|
||||
removePact(floor);
|
||||
|
||||
@@ -107,7 +109,7 @@ export function PactDebugSection() {
|
||||
delete newSignedPactDetails[floor];
|
||||
debugSetPactDetails(newSignedPactDetails);
|
||||
|
||||
addLog(`📜 DEBUG: Removed pact with ${guardian?.name || 'Unknown'}!`);
|
||||
addLog(`\ud83d\udcdc DEBUG: Removed pact with ${guardian ? guardian.name : 'Unknown'}!`);
|
||||
};
|
||||
|
||||
const signAllPacts = () => {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user