refactor: split bloated state types into State + Actions interfaces (issue #102)
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m19s

- CombatState: split into CombatState (data) + CombatActions + CombatStore
- PrestigeState: split into PrestigeState (data) + PrestigeActions + PrestigeStore
- ManaState: split into ManaState (data) + ManaActions + ManaStore
- GameState: deprecated, removed from barrel exports
- crafting-actions: updated to use CraftingState instead of GameState
- combat-utils/mana-utils: replaced Pick<GameState,...> with focused interfaces
- DisciplineCardProps: split into Definition + Runtime + Callbacks
- stores/index.ts: now exports both State and Actions types
This commit is contained in:
2026-05-20 21:05:22 +02:00
parent ee893e8973
commit 8a7ddaae27
24 changed files with 411 additions and 321 deletions
@@ -2,16 +2,16 @@
// Note: The main implementation is now in craftingStore.ts
// These wrappers are kept for backward compatibility but are no longer used directly
import type { GameState } from '../types';
import type { CraftingState } from '../stores/craftingStore.types';
import type { GameAction } from '../types';
import * as CraftingEquipment from '../crafting-equipment';
// Wrapper functions kept for backward compatibility
// The actual implementation is in craftingStore.ts using CraftingEquipment functions directly
export function startCraftingEquipment(
blueprintId: string,
get: () => GameState,
set: (fn: (state: GameState) => Partial<GameState>) => void
get: () => CraftingState,
set: (fn: (state: CraftingState) => Partial<CraftingState>) => void,
rawMana: number,
currentAction: GameAction,
): boolean {
const state = get();
@@ -19,8 +19,8 @@ export function startCraftingEquipment(
blueprintId,
state.lootInventory.blueprints.includes(blueprintId),
state.lootInventory.materials,
state.rawMana,
state.currentAction
rawMana,
currentAction
);
if (!check.canCraft) return false;
@@ -28,16 +28,14 @@ export function startCraftingEquipment(
const result = CraftingEquipment.initializeEquipmentCrafting(
blueprintId,
state.lootInventory.materials,
state.rawMana
rawMana
);
set((state) => ({
set((s) => ({
lootInventory: {
...state.lootInventory,
...s.lootInventory,
materials: result.newMaterials,
},
rawMana: state.rawMana - result.manaCost,
currentAction: 'craft' as const,
equipmentCraftingProgress: result.progress,
}));
@@ -45,12 +43,12 @@ export function startCraftingEquipment(
}
export function cancelEquipmentCrafting(
get: () => GameState,
set: (fn: (state: GameState) => Partial<GameState>) => void
get: () => CraftingState,
set: (fn: (state: CraftingState) => Partial<CraftingState>) => void
) {
set((state) => {
const progress = state.equipmentCraftingProgress;
if (!progress) return { currentAction: 'meditate' as const, equipmentCraftingProgress: null };
if (!progress) return { equipmentCraftingProgress: null };
const cancelResult = CraftingEquipment.cancelEquipmentCrafting(
progress.blueprintId,
@@ -58,10 +56,8 @@ export function cancelEquipmentCrafting(
);
return {
currentAction: 'meditate' as const,
equipmentCraftingProgress: null,
rawMana: state.rawMana + cancelResult.manaRefund,
log: [cancelResult.logMessage, ...state.log.slice(0, 49)],
log: [cancelResult.logMessage],
};
});
}
@@ -69,8 +65,8 @@ export function cancelEquipmentCrafting(
export function deleteMaterial(
materialId: string,
amount: number,
get: () => GameState,
set: (fn: (state: GameState) => Partial<GameState>) => void
get: () => CraftingState,
set: (fn: (state: CraftingState) => Partial<CraftingState>) => void
) {
set((state) => {
const newMaterials = { ...state.lootInventory.materials };
@@ -88,7 +84,7 @@ export function deleteMaterial(
...state.lootInventory,
materials: newMaterials,
},
log: [`🗑️ Deleted ${amount}x ${materialId}.`, ...state.log.slice(0, 49)],
log: [`🗑️ Deleted ${amount}x ${materialId}.`],
};
});
}