feat(engine): execute story actions via storyChoiceId

This commit is contained in:
ginnoir
2026-06-11 20:36:07 -05:00
parent b3940774c4
commit 8d9484171f
3 changed files with 58 additions and 0 deletions
+24
View File
@@ -1,4 +1,8 @@
import type { Content } from '../content/schema';
import type { StoryContent } from '../content/storySchema';
import { applyChoice, isStoryChoiceAvailable } from './story';
type GameContent = Content & StoryContent;
/**
* Core game state and per-tick simulation.
@@ -173,6 +177,26 @@ export function executeInstant(state: GameState, content: Content, actionId: str
grantYields(state, content, actionId);
}
/**
* Execute a story action by resolving its storyChoiceId and applying it.
* Throws if the action is not of kind 'story', has no storyChoiceId, or the
* choice is not currently available.
*/
export function executeStoryAction(
state: GameState,
content: GameContent,
actionId: string,
): void {
const action = content.actionsById[actionId];
if (!action || action.kind !== 'story' || !action.storyChoiceId) {
throw new Error(`Action "${actionId}" is not a story action`);
}
if (!isStoryChoiceAvailable(state, content, action.storyChoiceId)) {
throw new Error(`Story choice "${action.storyChoiceId}" is not available`);
}
applyChoice(state, content, action.storyChoiceId);
}
/**
* Advance the active action by `tickMs`. On completion, grants yields and
* advances the queue — actions do not auto-repeat when the queue is empty.