fix: resolve all Priority 5 CRASH/BLOCKER issues (#51-#57)
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m19s

- #51: Fix broken import path @/types/disciplines → @/lib/game/types/disciplines
- #52: Fix canProceedDiscipline() called with wrong arguments in discipline-slice.ts
- #53: Add local useState for activeAttunement tab filtering in DisciplinesTab
- #54: Make canProceedDiscipline() defensive when gameState is undefined
- #57: Remove stale CraftingTab export from game/index.ts
- Refactored DisciplineCard to use Zustand selector subscriptions properly
- Added DisciplinePerk type import to discipline-math.ts
This commit is contained in:
2026-05-18 17:51:06 +02:00
parent 92238e4dd8
commit ff3a268358
6 changed files with 169 additions and 213 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
# Circular Dependencies # Circular Dependencies
Generated: 2026-05-18T13:07:38.493Z Generated: 2026-05-18T13:14:04.833Z
Found: 1 circular chain(s) — these MUST be fixed before modifying involved files. Found: 1 circular chain(s) — these MUST be fixed before modifying involved files.
1. Processed 123 files (1.2s) (29 warnings) 1. Processed 123 files (1.2s) (29 warnings)
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"_meta": { "_meta": {
"generated": "2026-05-18T13:07:36.959Z", "generated": "2026-05-18T13:14:03.496Z",
"description": "Import dependency graph for src/lib/game. Keys are files, values are arrays of files they import.", "description": "Import dependency graph for src/lib/game. Keys are files, values are arrays of files they import.",
"usage": "To find what a file affects, search for its path in the VALUES. To find what a file depends on, look at its KEY entry." "usage": "To find what a file affects, search for its path in the VALUES. To find what a file depends on, look at its KEY entry."
}, },
-1
View File
@@ -2,7 +2,6 @@
// Re-exports all game tab components for cleaner imports // Re-exports all game tab components for cleaner imports
// Tab components // Tab components
export { CraftingTab } from './crafting';
export { SpellsTab } from './SpellsTab'; export { SpellsTab } from './SpellsTab';
export { StatsTab } from './StatsTab'; export { StatsTab } from './StatsTab';
+53 -101
View File
@@ -1,48 +1,30 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { useDisciplineStore } from '@/lib/game/stores/discipline-slice'; import { useDisciplineStore } from '@/lib/game/stores/discipline-slice';
import type { DisciplineDefinition } from '@/types/disciplines'; import type { DisciplineDefinition } from '@/lib/game/types/disciplines';
import { baseDisciplines } from '@/lib/game/data/disciplines/base'; import { baseDisciplines } from '@/lib/game/data/disciplines/base';
import { enchanterDisciplines } from '@/lib/game/data/disciplines/enchanter'; import { enchanterDisciplines } from '@/lib/game/data/disciplines/enchanter';
import { fabricatorDisciplines } from '@/lib/game/data/disciplines/fabricator'; import { fabricatorDisciplines } from '@/lib/game/data/disciplines/fabricator';
import { invokerDisciplines } from '@/lib/game/data/disciplines/invoker'; import { invokerDisciplines } from '@/lib/game/data/disciplines/invoker';
import { calculateStatBonus, calculateManaDrain } from '@/lib/game/utils/discipline-math'; import { calculateStatBonus, calculateManaDrain } from '@/lib/game/utils/discipline-math';
import { useRef } from 'react';
import clsx from 'clsx'; import clsx from 'clsx';
export const DisciplinesTab: React.FC = () => { interface AttunementTab {
const store = useDisciplineStore(); key: string;
const { disciplines, activeIds, concurrentLimit } = store;
const [mounted, setMounted] = useState(false);
useEffect(() => {
setMounted(true);
}, []);
const allDisciplines: DisciplineDefinition[] = [
...baseDisciplines,
...enchanterDisciplines,
...fabricatorDisciplines,
...invokerDisciplines,
];
// Group disciplines by attunement for tab rendering
const attunementTabs: {
label: string; label: string;
items: DisciplineDefinition[]; items: DisciplineDefinition[];
}[] = [ }
{ label: 'Base', items: baseDisciplines },
{ label: 'Enchanter', items: enchanterDisciplines }, const ATTUNEMENT_TABS: AttunementTab[] = [
{ label: 'Fabricator', items: fabricatorDisciplines }, { key: 'base', label: 'Base', items: baseDisciplines },
{ label: 'Invoker', items: invokerDisciplines }, { key: 'enchanter', label: 'Enchanter', items: enchanterDisciplines },
{ key: 'fabricator', label: 'Fabricator', items: fabricatorDisciplines },
{ key: 'invoker', label: 'Invoker', items: invokerDisciplines },
]; ];
// Helper to render a single discipline card interface DisciplineCardProps {
const DisciplineCard: React.FC<{
id: string; id: string;
name: string; name: string;
description: string; description: string;
xp: number;
perkThresholds?: number[]; perkThresholds?: number[];
perkValues?: number[]; perkValues?: number[];
perkTypes?: string[]; perkTypes?: string[];
@@ -51,11 +33,12 @@ export const DisciplinesTab: React.FC = () => {
drainBase: number; drainBase: number;
difficultyFactor: number; difficultyFactor: number;
scalingFactor: number; scalingFactor: number;
}> = ({ }
const DisciplineCard: React.FC<DisciplineCardProps> = ({
id, id,
name, name,
description, description,
xp,
perkThresholds, perkThresholds,
perkValues, perkValues,
perkTypes, perkTypes,
@@ -65,55 +48,35 @@ export const DisciplinesTab: React.FC = () => {
difficultyFactor, difficultyFactor,
scalingFactor, scalingFactor,
}) => { }) => {
if (!mounted) return null; const activeIds = useDisciplineStore((s) => s.activeIds);
const concurrentLimit = useDisciplineStore((s) => s.concurrentLimit);
const currentDisc = useDisciplineStore((s) => s.disciplines[id] ?? { xp: 0, paused: true });
const state = useDisciplineStore().getState();
const currentDisc = state.disciplines[id] ?? { xp: 0, paused: true };
const isActive = activeIds.includes(id);
const canActivate = concurrentLimit > activeIds.filter(a => state.disciplines[a]?.paused !== true).length;
// Calculate displayed stats
const displayXp = currentDisc.xp; const displayXp = currentDisc.xp;
const progressPercent = Math.min(displayXp / Math.max(1, (concurrentLimit * 100) ?? 1), 100); const progressPercent = Math.min(displayXp / Math.max(1, concurrentLimit * 100), 100);
const isPaused = currentDisc.paused; const isPaused = currentDisc.paused;
const hasPendingPerk = perkThresholds?.some((t, i) => displayXp >= t && perkTypes?.[i] !== 'capped');
const activeStatBonus = calculateStatBonus( const activeStatBonus = calculateStatBonus(baseValue, displayXp, scalingFactor);
parseInt(baseValue) || 0, const estimatedDrain = calculateManaDrain(drainBase, displayXp, difficultyFactor);
displayXp,
scalingFactor
);
// Simple visual for drain per tick
const estimatedDrain = calculateManaDrain(
drainBase,
displayXp,
difficultyFactor
);
// Determine unlocked perks
const unlockedPerks = perkTypes?.reduce<string[]>((acc, typ, idx) => { const unlockedPerks = perkTypes?.reduce<string[]>((acc, typ, idx) => {
const threshold = perkThresholds?.[idx];
if (threshold === undefined) return acc;
if (typ === 'once' || typ === 'infinite') { if (typ === 'once' || typ === 'infinite') {
if (displayXp >= perkThresholds?.[idx] ?? 0) { if (displayXp >= threshold) acc.push(`${typ}-${idx}`);
acc.push(`${typ}-${idx}`);
}
} else if (typ === 'capped') { } else if (typ === 'capped') {
const tier = Math.max(0, Math.floor((displayXp - perkThresholds?.[idx] ?? 0) / perkValues?.[idx] ?? 1) + 1); const interval = perkValues?.[idx] ?? 1;
const tier = Math.max(0, Math.floor((displayXp - threshold) / interval) + 1);
if (tier > 0) acc.push(`${typ}-${idx}`); if (tier > 0) acc.push(`${typ}-${idx}`);
} }
return acc; return acc;
}, []); }, []);
// Helper to decide button action
const toggleAction = () => { const toggleAction = () => {
if (isPaused) { if (isPaused) {
// Resume activate useDisciplineStore.getState().activate(id);
const storeDispatch = useDisciplineStore().getState().activate as any;
storeDispatch(id);
} else { } else {
// Pause deactivate useDisciplineStore.getState().deactivate(id);
const storeDispatch = useDisciplineStore().getState().deactivate as any;
storeDispatch(id);
} }
}; };
@@ -126,25 +89,21 @@ export const DisciplinesTab: React.FC = () => {
<span className="text-xs font-mono whitespace-nowrap">{Math.round(progressPercent)}%</span> <span className="text-xs font-mono whitespace-nowrap">{Math.round(progressPercent)}%</span>
<div className="flex-1 bg-gray-200 rounded-full overflow-hidden h-3"> <div className="flex-1 bg-gray-200 rounded-full overflow-hidden h-3">
<div <div
className={`bg-blue-500 transition-all duration-300 ${ className={`transition-all duration-300 ${activeStatBonus > 0 ? 'bg-green-500' : 'bg-red-500'}`}
activeStatBonus > 0 ? 'bg-green-500' : 'bg-red-500' style={{ width: `${Math.round(progressPercent)}%` }}
}`}
style={{ width: `${progressPercent}%` }}
/> />
</div> </div>
</div> </div>
<div className="text-sm text-gray-400"> <div className="text-sm text-gray-400">
<strong>Drain:</strong> {estimatedDrain.toFixed(1)}{' '} <strong>Drain:</strong> {estimatedDrain.toFixed(1)} {' '}
<strong>XP:</strong> {displayXp} <strong>XP:</strong> {displayXp}
</div> </div>
{/* Bonus display */}
<div className="mt-2 text-sm"> <div className="mt-2 text-sm">
<strong>Stat Bonus:</strong> {activeStatBonus.toFixed(2)} on {statBonus} <strong>Stat Bonus:</strong> {activeStatBonus.toFixed(2)} on {statBonus}
</div> </div>
{/* Perks */}
<div className="mt-2"> <div className="mt-2">
<strong>Perks:</strong> <strong>Perks:</strong>
<ul className="mt-1 list-disc list-inside space-y-1 text-xs"> <ul className="mt-1 list-disc list-inside space-y-1 text-xs">
@@ -158,7 +117,6 @@ export const DisciplinesTab: React.FC = () => {
</ul> </ul>
</div> </div>
{/* Action button */}
<div className="mt-4 flex justify-end"> <div className="mt-4 flex justify-end">
<button <button
onClick={toggleAction} onClick={toggleAction}
@@ -176,6 +134,16 @@ export const DisciplinesTab: React.FC = () => {
); );
}; };
export const DisciplinesTab: React.FC = () => {
const { activeIds, concurrentLimit } = useDisciplineStore();
const [mounted, setMounted] = useState(false);
const [activeAttunement, setActiveAttunement] = useState<string>('base');
useEffect(() => {
setMounted(true);
}, []);
if (!mounted) { if (!mounted) {
return ( return (
<div className="flex items-center justify-center p-8 text-gray-500"> <div className="flex items-center justify-center p-8 text-gray-500">
@@ -184,25 +152,21 @@ export const DisciplinesTab: React.FC = () => {
); );
} }
const activeTab = ATTUNEMENT_TABS.find((t) => t.key === activeAttunement);
return ( return (
<div className="mt-6"> <div className="mt-6">
{/* Tab bar */} {/* Tab bar */}
<div className="flex gap-2 mb-4"> <div className="flex gap-2 mb-4">
{attunementTabs.map((tab) => { {ATTUNEMENT_TABS.map((tab) => {
const isActiveTab = store const isActiveTab = activeAttunement === tab.key;
.getState()
.activeAttunement === tab.label.toLowerCase();
return ( return (
<button <button
key={tab.label} key={tab.key}
onClick={() => { onClick={() => setActiveAttunement(tab.key)}
// Here you could dispatch an action to switch tabs if needed
// For simplicity, we just render the tabs
console.log(`Switch to ${tab.label}`);
}}
className={clsx('rounded px-3 py-1', { className={clsx('rounded px-3 py-1', {
'bg-blue-600 text-white': tab.label === 'Base', // highlight first for demo 'bg-blue-600 text-white': isActiveTab,
'text-gray-600': tab.label !== 'Base', 'text-gray-600': !isActiveTab,
})} })}
> >
{tab.label} {tab.label}
@@ -211,36 +175,24 @@ export const DisciplinesTab: React.FC = () => {
})} })}
</div> </div>
{/* Discipline cards */} {/* Discipline cards — only render active tab */}
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4"> <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
{attunementTabs {activeTab?.items.map((disc) => (
.map((tab) =>
tab.items.map((disc) => {
const state = useDisciplineStore().getState();
const discState = state.disciplines[disc.id] ?? { xp: 0, paused: true };
const isActive = activeIds.includes(disc.id);
const isVisible = attunementTabs.find((t) => t.label === tab.label)?.items === tab.items;
return isVisible && (
<DisciplineCard <DisciplineCard
key={disc.id} key={disc.id}
id={disc.id} id={disc.id}
name={disc.name} name={disc.name}
description={disc.description} description={disc.description}
xp={discState.xp}
perkThresholds={disc.perks?.map((p) => p.threshold)} perkThresholds={disc.perks?.map((p) => p.threshold)}
perkValues={disc.perks?.map((p) => p.value)} perkValues={disc.perks?.map((p) => p.value)}
perkTypes={disc.perks?.map((p) => p.type)} perkTypes={disc.perks?.map((p) => p.type)}
statBonus={disc.statBonus} statBonus={disc.statBonus.stat}
baseValue={disc.statBonus.baseValue?.toString() ?? '0'} baseValue={disc.statBonus.baseValue}
drainBase={disc.drainBase} drainBase={disc.drainBase}
difficultyFactor={disc.difficultyFactor} difficultyFactor={disc.difficultyFactor}
scalingFactor={disc.scalingFactor} scalingFactor={disc.scalingFactor}
/> />
); ))}
})
)
.flat()
}
</div> </div>
{/* Summary info */} {/* Summary info */}
+2 -1
View File
@@ -58,7 +58,8 @@ export const useDisciplineStore = create<DisciplineStore>()(
return d && !d.paused; return d && !d.paused;
}).length; }).length;
if (nonPaused >= s.concurrentLimit) return s; if (nonPaused >= s.concurrentLimit) return s;
if (!canProceedDiscipline(id, gameState)) return s; const discState = s.disciplines[id];
if (!canProceedDiscipline(def, discState, gameState)) return s;
const existing = s.disciplines[id] || { id, xp: 0, paused: false }; const existing = s.disciplines[id] || { id, xp: 0, paused: false };
return { return {
+7 -3
View File
@@ -1,7 +1,7 @@
// ─── Discipline Math Utilities ──────────────────────────────────────────────── // ─── Discipline Math Utilities ────────────────────────────────────────────────
// Continuous scaling formulas for Active Disciplines // Continuous scaling formulas for Active Disciplines
import type { DisciplineState, DisciplineDefinition } from '../types/disciplines'; import type { DisciplineState, DisciplineDefinition, DisciplinePerk } from '../types/disciplines';
/** /**
* Calculate continuous stat bonus from discipline XP * Calculate continuous stat bonus from discipline XP
@@ -64,11 +64,15 @@ export function canActivateDiscipline(
*/ */
export function canProceedDiscipline( export function canProceedDiscipline(
discipline: DisciplineDefinition, discipline: DisciplineDefinition,
disciplineState: DisciplineState, disciplineState: DisciplineState | undefined,
gameState: { elements?: Record<string, any>; rawMana?: number } gameState?: { elements?: Record<string, any>; rawMana?: number }
): boolean { ): boolean {
if (!disciplineState) return true;
if (disciplineState.paused) return false; if (disciplineState.paused) return false;
// If no game state provided, allow activation (optimistic)
if (!gameState) return true;
const drain = calculateManaDrain( const drain = calculateManaDrain(
discipline.drainBase, discipline.drainBase,
disciplineState.xp, disciplineState.xp,