Fix: Add missing startCraftingEquipment and cancelEquipmentCrafting actions to craftingStore
Build and Publish Mana Loop Docker Image / build-and-publish (push) Failing after 1m37s
Build and Publish Mana Loop Docker Image / build-and-publish (push) Failing after 1m37s
- Added startCraftingEquipment action that validates and initializes equipment crafting - Added cancelEquipmentCrafting action that cancels crafting and refunds mana - Used CraftingEquipment functions directly instead of deprecated wrapper actions - Updated craftingStore imports to include useManaStore and useUIStore - Fixed crafting/index.tsx barrel file export (removed non-existent type exports) - Fixed syntax errors in craftingStore.ts (missing commas in function params) Fixes issue where EquipmentCrafter component couldn't find these actions on craftingStore.
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
// ─── 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 { GameState } 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,
|
||||
|
||||
@@ -15,13 +15,15 @@ import { hasSpecial, SPECIAL_EFFECTS } from '../special-effects';
|
||||
// Import other stores to access required state
|
||||
import { useSkillStore } from './skillStore';
|
||||
import { useGameStore } from './gameStore';
|
||||
import { useManaStore } from './manaStore';
|
||||
import { useCombatStore } from './combatStore';
|
||||
import { useUIStore } from './uiStore';
|
||||
|
||||
// Import action modules
|
||||
import * as ApplicationActions from '../crafting-actions/application-actions';
|
||||
import * as CraftingApply from '../crafting-apply';
|
||||
import * as PreparationActions from '../crafting-actions/preparation-actions';
|
||||
import * as EquipmentCraftingActions from '../crafting-actions/crafting-equipment-actions';
|
||||
import * as CraftingEquipment from '../crafting-equipment';
|
||||
|
||||
export interface CraftingState {
|
||||
// Crafting progress
|
||||
@@ -50,13 +52,13 @@ export interface CraftingActions {
|
||||
// Actions for design progress
|
||||
setDesignProgress: (progress: DesignProgress | null) => void;
|
||||
setDesignProgress2: (progress: DesignProgress | null) => void;
|
||||
|
||||
|
||||
// Actions for preparation progress
|
||||
setPreparationProgress: (progress: PreparationProgress | null) => void;
|
||||
|
||||
|
||||
// Actions for application progress
|
||||
setApplicationProgress: (progress: ApplicationProgress | null) => void;
|
||||
|
||||
|
||||
// Actions for equipment crafting progress
|
||||
setEquipmentCraftingProgress: (progress: EquipmentCraftingProgress | null) => void;
|
||||
|
||||
@@ -104,7 +106,7 @@ export const useCraftingStore = create<CraftingStore>()(
|
||||
materials: {},
|
||||
blueprints: [],
|
||||
},
|
||||
|
||||
|
||||
// Actions
|
||||
setDesignProgress: (progress) => set({ designProgress: progress }),
|
||||
setDesignProgress2: (progress) => set({ designProgress2: progress }),
|
||||
@@ -243,30 +245,68 @@ export const useCraftingStore = create<CraftingStore>()(
|
||||
|
||||
// Equipment crafting actions
|
||||
startCraftingEquipment: (blueprintId: string) => {
|
||||
// Get state needed for equipment crafting
|
||||
const state = get();
|
||||
const rawMana = useManaStore.getState().rawMana;
|
||||
const currentAction = useCombatStore.getState().currentAction;
|
||||
const lootInventory = get().lootInventory;
|
||||
// Create a temporary state object with all required fields
|
||||
const tempState = {
|
||||
...get(),
|
||||
rawMana,
|
||||
currentAction,
|
||||
lootInventory,
|
||||
} as any;
|
||||
return EquipmentCraftingActions.startCraftingEquipment(
|
||||
|
||||
// Check if we can start crafting
|
||||
const check = CraftingEquipment.canStartEquipmentCrafting(
|
||||
blueprintId,
|
||||
() => tempState,
|
||||
set
|
||||
state.lootInventory.blueprints.includes(blueprintId),
|
||||
state.lootInventory.materials,
|
||||
rawMana,
|
||||
currentAction
|
||||
);
|
||||
|
||||
if (!check.canCraft) return false;
|
||||
|
||||
// Initialize crafting
|
||||
const result = CraftingEquipment.initializeEquipmentCrafting(
|
||||
blueprintId,
|
||||
state.lootInventory.materials,
|
||||
rawMana
|
||||
);
|
||||
|
||||
// Update crafting store state
|
||||
set((s) => ({
|
||||
lootInventory: {
|
||||
...s.lootInventory,
|
||||
materials: result.newMaterials,
|
||||
},
|
||||
equipmentCraftingProgress: result.progress,
|
||||
}));
|
||||
|
||||
// Update mana store (deduct mana)
|
||||
useManaStore.setState((s) => ({ rawMana: s.rawMana - result.manaCost }));
|
||||
|
||||
// Update combat store (set current action)
|
||||
useCombatStore.setState({ currentAction: 'craft' });
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
cancelEquipmentCrafting: () => {
|
||||
EquipmentCraftingActions.cancelEquipmentCrafting(
|
||||
get,
|
||||
set
|
||||
const state = get();
|
||||
const progress = state.equipmentCraftingProgress;
|
||||
if (!progress) return;
|
||||
|
||||
// Get cancel result (mana refund)
|
||||
const cancelResult = CraftingEquipment.cancelEquipmentCrafting(
|
||||
progress.blueprintId,
|
||||
progress.manaSpent
|
||||
);
|
||||
|
||||
// Update crafting store state
|
||||
set({ equipmentCraftingProgress: null });
|
||||
|
||||
// Refund mana to mana store
|
||||
useManaStore.setState((s) => ({ rawMana: s.rawMana + cancelResult.manaRefund }));
|
||||
|
||||
// Update combat store (reset action)
|
||||
useCombatStore.setState({ currentAction: 'meditate' });
|
||||
|
||||
// Add log message to UI store
|
||||
useUIStore.getState().addLog(cancelResult.logMessage);
|
||||
},
|
||||
|
||||
// Loot inventory actions
|
||||
|
||||
Reference in New Issue
Block a user