Interface StoryRuntime<TEffect, TState>

Runtime interface for navigating and interacting with a story.

interface StoryRuntime<TEffect, TState> {
    choose(choiceId, state): StepResult<TEffect>;
    current(state): StepResult<TEffect>;
    divert(to, state): StepResult<TEffect>;
    getPosition(): {
        knotId: string;
        nodeId: string;
    };
    getStory(): Story<TEffect>;
}

Type Parameters

  • TEffect = unknown

    The type of effects used in the story

  • TState = unknown

    The type of game state used for condition evaluation

Methods

  • Makes a choice and advances the story to the target node. Throws an error if the choice doesn't exist or isn't available.

    Parameters

    • choiceId: string

      ID of the choice to make

    • state: TState

      Current game state for condition evaluation

    Returns StepResult<TEffect>

    Step result after advancing

    Throws

    Error if choice not found or condition not met

  • Returns the current story step without advancing. Choices are filtered based on conditions evaluated against the provided state.

    Parameters

    • state: TState

      Current game state for condition evaluation

    Returns StepResult<TEffect>

    Current step result with available choices

  • Jumps directly to a specific knot and node. Useful for save/load, debugging, or special navigation.

    Parameters

    • to: {
          knot?: string;
          node: string;
      }

      Target location (knot optional, defaults to current)

      • Optional knot?: string
      • node: string
    • state: TState

      Current game state for condition evaluation

    Returns StepResult<TEffect>

    Step result at the new location

    Throws

    Error if target knot or node doesn't exist

  • Gets the current position in the story.

    Returns {
        knotId: string;
        nodeId: string;
    }

    Object containing the current knot and node IDs

    • knotId: string
    • nodeId: string