29 lines
838 B
TypeScript
29 lines
838 B
TypeScript
import { create } from 'zustand';
|
|
import type { GameView } from './viewModel';
|
|
|
|
/**
|
|
* The view store. The runtime owns the authoritative engine state and pushes a
|
|
* fresh view snapshot here at ~10 fps; React components subscribe to slices of
|
|
* it. The store is a dumb mirror plus an event log — no game logic lives here.
|
|
*/
|
|
|
|
const MAX_LOG_LINES = 50;
|
|
|
|
export interface GameStoreState extends GameView {
|
|
log: string[];
|
|
setView: (view: GameView) => void;
|
|
appendLog: (line: string) => void;
|
|
}
|
|
|
|
export const useGameStore = create<GameStoreState>((set) => ({
|
|
resources: [],
|
|
activeActionId: null,
|
|
actionName: null,
|
|
actionProgress: 0,
|
|
queuedActionIds: [],
|
|
queuedActionNames: [],
|
|
log: [],
|
|
setView: (view) => set(view),
|
|
appendLog: (line) => set((state) => ({ log: [...state.log, line].slice(-MAX_LOG_LINES) })),
|
|
}));
|