Skip to main content

Class: Passage

Defined in: packages/core/src/passages/passage.ts:29

Base class for all passage types in the text game engine.

Passages represent different screens or scenes in the game. Each passage has a unique identifier and type, and is automatically registered with the Game when instantiated.

Subclasses must implement the display() method to define how the passage renders.

Example

class CustomPassage extends Passage {
constructor(id: string) {
super(id, 'custom');
}

display(props) {
return { content: 'Custom passage content' };
}
}

See

  • Story - Text-based narrative passage implementation
  • InteractiveMap - Map-based interactive passage implementation
  • Widget - React component passage implementation

Extended by

Constructors

Constructor

new Passage(id, type): Passage

Defined in: packages/core/src/passages/passage.ts:55

Creates a new passage and automatically registers it with the Game.

Parameters

id

string

Unique identifier for this passage

type

PassageType

The passage type (story, interactiveMap, or widget)

Returns

Passage

Properties

_lastDisplayResult

protected _lastDisplayResult: unknown = null

Defined in: packages/core/src/passages/passage.ts:47

Internal

Cached result from the last display() call. Used to access display data without re-executing content functions.


id

readonly id: string

Defined in: packages/core/src/passages/passage.ts:34

Unique identifier for this passage. Used for navigation and registry lookup.


type

readonly type: PassageType

Defined in: packages/core/src/passages/passage.ts:40

The type of this passage. Determines how the passage should be rendered in the UI.

Methods

display()

display<T>(_props): void

Defined in: packages/core/src/passages/passage.ts:72

Renders the passage content with optional props.

This method must be implemented by subclasses to define the passage behavior.

Type Parameters

T

T extends InitVarsType = EmptyObject

Type of props passed to the display method

Parameters

_props

T = ...

Optional properties for rendering the passage

Returns

void

The rendered passage content (type depends on passage implementation)

Throws

Error if not implemented by subclass


getLastDisplayResult()

getLastDisplayResult<T>(): T | null

Defined in: packages/core/src/passages/passage.ts:97

Returns the cached result from the last display() call. Use this method to access passage data without re-executing content functions, which prevents unwanted side effects.

Type Parameters

T

T = unknown

Expected return type

Returns

T | null

The cached display result, or null if display() has never been called

Example

const story = newStory('test', () => [{ type: 'text', content: 'Hello' }]);

// First call to display() - executes content function
const result = story.display();

// Get cached result - does NOT execute content function again
const cached = story.getLastDisplayResult();

hasDisplayCache()

hasDisplayCache(): boolean

Defined in: packages/core/src/passages/passage.ts:106

Checks if a cached display result exists.

Returns

boolean

true if display() has been called at least once, false otherwise