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,20 +1,28 @@
|
||||
// ─── Enchantment Design Actions ────────────────────────────────────────────
|
||||
|
||||
import type { GameState, EnchantmentDesign, DesignEffect, DesignProgress } from '../types';
|
||||
import type { CraftingState } from '../stores/craftingStore.types';
|
||||
import type { EnchantmentDesign, DesignEffect } from '../types';
|
||||
import * as CraftingUtils from '../crafting-utils';
|
||||
import * as CraftingDesign from '../crafting-design';
|
||||
import { computeEffects } from '../effects/upgrade-effects';
|
||||
import { hasSpecial, SPECIAL_EFFECTS } from '../effects/special-effects';
|
||||
|
||||
export interface DesignActionsParams {
|
||||
skills: Record<string, number>;
|
||||
skillUpgrades: Record<string, string[]>;
|
||||
skillTiers: Record<string, number>;
|
||||
}
|
||||
|
||||
export function startDesigningEnchantment(
|
||||
name: string,
|
||||
equipmentTypeId: string,
|
||||
effects: DesignEffect[],
|
||||
get: () => GameState,
|
||||
set: (fn: (state: GameState) => Partial<GameState>) => void
|
||||
params: DesignActionsParams,
|
||||
get: () => CraftingState,
|
||||
set: (fn: (state: CraftingState) => Partial<CraftingState>) => void
|
||||
): boolean {
|
||||
const state = get();
|
||||
const enchantingLevel = state.skills.enchanting || 0;
|
||||
const enchantingLevel = params.skills.enchanting || 0;
|
||||
const validation = CraftingDesign.validateDesignEffects(
|
||||
effects,
|
||||
equipmentTypeId,
|
||||
@@ -25,21 +33,20 @@ export function startDesigningEnchantment(
|
||||
const equipType = CraftingUtils.getEquipmentType(equipmentTypeId);
|
||||
if (!equipType) return false;
|
||||
|
||||
const efficiencyBonus = ((state.skillUpgrades || {})['efficientEnchant'] || [])?.length * 0.05 || 0;
|
||||
const efficiencyBonus = ((params.skillUpgrades || {})['efficientEnchant'] || [])?.length * 0.05 || 0;
|
||||
const totalCapacityCost = CraftingDesign.calculateDesignCapacityCost(effects, efficiencyBonus);
|
||||
|
||||
if (totalCapacityCost > equipType.baseCapacity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const computedEffects = computeEffects(state.skillUpgrades || {}, state.skillTiers || {});
|
||||
const computedEffects = computeEffects(params.skillUpgrades || {}, params.skillTiers || {});
|
||||
const hasEnchantMastery = hasSpecial(computedEffects, SPECIAL_EFFECTS.ENCHANT_MASTERY);
|
||||
|
||||
let updates: Partial<GameState> = {};
|
||||
let updates: Partial<CraftingState> = {};
|
||||
|
||||
if (!state.designProgress) {
|
||||
updates = {
|
||||
currentAction: 'design' as const,
|
||||
designProgress: {
|
||||
designId: CraftingUtils.generateDesignId(),
|
||||
progress: 0,
|
||||
@@ -69,15 +76,14 @@ export function startDesigningEnchantment(
|
||||
}
|
||||
|
||||
export function cancelDesign(
|
||||
get: () => GameState,
|
||||
set: (fn: (state: GameState) => Partial<GameState>) => void
|
||||
get: () => CraftingState,
|
||||
set: (fn: (state: CraftingState) => Partial<CraftingState>) => void
|
||||
) {
|
||||
const state = get();
|
||||
if (state.designProgress2 && !state.designProgress) {
|
||||
set(() => ({ designProgress2: null }));
|
||||
} else {
|
||||
set(() => ({
|
||||
currentAction: 'meditate' as const,
|
||||
designProgress: null,
|
||||
}));
|
||||
}
|
||||
@@ -85,27 +91,26 @@ export function cancelDesign(
|
||||
|
||||
export function saveDesign(
|
||||
design: EnchantmentDesign,
|
||||
get: () => GameState,
|
||||
set: (fn: (state: GameState) => Partial<GameState>) => void
|
||||
get: () => CraftingState,
|
||||
set: (fn: (state: CraftingState) => Partial<CraftingState>) => void
|
||||
) {
|
||||
const state = get();
|
||||
if (state.designProgress2 && state.designProgress2.designId === design.id) {
|
||||
set((state) => ({
|
||||
enchantmentDesigns: [...state.enchantmentDesigns, design],
|
||||
set((s) => ({
|
||||
enchantmentDesigns: [...s.enchantmentDesigns, design],
|
||||
designProgress2: null,
|
||||
}));
|
||||
} else {
|
||||
set((state) => ({
|
||||
enchantmentDesigns: [...state.enchantmentDesigns, design],
|
||||
set((s) => ({
|
||||
enchantmentDesigns: [...s.enchantmentDesigns, design],
|
||||
designProgress: null,
|
||||
currentAction: 'meditate' as const,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
export function deleteDesign(
|
||||
designId: string,
|
||||
set: (fn: (state: GameState) => Partial<GameState>) => void
|
||||
set: (fn: (state: CraftingState) => Partial<CraftingState>) => void
|
||||
) {
|
||||
set((state) => ({
|
||||
enchantmentDesigns: state.enchantmentDesigns.filter(d => d.id !== designId),
|
||||
|
||||
Reference in New Issue
Block a user