Story
⚠️
This page is under construction.
⚠️
Beta feature, subject to change.
Story
is the main entry point for creating a story.
import { Story } from 'narraleaf-react';
const story = new Story("story name");
const scene1 = new Scene("scene 1");
story.entry(scene1);
Public Method
constructor
name: string
- Name of the storyconfig: IStoryConfig
- See IStoryConfig
entry
scene: Scene
- The first scene to be executed- Returns
this
registerScene
Scenes that are registered can be accessed by their name. For exmaple, you can jump to a scene by its name.
const scene1 = new Scene("scene 1");
const scene2 = new Scene("scene 2");
scene1.action([
scene1.jump("scene 2") // use string instead of scene instance
]);
const story = new Story("story name");
story.registerScene("scene 2", scene2);
Overload 1 of 2
scene: Scene
- The scene to be registered- Returns
this
Overload 2 of 2
This overload allows you to pass the scene alias and the scene instance.
name: string
- Name of the scenescene: Scene
- The scene to be registered- Returns
this
registerPersistent
You have to register the persistent to make it available in the story.
const story = new Story("story name");
const persis = new Persistent</* ... */>("persis", /* ... */);
story.registerPersistent(persistent);
const scene1 = new Scene("scene 1");
scene1.action([
persis.set(/* ... */, /* ... */)
]);
persistent: Persistent<any>
- The Persistent to be registered- Returns
this
registerService
Register a service. For more information, see Service.
const story = new Story(/* ... */);
const gallery = new Gallery(/* ... */);
story.registerService("gallery", gallery);
name: string
- Name of the serviceservice: Service<any>
- The Service to be registered- Returns
this
getService<T extends Service>
Get the service by its name. Throws an error if the service is not found.
const {game} = useGame();
const liveGame = game.getLiveGame();
const gallery = liveGame.story?.getService<Gallery>("gallery");
name: string
- Name of the service- Returns
T