feat(state): wire enqueueAction through runtime and view model

This commit is contained in:
ginnoir
2026-06-11 18:21:12 -05:00
parent 7625e081fd
commit fce561b8e5
5 changed files with 38 additions and 8 deletions
+12 -6
View File
@@ -1,5 +1,5 @@
import { content } from '../content';
import { startAction as engineStartAction, type GameState, tickGame } from '../engine/game';
import { enqueueAction as engineEnqueueAction, type GameState, tickGame } from '../engine/game';
import { advance, createTickLoop, TICK_MS, type TickLoop } from '../engine/tickLoop';
import { createDefaultBackend, loadGame, type SaveBackend, saveGame } from './persistence';
import { useGameStore } from './store';
@@ -58,15 +58,21 @@ class GameRuntime {
}
}
startAction(actionId: string): void {
enqueueAction(actionId: string): void {
const state = this.state;
if (!state) {
return;
}
engineStartAction(state, content, actionId);
const action = content.actionsById[actionId];
if (action) {
useGameStore.getState().appendLog(`Started: ${action.name}.`);
try {
engineEnqueueAction(state, content, actionId);
const action = content.actionsById[actionId];
if (action) {
const verb = state.actionQueue.includes(actionId) ? 'Queued' : 'Started';
useGameStore.getState().appendLog(`${verb}: ${action.name}.`);
}
} catch (err) {
const msg = err instanceof Error ? err.message : 'Cannot start action';
useGameStore.getState().appendLog(msg);
}
this.publish();
}