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
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:
@@ -1,13 +1,19 @@
|
||||
// ─── Enchantment Application Actions ────────────────────────────────────────
|
||||
|
||||
import type { GameState } from '../types';
|
||||
import type { CraftingState } from '../stores/craftingStore.types';
|
||||
import type { GameAction } from '../types';
|
||||
import * as CraftingApply from '../crafting-apply';
|
||||
|
||||
/**
|
||||
* Start applying an enchantment design to an equipment instance.
|
||||
* Note: currentAction must be passed from the combat store.
|
||||
*/
|
||||
export function startApplying(
|
||||
equipmentInstanceId: string,
|
||||
designId: string,
|
||||
get: () => GameState,
|
||||
set: (fn: (state: GameState) => Partial<GameState>) => void
|
||||
get: () => CraftingState,
|
||||
set: (partial: Partial<CraftingState>) => void,
|
||||
currentAction: GameAction,
|
||||
): boolean {
|
||||
const state = get();
|
||||
const instance = state.equipmentInstances[equipmentInstanceId];
|
||||
@@ -16,57 +22,53 @@ export function startApplying(
|
||||
const validation = CraftingApply.canApplyEnchantment(
|
||||
instance,
|
||||
design,
|
||||
state.currentAction
|
||||
currentAction
|
||||
);
|
||||
if (!validation.canApply) return false;
|
||||
|
||||
set(() => ({
|
||||
currentAction: 'enchant' as const,
|
||||
set({
|
||||
applicationProgress: CraftingApply.initializeApplicationProgress(
|
||||
equipmentInstanceId,
|
||||
designId,
|
||||
design!
|
||||
),
|
||||
}));
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export function pauseApplication(
|
||||
get: () => GameState,
|
||||
set: (fn: (state: GameState) => Partial<GameState>) => void
|
||||
get: () => CraftingState,
|
||||
set: (partial: Partial<CraftingState>) => void
|
||||
) {
|
||||
set((state) => {
|
||||
if (!state.applicationProgress) return {};
|
||||
return {
|
||||
applicationProgress: {
|
||||
...state.applicationProgress,
|
||||
paused: true,
|
||||
},
|
||||
};
|
||||
const state = get();
|
||||
if (!state.applicationProgress) return;
|
||||
set({
|
||||
applicationProgress: {
|
||||
...state.applicationProgress,
|
||||
paused: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function resumeApplication(
|
||||
get: () => GameState,
|
||||
set: (fn: (state: GameState) => Partial<GameState>) => void
|
||||
get: () => CraftingState,
|
||||
set: (partial: Partial<CraftingState>) => void
|
||||
) {
|
||||
set((state) => {
|
||||
if (!state.applicationProgress) return {};
|
||||
return {
|
||||
applicationProgress: {
|
||||
...state.applicationProgress,
|
||||
paused: false,
|
||||
},
|
||||
};
|
||||
const state = get();
|
||||
if (!state.applicationProgress) return;
|
||||
set({
|
||||
applicationProgress: {
|
||||
...state.applicationProgress,
|
||||
paused: false,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function cancelApplication(
|
||||
set: (fn: (state: GameState) => Partial<GameState>) => void
|
||||
set: (partial: Partial<CraftingState>) => void
|
||||
) {
|
||||
set(() => ({
|
||||
currentAction: 'meditate' as const,
|
||||
set({
|
||||
applicationProgress: null,
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user