@@ -52,19 +52,29 @@ export const useDisciplineStore = create<DisciplineStore>()(
|
||||
set((s) => {
|
||||
const def = DISCIPLINE_MAP[id];
|
||||
if (!def) return s;
|
||||
if (s.activeIds.includes(id)) return s;
|
||||
|
||||
// Allow re-activation if discipline exists but is paused
|
||||
const existing = s.disciplines[id];
|
||||
if (s.activeIds.includes(id)) {
|
||||
// If already active and paused, un-pause it
|
||||
if (existing?.paused) {
|
||||
return {
|
||||
disciplines: { ...s.disciplines, [id]: { ...existing, paused: false } },
|
||||
};
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
const nonPaused = s.activeIds.filter((aid) => {
|
||||
const d = s.disciplines[aid];
|
||||
return d && !d.paused;
|
||||
}).length;
|
||||
if (nonPaused >= s.concurrentLimit) return s;
|
||||
const discState = s.disciplines[id];
|
||||
if (!canProceedDiscipline(def, discState, gameState)) return s;
|
||||
if (!canProceedDiscipline(def, existing, gameState)) return s;
|
||||
|
||||
const existing = s.disciplines[id] || { id, xp: 0, paused: false };
|
||||
const discState = existing || { id, xp: 0, paused: false };
|
||||
return {
|
||||
disciplines: { ...s.disciplines, [id]: { ...existing, paused: false } },
|
||||
disciplines: { ...s.disciplines, [id]: { ...discState, paused: false } },
|
||||
activeIds: [...s.activeIds, id],
|
||||
};
|
||||
});
|
||||
@@ -73,6 +83,9 @@ export const useDisciplineStore = create<DisciplineStore>()(
|
||||
deactivate(id) {
|
||||
set((s) => ({
|
||||
activeIds: s.activeIds.filter((aid) => aid !== id),
|
||||
disciplines: s.disciplines[id]
|
||||
? { ...s.disciplines, [id]: { ...s.disciplines[id], paused: true } }
|
||||
: s.disciplines,
|
||||
}));
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user