story_adventure

@story-adventure/shared

Shared types, utilities, and action system for Story Adventure.

Overview

This package contains the core logic and type definitions used by both the Story Adventure editor and viewer. It includes:

Installation

pnpm add @story-adventure/shared

Usage

Types

import type { Story, Section, Action } from '@story-adventure/shared';

const story: Story = {
  sections: {
    '1': {
      id: '1',
      text_lines: ['Hello ${name}!'],
      next: [{ text: 'Continue', next: '2' }],
    },
  },
  state: {
    variables: { name: 'Alice' },
  },
};

Actions

import { execute_actions, supported_actions } from '@story-adventure/shared';

// Execute actions from a section's script
execute_actions(story, [
  { action: 'SET', parameters: ['score', '100'] },
  { action: 'ADD_CHOICE', parameters: ['2', 'Go to section 2'] },
]);

Variable Interpolation

import { replace_variables } from '@story-adventure/shared';

const text = replace_variables('Hello ${name}', { name: 'Alice' });
// Returns: "Hello Alice"

Utilities

import { get_text_from_section, get_file_safe_title } from '@story-adventure/shared';

const text = get_text_from_section(section, story.state?.variables);
const filename = get_file_safe_title(story);

Action Types

The action system supports the following action types:

See the Story Format documentation for detailed action specifications.

Testing

Run tests with:

pnpm test

License

See root LICENSE file.