refactor: remove GUARDIANS constant, consolidate into guardian-data.ts
- Delete src/lib/game/constants/guardians.ts (the old static GUARDIANS constant) - Create src/lib/game/data/guardian-data.ts with BASE_GUARDIANS (same data, new home) - Remove GUARDIANS export from constants/index.ts - Update all 11 files that imported GUARDIANS to use getGuardianForFloor() or BASE_GUARDIANS: - useGameDerived.ts, combat-actions.ts, gameStore.ts, prestigeStore.ts - combat-utils.ts, room-utils.ts, floor-utils.ts, spire-utils.ts - SpireCombatPage.tsx, SpireHeader.tsx - Update 4 test files to use getGuardianForFloor() instead of GUARDIANS constant - guardian-encounters.ts now imports BASE_GUARDIANS from guardian-data.ts - Split room-utils.test.ts (505 lines) into room-utils.test.ts + room-utils-floor-state.test.ts
This commit is contained in:
@@ -29,8 +29,9 @@ describe('Tab barrel export', () => {
|
||||
|
||||
describe('Guardian data', () => {
|
||||
it('all guardians have required fields', async () => {
|
||||
const { GUARDIANS } = await import('@/lib/game/constants/guardians');
|
||||
for (const [floor, def] of Object.entries(GUARDIANS)) {
|
||||
const { getGuardianForFloor } = await import('@/lib/game/data/guardian-encounters');
|
||||
for (const floor of [10, 20, 30, 40, 50, 60, 80, 90, 100]) {
|
||||
const def = getGuardianForFloor(floor)!;
|
||||
expect(def.name).toBeTruthy();
|
||||
expect(def.element).toBeTruthy();
|
||||
expect(def.hp).toBeGreaterThan(0);
|
||||
@@ -49,10 +50,10 @@ describe('Guardian data', () => {
|
||||
});
|
||||
|
||||
it('guardians are defined at expected floors', async () => {
|
||||
const { GUARDIANS } = await import('@/lib/game/constants/guardians');
|
||||
const { getGuardianForFloor } = await import('@/lib/game/data/guardian-encounters');
|
||||
const expectedFloors = [10, 20, 30, 40, 50, 60, 80, 90, 100];
|
||||
for (const floor of expectedFloors) {
|
||||
expect(GUARDIANS[floor]).toBeDefined();
|
||||
expect(getGuardianForFloor(floor)).not.toBeNull();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -62,8 +63,9 @@ describe('Guardian data', () => {
|
||||
'critChance', 'critDamage', 'spellEfficiency', 'manaGain', 'insightGain',
|
||||
'studySpeed', 'prestigeInsight',
|
||||
];
|
||||
const { GUARDIANS } = await import('@/lib/game/constants/guardians');
|
||||
for (const def of Object.values(GUARDIANS)) {
|
||||
const { getGuardianForFloor } = await import('@/lib/game/data/guardian-encounters');
|
||||
for (const floor of [10, 20, 30, 40, 50, 60, 80, 90, 100]) {
|
||||
const def = getGuardianForFloor(floor)!;
|
||||
for (const boon of def.boons) {
|
||||
expect(validBoonTypes).toContain(boon.type);
|
||||
expect(boon.value).toBeGreaterThan(0);
|
||||
|
||||
@@ -6,8 +6,7 @@ import { useCombatStore, useManaStore, usePrestigeStore, fmt, computeMaxMana, co
|
||||
import { computeDisciplineEffects } from '@/lib/game/effects/discipline-effects';
|
||||
import { getUnifiedEffects } from '@/lib/game/effects';
|
||||
import { useCraftingStore } from '@/lib/game/stores/craftingStore';
|
||||
import { GUARDIANS } from '@/lib/game/constants';
|
||||
import { getExtendedGuardian, isGuardianFloor } from '@/lib/game/data/guardian-encounters';
|
||||
import { getGuardianForFloor, isGuardianFloor } from '@/lib/game/data/guardian-encounters';
|
||||
import { getRoomsForFloor, generateSpireFloorState } from '@/lib/game/utils/spire-utils';
|
||||
import { SpireHeader } from './SpireHeader';
|
||||
import { RoomDisplay } from './RoomDisplay';
|
||||
@@ -122,7 +121,7 @@ export function SpireCombatPage() {
|
||||
setClearedFloor(currentFloor, true);
|
||||
|
||||
if (wasGuardian) {
|
||||
const guardian = GUARDIANS[currentFloor] || getExtendedGuardian(currentFloor);
|
||||
const guardian = getGuardianForFloor(currentFloor);
|
||||
if (guardian) {
|
||||
addActivityLog('enemy_defeated', `⚔️ ${guardian.name} defeated!`, {
|
||||
enemyName: guardian.name,
|
||||
|
||||
@@ -5,8 +5,7 @@ import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent } from '@/components/ui/card';
|
||||
import { Progress } from '@/components/ui/progress';
|
||||
import { Mountain, ArrowUp, ArrowDown, LogOut } from 'lucide-react';
|
||||
import { GUARDIANS } from '@/lib/game/constants';
|
||||
import { isGuardianFloor, getExtendedGuardian } from '@/lib/game/data/guardian-encounters';
|
||||
import { getGuardianForFloor, isGuardianFloor } from '@/lib/game/data/guardian-encounters';
|
||||
|
||||
interface SpireHeaderProps {
|
||||
currentFloor: number;
|
||||
@@ -34,7 +33,7 @@ export function SpireHeader({
|
||||
const maxFloorReached = useCombatStore((s) => s.maxFloorReached);
|
||||
const { insight } = usePrestigeStore((s) => ({ insight: s.insight }));
|
||||
|
||||
const guardian = GUARDIANS[currentFloor] || getExtendedGuardian(currentFloor);
|
||||
const guardian = getGuardianForFloor(currentFloor);
|
||||
const isGuardian = isGuardianFloor(currentFloor);
|
||||
const hpPercent = floorMaxHP > 0 ? (floorHP / floorMaxHP) * 100 : 100;
|
||||
const roomProgress = totalRooms > 0 ? ((roomsCleared) / totalRooms) * 100 : 0;
|
||||
|
||||
@@ -27,23 +27,26 @@ describe('Tab barrel export', () => {
|
||||
|
||||
// ─── Test: Guardian data ───────────────────────────────────────────────────────
|
||||
|
||||
describe('Guardian constants', () => {
|
||||
it('has 9 guardians defined', async () => {
|
||||
const { GUARDIANS } = await import('@/lib/game/constants');
|
||||
expect(Object.keys(GUARDIANS).length).toBe(9);
|
||||
describe('Guardian data', () => {
|
||||
it('has 9 static guardians plus extended guardians', async () => {
|
||||
const { getAllGuardianFloors } = await import('@/lib/game/data/guardian-encounters');
|
||||
const floors = getAllGuardianFloors();
|
||||
// 9 static + compound (110) + exotic (120,130,140) + combo (150-240) = 23 total
|
||||
expect(floors.length).toBeGreaterThanOrEqual(9);
|
||||
});
|
||||
|
||||
it('guardians are at expected floors', async () => {
|
||||
const { GUARDIANS } = await import('@/lib/game/constants');
|
||||
it('guardians are at expected base floors', async () => {
|
||||
const { getGuardianForFloor } = await import('@/lib/game/data/guardian-encounters');
|
||||
const expectedFloors = [10, 20, 30, 40, 50, 60, 80, 90, 100];
|
||||
for (const floor of expectedFloors) {
|
||||
expect(GUARDIANS[floor]).toBeDefined();
|
||||
expect(getGuardianForFloor(floor)).not.toBeNull();
|
||||
}
|
||||
});
|
||||
|
||||
it('all guardians have required fields', async () => {
|
||||
const { GUARDIANS } = await import('@/lib/game/constants');
|
||||
for (const [, def] of Object.entries(GUARDIANS)) {
|
||||
it('all base guardians have required fields', async () => {
|
||||
const { getGuardianForFloor } = await import('@/lib/game/data/guardian-encounters');
|
||||
for (const floor of [10, 20, 30, 40, 50, 60, 80, 90, 100]) {
|
||||
const def = getGuardianForFloor(floor)!;
|
||||
expect(def.name).toBeTruthy();
|
||||
expect(def.element).toBeTruthy();
|
||||
expect(def.hp).toBeGreaterThan(0);
|
||||
@@ -53,9 +56,9 @@ describe('Guardian constants', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('all guardians have unique elements', async () => {
|
||||
const { GUARDIANS } = await import('@/lib/game/constants');
|
||||
const elements = Object.values(GUARDIANS).map((g) => g.element);
|
||||
it('all base guardians have unique elements', async () => {
|
||||
const { getGuardianForFloor } = await import('@/lib/game/data/guardian-encounters');
|
||||
const elements = [10, 20, 30, 40, 50, 60, 80, 90, 100].map((f) => getGuardianForFloor(f)!.element);
|
||||
const uniqueElements = new Set(elements);
|
||||
expect(uniqueElements.size).toBe(elements.length);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user