The initial state value (will be deep cloned).
Optional configuration for persistence, undo, and callbacks.
A Zustand store with game state management features.
// Basic store
interface PlayerState {
health: number;
position: [number, number, number];
inventory: string[];
}
const usePlayerStore = createGameStore<PlayerState>({
health: 100,
position: [0, 0, 0],
inventory: [],
});
// In a React component
const health = usePlayerStore(state => state.data.health);
const { set, undo, redo, save, load } = usePlayerStore();
// Update state
set({ health: 50, position: [10, 0, 5], inventory: [] });
// Undo last change
undo();
// Save to storage
await save('slot1');
// Advanced configuration
const useGameStore = createGameStore(
{ world: {}, player: {} },
{
enablePersistence: true,
maxUndoHistory: 100,
storagePrefix: 'mygame',
persistenceAdapter: customAdapter,
onSave: (success) => {
console.log('Save result:', success);
},
onLoad: (state) => {
console.log('Loaded state:', state);
}
}
);
Creates a Zustand store with undo/redo and persistence capabilities.
The main factory function for creating game state stores. Combines Zustand, Immer, and zundo middleware to provide a complete state management solution with automatic persistence, undo/redo history, and checksum validation.