fix: resolve bugs #118 #119 #120 #123 and refactor craftingStore init

This commit is contained in:
2026-05-22 18:18:26 +02:00
parent ca1709006f
commit 5bc05ded6f
8 changed files with 90 additions and 46 deletions
+11
View File
@@ -191,15 +191,24 @@ Mana-Loop/
│ │ ├── __tests__/ │ │ ├── __tests__/
│ │ │ ├── store-method-tests/ │ │ │ ├── store-method-tests/
│ │ │ ├── achievements.test.ts │ │ │ ├── achievements.test.ts
│ │ │ ├── activity-log.test.ts
│ │ │ ├── bug-fixes.test.ts │ │ │ ├── bug-fixes.test.ts
│ │ │ ├── combat-utils.test.ts │ │ │ ├── combat-utils.test.ts
│ │ │ ├── computed-stats.test.ts │ │ │ ├── computed-stats.test.ts
│ │ │ ├── crafting-utils-basic.test.ts
│ │ │ ├── crafting-utils-equipment.test.ts
│ │ │ ├── crafting-utils-recipe.test.ts
│ │ │ ├── crafting-utils-time.test.ts
│ │ │ ├── discipline-math.test.ts │ │ │ ├── discipline-math.test.ts
│ │ │ ├── enemy-generator.test.ts │ │ │ ├── enemy-generator.test.ts
│ │ │ ├── enemy-utils.test.ts
│ │ │ ├── floor-utils.test.ts │ │ │ ├── floor-utils.test.ts
│ │ │ ├── floor-utils.upgraded.test.ts
│ │ │ ├── formatting.test.ts │ │ │ ├── formatting.test.ts
│ │ │ ├── mana-utils.test.ts │ │ │ ├── mana-utils.test.ts
│ │ │ ├── pact-utils.test.ts
│ │ │ ├── regression-fixes.test.ts │ │ │ ├── regression-fixes.test.ts
│ │ │ ├── room-utils.test.ts
│ │ │ ├── spire-utils.test.ts │ │ │ ├── spire-utils.test.ts
│ │ │ ├── store-actions-combat-prestige.test.ts │ │ │ ├── store-actions-combat-prestige.test.ts
│ │ │ ├── store-actions-discipline.test.ts │ │ │ ├── store-actions-discipline.test.ts
@@ -302,6 +311,7 @@ Mana-Loop/
│ │ │ ├── combat-actions.ts │ │ │ ├── combat-actions.ts
│ │ │ ├── combat-state.types.ts │ │ │ ├── combat-state.types.ts
│ │ │ ├── combatStore.ts │ │ │ ├── combatStore.ts
│ │ │ ├── crafting-initial-state.ts
│ │ │ ├── craftingStore.ts │ │ │ ├── craftingStore.ts
│ │ │ ├── craftingStore.types.ts │ │ │ ├── craftingStore.types.ts
│ │ │ ├── discipline-slice.ts │ │ │ ├── discipline-slice.ts
@@ -357,6 +367,7 @@ Mana-Loop/
├── Caddyfile ├── Caddyfile
├── Dockerfile ├── Dockerfile
├── README.md ├── README.md
├── STATS_TAB_INVESTIGATION_REPORT.md
├── bun.lock ├── bun.lock
├── bunfig.toml ├── bunfig.toml
├── components.json ├── components.json
+2 -2
View File
@@ -22,8 +22,8 @@ export function EquipmentTab() {
}, []); }, []);
const handleEquip = useCallback( const handleEquip = useCallback(
(instanceId: string, slot: EquipmentSlot) => { (instanceId: string, slot: EquipmentSlot): boolean => {
storeEquipItem(instanceId, slot); return storeEquipItem(instanceId, slot);
}, },
[storeEquipItem] [storeEquipItem]
); );
@@ -90,8 +90,8 @@ export function RoomDisplay({ floorState, floor }: RoomDisplayProps) {
const rt = floorState.roomType as string; const rt = floorState.roomType as string;
if (rt === 'recovery') { if (rt === 'recovery') {
const progress = floorState.puzzleProgress || 0; const progress = floorState.recoveryProgress || 0;
const required = floorState.puzzleRequired || 1; const required = floorState.recoveryRequired || 1;
return ( return (
<Card className="bg-gray-900/80 border-green-800/40"> <Card className="bg-gray-900/80 border-green-800/40">
<CardHeader className="pb-2"> <CardHeader className="pb-2">
+11 -13
View File
@@ -28,20 +28,18 @@ export function StatsTab() {
effectiveRegen={manaStats.effectiveRegen} effectiveRegen={manaStats.effectiveRegen}
clickMana={manaStats.clickMana} clickMana={manaStats.clickMana}
meditationMultiplier={manaStats.meditationMultiplier} meditationMultiplier={manaStats.meditationMultiplier}
upgradeEffects={{ upgradeEffects={manaStats.upgradeEffects}
...manaStats.upgradeEffects,
incursionStrength: manaStats.incursionStrength,
rawMana: manaStats.maxMana,
hasSteadyStream: manaStats.hasSteadyStream,
hasManaTorrent: manaStats.hasManaTorrent,
hasDesperateWells: manaStats.hasDesperateWells,
manaCascadeBonus: manaStats.manaCascadeBonus,
manaWaterfallBonus: manaStats.manaWaterfallBonus,
hasFlowSurge: manaStats.hasFlowSurge,
hasManaOverflow: manaStats.hasManaOverflow,
hasEternalFlow: manaStats.hasEternalFlow,
}}
elemMax={elemMax} elemMax={elemMax}
incursionStrength={manaStats.incursionStrength}
rawMana={manaStats.maxMana}
hasSteadyStream={manaStats.hasSteadyStream}
hasManaTorrent={manaStats.hasManaTorrent}
hasDesperateWells={manaStats.hasDesperateWells}
manaCascadeBonus={manaStats.manaCascadeBonus}
manaWaterfallBonus={manaStats.manaWaterfallBonus}
hasFlowSurge={manaStats.hasFlowSurge}
hasManaOverflow={manaStats.hasManaOverflow}
hasEternalFlow={manaStats.hasEternalFlow}
/> />
<CombatStatsSection <CombatStatsSection
activeSpellDef={combatStats.activeSpellDef} activeSpellDef={combatStats.activeSpellDef}
@@ -5,7 +5,15 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Droplet } from 'lucide-react'; import { Droplet } from 'lucide-react';
import type { ComputedEffects } from '@/lib/game/effects/upgrade-effects.types'; import type { ComputedEffects } from '@/lib/game/effects/upgrade-effects.types';
interface ManaStatsEffects extends ComputedEffects { interface ManaStatsSectionProps {
maxMana: number;
baseRegen: number;
effectiveRegen: number;
clickMana: number;
meditationMultiplier: number;
upgradeEffects: ComputedEffects;
elemMax: number;
// Special effect flags passed separately
incursionStrength: number; incursionStrength: number;
rawMana: number; rawMana: number;
hasSteadyStream: boolean; hasSteadyStream: boolean;
@@ -18,15 +26,7 @@ interface ManaStatsEffects extends ComputedEffects {
hasEternalFlow: boolean; hasEternalFlow: boolean;
} }
interface ManaStatsSectionProps {
maxMana: number;
baseRegen: number;
effectiveRegen: number;
clickMana: number;
meditationMultiplier: number;
upgradeEffects: ManaStatsEffects;
elemMax: number;
}
export function ManaStatsSection({ export function ManaStatsSection({
maxMana, maxMana,
@@ -36,6 +36,16 @@ export function ManaStatsSection({
meditationMultiplier, meditationMultiplier,
upgradeEffects, upgradeEffects,
elemMax, elemMax,
incursionStrength,
rawMana,
hasSteadyStream,
hasManaTorrent,
hasDesperateWells,
manaCascadeBonus,
manaWaterfallBonus,
hasFlowSurge,
hasManaOverflow,
hasEternalFlow,
}: ManaStatsSectionProps) { }: ManaStatsSectionProps) {
return ( return (
<Card className="bg-[var(--bg-panel)] border-[var(--border-subtle)]"> <Card className="bg-[var(--bg-panel)] border-[var(--border-subtle)]">
@@ -114,7 +124,7 @@ export function ManaStatsSection({
</div> </div>
<div className="flex justify-between text-sm"> <div className="flex justify-between text-sm">
<span style={{ color: 'var(--text-muted)' }}>Incursion Strength:</span> <span style={{ color: 'var(--text-muted)' }}>Incursion Strength:</span>
<span style={{ color: 'var(--color-danger)' }}>{Math.round(upgradeEffects.incursionStrength * 100)}%</span> <span style={{ color: 'var(--color-danger)' }}>{Math.round(incursionStrength * 100)}%</span>
</div> </div>
<div className="flex justify-between text-sm font-semibold border-t border-[var(--border-subtle)] pt-2"> <div className="flex justify-between text-sm font-semibold border-t border-[var(--border-subtle)] pt-2">
<span style={{ color: 'var(--text-secondary)' }}>Effective Regen:</span> <span style={{ color: 'var(--text-secondary)' }}>Effective Regen:</span>
@@ -123,55 +133,55 @@ export function ManaStatsSection({
</div> </div>
</div> </div>
{/* Special Effects */} {/* Special Effects */}
{(upgradeEffects.hasSteadyStream || upgradeEffects.hasManaTorrent || {(hasSteadyStream || hasManaTorrent ||
upgradeEffects.hasDesperateWells || upgradeEffects.manaCascadeBonus > 0 || hasDesperateWells || manaCascadeBonus > 0 ||
upgradeEffects.manaWaterfallBonus > 0) && ( manaWaterfallBonus > 0) && (
<> <>
<div className="mt-3 mb-2"><span className="text-xs text-[var(--mana-light)] game-panel-title">Special Effects</span></div> <div className="mt-3 mb-2"><span className="text-xs text-[var(--mana-light)] game-panel-title">Special Effects</span></div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-2"> <div className="grid grid-cols-1 md:grid-cols-2 gap-2">
{upgradeEffects.hasSteadyStream && ( {hasSteadyStream && (
<div className="flex justify-between text-xs bg-[var(--bg-sunken)]/50 rounded px-2 py-1"> <div className="flex justify-between text-xs bg-[var(--bg-sunken)]/50 rounded px-2 py-1">
<span style={{ color: 'var(--text-secondary)' }}>Steady Stream:</span> <span style={{ color: 'var(--text-secondary)' }}>Steady Stream:</span>
<span style={{ color: 'var(--color-success)' }}>Immune to incursion</span> <span style={{ color: 'var(--color-success)' }}>Immune to incursion</span>
</div> </div>
)} )}
{upgradeEffects.manaCascadeBonus > 0 && ( {manaCascadeBonus > 0 && (
<div className="flex justify-between text-xs bg-[var(--bg-sunken)]/50 rounded px-2 py-1"> <div className="flex justify-between text-xs bg-[var(--bg-sunken)]/50 rounded px-2 py-1">
<span style={{ color: 'var(--text-secondary)' }}>Mana Cascade:</span> <span style={{ color: 'var(--text-secondary)' }}>Mana Cascade:</span>
<span style={{ color: 'var(--mana-crystal)' }}>+{fmtDec(upgradeEffects.manaCascadeBonus, 2)}/hr</span> <span style={{ color: 'var(--mana-crystal)' }}>+{fmtDec(manaCascadeBonus, 2)}/hr</span>
</div> </div>
)} )}
{upgradeEffects.manaWaterfallBonus > 0 && ( {manaWaterfallBonus > 0 && (
<div className="flex justify-between text-xs bg-[var(--bg-sunken)]/50 rounded px-2 py-1"> <div className="flex justify-between text-xs bg-[var(--bg-sunken)]/50 rounded px-2 py-1">
<span style={{ color: 'var(--text-secondary)' }}>Mana Waterfall:</span> <span style={{ color: 'var(--text-secondary)' }}>Mana Waterfall:</span>
<span style={{ color: 'var(--mana-crystal)' }}>+{fmtDec(upgradeEffects.manaWaterfallBonus, 2)}/hr</span> <span style={{ color: 'var(--mana-crystal)' }}>+{fmtDec(manaWaterfallBonus, 2)}/hr</span>
</div> </div>
)} )}
{upgradeEffects.hasFlowSurge && ( {hasFlowSurge && (
<div className="flex justify-between text-xs bg-[var(--bg-sunken)]/50 rounded px-2 py-1"> <div className="flex justify-between text-xs bg-[var(--bg-sunken)]/50 rounded px-2 py-1">
<span style={{ color: 'var(--text-secondary)' }}>Flow Surge:</span> <span style={{ color: 'var(--text-secondary)' }}>Flow Surge:</span>
<span style={{ color: 'var(--mana-crystal)' }}>Clicks +100% regen for 1hr</span> <span style={{ color: 'var(--mana-crystal)' }}>Clicks +100% regen for 1hr</span>
</div> </div>
)} )}
{upgradeEffects.hasManaOverflow && ( {hasManaOverflow && (
<div className="flex justify-between text-xs bg-[var(--bg-sunken)]/50 rounded px-2 py-1"> <div className="flex justify-between text-xs bg-[var(--bg-sunken)]/50 rounded px-2 py-1">
<span style={{ color: 'var(--text-secondary)' }}>Mana Overflow:</span> <span style={{ color: 'var(--text-secondary)' }}>Mana Overflow:</span>
<span style={{ color: 'var(--mana-crystal)' }}>Raw can exceed max by 20%</span> <span style={{ color: 'var(--mana-crystal)' }}>Raw can exceed max by 20%</span>
</div> </div>
)} )}
{upgradeEffects.hasEternalFlow && ( {hasEternalFlow && (
<div className="flex justify-between text-xs bg-[var(--bg-sunken)]/50 rounded px-2 py-1"> <div className="flex justify-between text-xs bg-[var(--bg-sunken)]/50 rounded px-2 py-1">
<span style={{ color: 'var(--text-secondary)' }}>Eternal Flow:</span> <span style={{ color: 'var(--text-secondary)' }}>Eternal Flow:</span>
<span style={{ color: 'var(--color-success)' }}>Regen immune to ALL penalties</span> <span style={{ color: 'var(--color-success)' }}>Regen immune to ALL penalties</span>
</div> </div>
)} )}
{upgradeEffects.hasManaTorrent && upgradeEffects.rawMana > maxMana * 0.75 && ( {hasManaTorrent && rawMana > maxMana * 0.75 && (
<div className="flex justify-between text-xs bg-[var(--bg-sunken)]/50 rounded px-2 py-1"> <div className="flex justify-between text-xs bg-[var(--bg-sunken)]/50 rounded px-2 py-1">
<span style={{ color: 'var(--text-secondary)' }}>Mana Torrent:</span> <span style={{ color: 'var(--text-secondary)' }}>Mana Torrent:</span>
<span style={{ color: 'var(--mana-crystal)' }}>+50% regen (high mana)</span> <span style={{ color: 'var(--mana-crystal)' }}>+50% regen (high mana)</span>
</div> </div>
)} )}
{upgradeEffects.hasDesperateWells && upgradeEffects.rawMana < maxMana * 0.25 && ( {hasDesperateWells && rawMana < maxMana * 0.25 && (
<div className="flex justify-between text-xs bg-[var(--bg-sunken)]/50 rounded px-2 py-1"> <div className="flex justify-between text-xs bg-[var(--bg-sunken)]/50 rounded px-2 py-1">
<span style={{ color: 'var(--text-secondary)' }}>Desperate Wells:</span> <span style={{ color: 'var(--text-secondary)' }}>Desperate Wells:</span>
<span style={{ color: 'var(--mana-crystal)' }}>+50% regen (low mana)</span> <span style={{ color: 'var(--mana-crystal)' }}>+50% regen (low mana)</span>
+9
View File
@@ -13,6 +13,7 @@ import { useUIStore } from './uiStore';
import * as ApplicationActions from '../crafting-actions/application-actions'; import * as ApplicationActions from '../crafting-actions/application-actions';
import * as PreparationActions from '../crafting-actions/preparation-actions'; import * as PreparationActions from '../crafting-actions/preparation-actions';
import * as CraftingEquipment from '../crafting-equipment'; import * as CraftingEquipment from '../crafting-equipment';
import { equipItem as equipItemAction, unequipItem as unequipItemAction } from '../crafting-actions/equipment-actions';
import { ErrorCode } from '../utils/result'; import { ErrorCode } from '../utils/result';
import { createSafeStorage } from '../utils/safe-persist'; import { createSafeStorage } from '../utils/safe-persist';
import type { Result } from '../utils/result'; import type { Result } from '../utils/result';
@@ -376,6 +377,14 @@ export const useCraftingStore = create<CraftingStore>()(
}; };
}); });
}, },
equipItem: (instanceId: string, slot: EquipmentSlot) => {
return equipItemAction(instanceId, slot, get, set);
},
unequipItem: (slot: EquipmentSlot) => {
unequipItemAction(slot, set);
},
}; };
}, },
{ {
@@ -8,6 +8,7 @@ import type {
EquipmentInstance, EquipmentInstance,
DesignEffect, DesignEffect,
} from '../types'; } from '../types';
import type { EquipmentSlot } from '../types/equipmentSlot';
export interface CraftingError { export interface CraftingError {
code: string; code: string;
@@ -57,6 +58,8 @@ export interface CraftingActions {
cancelPreparation: () => void; cancelPreparation: () => void;
deleteMaterial: (materialId: string, amount: number) => void; deleteMaterial: (materialId: string, amount: number) => void;
deleteEquipmentInstance: (instanceId: string) => void; deleteEquipmentInstance: (instanceId: string) => void;
equipItem: (instanceId: string, slot: EquipmentSlot) => boolean;
unequipItem: (slot: EquipmentSlot) => void;
startCraftingEquipment: (blueprintId: string) => boolean; startCraftingEquipment: (blueprintId: string) => boolean;
cancelEquipmentCrafting: () => void; cancelEquipmentCrafting: () => void;
setSelectedEquipmentType: (type: string | null) => void; setSelectedEquipmentType: (type: string | null) => void;
+18 -5
View File
@@ -52,19 +52,29 @@ export const useDisciplineStore = create<DisciplineStore>()(
set((s) => { set((s) => {
const def = DISCIPLINE_MAP[id]; const def = DISCIPLINE_MAP[id];
if (!def) return s; if (!def) return s;
if (s.activeIds.includes(id)) return s;
// Allow re-activation if discipline exists but is paused
const existing = s.disciplines[id];
if (s.activeIds.includes(id)) {
// If already active and paused, un-pause it
if (existing?.paused) {
return {
disciplines: { ...s.disciplines, [id]: { ...existing, paused: false } },
};
}
return s;
}
const nonPaused = s.activeIds.filter((aid) => { const nonPaused = s.activeIds.filter((aid) => {
const d = s.disciplines[aid]; const d = s.disciplines[aid];
return d && !d.paused; return d && !d.paused;
}).length; }).length;
if (nonPaused >= s.concurrentLimit) return s; if (nonPaused >= s.concurrentLimit) return s;
const discState = s.disciplines[id]; if (!canProceedDiscipline(def, existing, gameState)) return s;
if (!canProceedDiscipline(def, discState, gameState)) return s;
const existing = s.disciplines[id] || { id, xp: 0, paused: false }; const discState = existing || { id, xp: 0, paused: false };
return { return {
disciplines: { ...s.disciplines, [id]: { ...existing, paused: false } }, disciplines: { ...s.disciplines, [id]: { ...discState, paused: false } },
activeIds: [...s.activeIds, id], activeIds: [...s.activeIds, id],
}; };
}); });
@@ -73,6 +83,9 @@ export const useDisciplineStore = create<DisciplineStore>()(
deactivate(id) { deactivate(id) {
set((s) => ({ set((s) => ({
activeIds: s.activeIds.filter((aid) => aid !== id), activeIds: s.activeIds.filter((aid) => aid !== id),
disciplines: s.disciplines[id]
? { ...s.disciplines, [id]: { ...s.disciplines[id], paused: true } }
: s.disciplines,
})); }));
}, },