refactor: make activate() read mana state from stores directly instead of requiring UI to pass gameState bag
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m28s
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m28s
This commit is contained in:
@@ -22,6 +22,8 @@ import { enchanterSpecialDisciplines } from '../data/disciplines/enchanter-speci
|
||||
import { fabricatorDisciplines } from '../data/disciplines/fabricator';
|
||||
import { invokerDisciplines } from '../data/disciplines/invoker';
|
||||
import { MAX_CONCURRENT_DISCIPLINES } from '../types/disciplines';
|
||||
import { useManaStore } from './manaStore';
|
||||
import { usePrestigeStore } from './prestigeStore';
|
||||
|
||||
|
||||
const ALL_DISCIPLINES = [
|
||||
@@ -48,7 +50,7 @@ export interface DisciplineStoreState {
|
||||
}
|
||||
|
||||
export interface DisciplineStoreActions {
|
||||
activate: (id: string, gameState?: { elements?: Record<string, ElementState>; rawMana?: number; signedPacts?: number[] }) => void;
|
||||
activate: (id: string, gameStateOverrides?: { elements?: Record<string, ElementState>; rawMana?: number; signedPacts?: number[] }) => void;
|
||||
deactivate: (id: string) => void;
|
||||
processTick: (mana: { rawMana: number; elements: Record<string, ElementState> }) => {
|
||||
rawMana: number;
|
||||
@@ -73,7 +75,7 @@ export const useDisciplineStore = create<DisciplineStore>()(
|
||||
processedPerks: [],
|
||||
practicingCallbacks: null,
|
||||
|
||||
activate(id, gameState) {
|
||||
activate(id, gameStateOverrides) {
|
||||
set((s) => {
|
||||
const def = DISCIPLINE_MAP[id];
|
||||
if (!def) return s;
|
||||
@@ -98,15 +100,26 @@ export const useDisciplineStore = create<DisciplineStore>()(
|
||||
return d && !d.paused;
|
||||
}).length;
|
||||
if (nonPaused >= s.concurrentLimit) return s;
|
||||
if (!canProceedDiscipline(def, existing, gameState)) return s;
|
||||
|
||||
// Resolve game state: use overrides if provided (for tests), otherwise read
|
||||
// directly from the mana and prestige stores. This prevents the UI from needing
|
||||
// to manually construct and pass a gameState bag — eliminating the class of bug
|
||||
// where a missing field (e.g. rawMana) silently prevents reactivation.
|
||||
const resolvedState = gameStateOverrides ?? {
|
||||
rawMana: useManaStore.getState().rawMana,
|
||||
elements: useManaStore.getState().elements,
|
||||
signedPacts: usePrestigeStore.getState().signedPacts,
|
||||
};
|
||||
|
||||
if (!canProceedDiscipline(def, existing, resolvedState)) return s;
|
||||
|
||||
// Check discipline prerequisites (requires field → discipline XP or mana type unlock)
|
||||
const prereqCheck = checkDisciplinePrerequisites(def, s.disciplines, ALL_DISCIPLINES, gameState?.elements, gameState?.signedPacts);
|
||||
const prereqCheck = checkDisciplinePrerequisites(def, s.disciplines, ALL_DISCIPLINES, resolvedState.elements, resolvedState.signedPacts);
|
||||
if (!prereqCheck.canProceed) return s;
|
||||
|
||||
// For conversion disciplines: gate on having all source mana types unlocked
|
||||
if (def.sourceManaTypes && def.sourceManaTypes.length > 0) {
|
||||
const elements = gameState?.elements;
|
||||
const elements = resolvedState.elements;
|
||||
if (elements) {
|
||||
for (const srcType of def.sourceManaTypes) {
|
||||
if (srcType === 'raw') continue; // raw is always available
|
||||
|
||||
Reference in New Issue
Block a user