narraleaf-react
Version:
A React visual novel player framework
93 lines (92 loc) • 3.05 kB
TypeScript
import { Constructable } from "../action/constructable";
import { Scene } from "../elements/scene";
import { SceneAction } from "../action/actions/sceneAction";
import { Persistent, PersistentContent } from "../elements/persistent";
import { Service } from "../elements/service";
export declare enum Origins {
topLeft = "top left",
topRight = "top right",
bottomLeft = "bottom left",
bottomRight = "bottom right"
}
export interface IStoryConfig {
origin: Origins;
}
export declare class Story extends Constructable<SceneAction<"scene:action">, Story> {
constructor(name: string, config?: IStoryConfig);
/**
* Set the entry scene of the story
* @example
* ```typescript
* const story = new Story("story");
* const scene = new Scene("scene");
* story.entry(scene); // The story will start from this scene
* ```
*/
entry(scene: Scene): this;
/**
* Register a scene to the story
* @example
* ```typescript
* // register a scene
* const story = new Story("story");
* const scene1 = new Scene("scene1");
* const scene2 = new Scene("scene2");
*
* story.register(scene1); // Register scene1
*
* scene2.action([
* scene2.jump("scene1") // Jump to scene1
* ]);
* ```
*/
registerScene(name: string, scene: Scene): this;
registerScene(scene: Scene): this;
/**
* Register a Persistent to the story
*
* You can't use a Persistent that isn't registered to the story
*/
registerPersistent(persistent: Persistent<any>): this;
/**
* Create a Persistent and register it to the story
* @example
* ```typescript
* const persistent = story.createPersistent("playerData", {
* name: "persistent",
* });
*
* // is equivalent to
* const persistent = new Persistent("playerData", {
* name: "persistent",
* });
* story.registerPersistent(persistent);
* ```
*/
createPersistent<T extends PersistentContent>(namespace: string, defaultContent: T): Persistent<T>;
/**
* Register a Service to the story
*
* **Note**: service name should be unique
*/
registerService(name: string, service: Service): this;
/**
* Get a registered service, throw an error if the service isn't found
*/
getService<T extends Service>(name: string): T;
/**
* Returns a 64-bit hash of the story
*
* The hash is calculated by the stringified story.
*
* If `strict` is true, the hash will be calculated by the stringified story with strict mode.
*
* In strict mode, the hash will be calculated
* - With all the Lambda functions stringified (If the lambda function is changed, the hash will be different)
*
* However, the hash is **not** calculated with the text content of the story.
*/
hash(strict?: boolean): string;
stringify(strict?: boolean): string;
getScene(name: string | Scene, assert?: false): Scene | null;
}