Core engine for Storyloom interactive storytelling framework.
npm install storyloom
import { createRuntime, Story } from 'storyloom';
// Define your story
const story: Story<any> = {
version: 1,
entryKnot: 'start',
knots: {
start: {
id: 'start',
entryNode: 'intro',
nodes: {
intro: {
id: 'intro',
text: 'Your adventure begins...',
choices: [
{
id: 'continue',
label: 'Continue',
target: { node: 'next' },
},
],
},
next: {
id: 'next',
text: 'The story continues...',
ending: { id: 'end', label: 'The End' },
},
},
},
},
};
// Create a runtime instance
const runtime = createRuntime(story);
// Get current step
const step = runtime.current();
console.log(step.text); // ['Your adventure begins...']
// Make a choice
const nextStep = runtime.choose('continue');
console.log(nextStep.text); // ['The story continues...']
createRuntime<TEffect, TState>(story: Story<TEffect>, options?: RuntimeOptions<TState>)Creates a new story runtime instance.
runtime.current(state?: TState): StepResult<TEffect>Gets the current story step with available choices.
runtime.choose(choiceId: string, state?: TState): StepResult<TEffect>Makes a choice and advances the story.
runtime.divert(target: { knot: string; node: string }): voidJumps to a specific knot and node in the story.
analyzeStory<TEffect>(story: Story<TEffect>): AnalysisResultAnalyzes a story for potential issues.
The runtime throws descriptive errors when:
This fail-fast behavior helps catch story structure issues during development.
To generate the API documentation locally:
npm run docs
This creates a docs/ folder with the full API reference. The docs are generated from TypeScript types and JSDoc comments, so they stay in sync with your code.
MIT