Skip to main content

View as Markdown · AI documentation index

Interface: ReactTextGameDebug

Defined in: packages/core/src/global.ts:5

Properties​

currentPassage​

readonly currentPassage: Passage | null

Defined in: packages/core/src/global.ts:8


Game​

Game: typeof Game

Defined in: packages/core/src/global.ts:6


getPassage()​

getPassage: (passageId) => Passage | null

Defined in: packages/core/src/global.ts:12

Retrieves a passage by its unique identifier.

Parameters​

passageId​

string

The unique ID of the passage to retrieve.

Returns​

Passage | null

The passage object if found, or null if no passage exists with the given ID.

Throws​

Error if Game.init() has not been called


getState()​

getState: (_fromI) => GameSaveState

Defined in: packages/core/src/global.ts:13

Captures the complete game state including all entities and passages.

This method:

  1. Saves the Game's internal state (current passage)
  2. Saves all registered entity states
  3. Returns the complete state object

Parameters​

_fromI​

boolean = false

Returns​

GameSaveState

The complete serializable game state

Throws​

Error if Game.init() has not been called

Example​

const savedState = Game.getState();
localStorage.setItem('save1', JSON.stringify(savedState));

jumpTo()​

jumpTo: (passage) => void

Defined in: packages/core/src/global.ts:11

Navigates the game to a specified passage.

On each call, generates a new unique renderId to enable React components to force remounts when revisiting the same passage. This is useful for resetting component state, restarting animations, or clearing forms.

Parameters​

passage​

PassageTarget

A passage instance (Story, InteractiveMap, Widget, or any other Passage) or the id of a registered passage.

Returns​

void

Does not return any value.

Throws​

Throws an error if a passage id is not found in the registry or if Game.init() has not been called

Remarks​

A passage instance that is not in the registry is registered on the spot, so navigating to an instance never fails with "Passage not found". Only a string id can refer to a passage that does not exist.

Example​

// Jump to a passage by ID
Game.jumpTo('intro');

// Jump to a passage instance - Story, InteractiveMap and Widget all work
const chapter1 = defineStory('chapter1', (h) => [...]);
const worldMap = defineInteractiveMap('world', (h) => [...], { image: '/world.png' });
const inventory = defineWidget('inventory', <InventoryUI />);

Game.jumpTo(chapter1);
Game.jumpTo(worldMap);
Game.jumpTo(inventory);

// Jumping to the same passage multiple times will generate different renderIds
Game.jumpTo('combat'); // renderId: "1234567890-0.123"
Game.jumpTo('combat'); // renderId: "1234567891-0.456" (different!)

passages​

readonly passages: Passage[]

Defined in: packages/core/src/global.ts:10


setState()​

setState: (state) => void

Defined in: packages/core/src/global.ts:14

Restores the complete game state including all entities and passages.

This method:

  1. Sets the Storage state
  2. Loads the Game's internal state (current passage)
  3. Loads all registered entity states

Parameters​

state​

GameSaveState

The game state to restore

Returns​

void

Throws​

Error if Game.init() has not been called

Example​

const savedState = JSON.parse(localStorage.getItem('save1'));
Game.setState(savedState);

state​

readonly state: Record<string, unknown>

Defined in: packages/core/src/global.ts:9


Storage​

Storage: typeof Storage

Defined in: packages/core/src/global.ts:7