fix: resolve priority 4 issues — discipline mutation, skill→discipline migration, uiStore persistence, game loop interval, toast listener leak, page re-renders
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m21s
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m21s
- Issue 70: Fix discipline-slice.ts nested element mutation (use immutable spread) - Issue 71: Add persist middleware to uiStore for paused/gameOver/victory - Issue 72: Wire discipline effects into calcDamage (spell-casting, void-manipulation) - Issue 73: Fix useGameLoop interval recreation (use getState() + empty deps) - Issue 74: Fix use-toast.ts listener leak (change [state] dep to []) - Issue 75: Reduce page.tsx re-renders with useShallow for multi-field subscriptions - Issue 76: Fix createGatherMana hardcoded click mana (use computeClickMana with discipline effects) - Issue 77: Pass discipline effects to computeMaxMana/computeRegen/calcInsight in tick() - Export DisciplineBonuses type and useDisciplineStore from barrel exports - Update tests to match new function signatures
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
// Handles logs, pause state, and UI-specific state
|
||||
|
||||
import { create } from 'zustand';
|
||||
import { persist } from 'zustand/middleware';
|
||||
|
||||
export interface LogEntry {
|
||||
message: string;
|
||||
@@ -25,40 +26,45 @@ export interface UIState {
|
||||
|
||||
const MAX_LOGS = 50;
|
||||
|
||||
export const useUIStore = create<UIState>((set) => ({
|
||||
logs: ['✨ The loop begins. You start with Mana Bolt. Gather your strength, mage.'],
|
||||
paused: false,
|
||||
gameOver: false,
|
||||
victory: false,
|
||||
|
||||
addLog: (message: string) => {
|
||||
set((state) => ({
|
||||
logs: [message, ...state.logs.slice(0, MAX_LOGS - 1)],
|
||||
}));
|
||||
},
|
||||
|
||||
clearLogs: () => {
|
||||
set({ logs: [] });
|
||||
},
|
||||
|
||||
togglePause: () => {
|
||||
set((state) => ({ paused: !state.paused }));
|
||||
},
|
||||
|
||||
setPaused: (paused: boolean) => {
|
||||
set({ paused });
|
||||
},
|
||||
|
||||
setGameOver: (gameOver: boolean, victory: boolean = false) => {
|
||||
set({ gameOver, victory });
|
||||
},
|
||||
|
||||
reset: () => {
|
||||
set({
|
||||
export const useUIStore = create<UIState>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
logs: ['✨ The loop begins. You start with Mana Bolt. Gather your strength, mage.'],
|
||||
paused: false,
|
||||
gameOver: false,
|
||||
victory: false,
|
||||
});
|
||||
},
|
||||
}));
|
||||
|
||||
addLog: (message: string) => {
|
||||
set((state) => ({
|
||||
logs: [message, ...state.logs.slice(0, MAX_LOGS - 1)],
|
||||
}));
|
||||
},
|
||||
|
||||
clearLogs: () => {
|
||||
set({ logs: [] });
|
||||
},
|
||||
|
||||
togglePause: () => {
|
||||
set((state) => ({ paused: !state.paused }));
|
||||
},
|
||||
|
||||
setPaused: (paused: boolean) => {
|
||||
set({ paused });
|
||||
},
|
||||
|
||||
setGameOver: (gameOver: boolean, victory: boolean = false) => {
|
||||
set({ gameOver, victory });
|
||||
},
|
||||
|
||||
reset: () => {
|
||||
set({
|
||||
logs: ['✨ The loop begins. You start with Mana Bolt. Gather your strength, mage.'],
|
||||
paused: false,
|
||||
gameOver: false,
|
||||
victory: false,
|
||||
});
|
||||
},
|
||||
}),
|
||||
{ name: 'mana-loop-ui-storage' }
|
||||
)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user