Files
Mana-Loop/src/lib/game/crafting-actions/crafting-equipment-actions.ts
T
n8n-gitea 8a7ddaae27
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m19s
refactor: split bloated state types into State + Actions interfaces (issue #102)
- 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
2026-05-20 21:05:22 +02:00

91 lines
2.4 KiB
TypeScript

// ─── Equipment Crafting Actions ────────────────────────────────────────────
// Note: The main implementation is now in craftingStore.ts
// These wrappers are kept for backward compatibility but are no longer used directly
import type { CraftingState } from '../stores/craftingStore.types';
import type { GameAction } from '../types';
import * as CraftingEquipment from '../crafting-equipment';
export function startCraftingEquipment(
blueprintId: string,
get: () => CraftingState,
set: (fn: (state: CraftingState) => Partial<CraftingState>) => void,
rawMana: number,
currentAction: GameAction,
): boolean {
const state = get();
const check = CraftingEquipment.canStartEquipmentCrafting(
blueprintId,
state.lootInventory.blueprints.includes(blueprintId),
state.lootInventory.materials,
rawMana,
currentAction
);
if (!check.canCraft) return false;
const result = CraftingEquipment.initializeEquipmentCrafting(
blueprintId,
state.lootInventory.materials,
rawMana
);
set((s) => ({
lootInventory: {
...s.lootInventory,
materials: result.newMaterials,
},
equipmentCraftingProgress: result.progress,
}));
return true;
}
export function cancelEquipmentCrafting(
get: () => CraftingState,
set: (fn: (state: CraftingState) => Partial<CraftingState>) => void
) {
set((state) => {
const progress = state.equipmentCraftingProgress;
if (!progress) return { equipmentCraftingProgress: null };
const cancelResult = CraftingEquipment.cancelEquipmentCrafting(
progress.blueprintId,
progress.manaSpent
);
return {
equipmentCraftingProgress: null,
log: [cancelResult.logMessage],
};
});
}
export function deleteMaterial(
materialId: string,
amount: number,
get: () => CraftingState,
set: (fn: (state: CraftingState) => Partial<CraftingState>) => void
) {
set((state) => {
const newMaterials = { ...state.lootInventory.materials };
const currentAmount = newMaterials[materialId] || 0;
const newAmount = Math.max(0, currentAmount - amount);
if (newAmount <= 0) {
delete newMaterials[materialId];
} else {
newMaterials[materialId] = newAmount;
}
return {
lootInventory: {
...state.lootInventory,
materials: newMaterials,
},
log: [`🗑️ Deleted ${amount}x ${materialId}.`],
};
});
}