narraleaf-react
Version:
A React visual novel player framework
57 lines (56 loc) • 1.83 kB
TypeScript
import { LogicAction } from "../../action/logicAction";
export declare enum NodeType {
TreeNode = "TreeNode",
ContentNode = "ContentNode"
}
export type RawData<T> = {
id: string;
data: T;
};
export declare class Node<C = any> {
type: string;
content: C | undefined;
constructor(type: string);
setContent(content: C): this;
getContent(): C;
}
export type RenderableNode = ContentNode;
export type RenderableNodeData = ContentNodeData | TreeNodeData;
export type ContentNodeData = {
id: string;
data: any;
};
export declare class ContentNode<T = any> extends Node<T> {
static create<T>(content: T): ContentNode<T>;
static forEachParent(node: RenderableNode, callback: (node: RenderableNode) => void): void;
static forEachChild(node: RenderableNode, callback: (node: RenderableNode) => void): void;
action: LogicAction.Actions | null;
private child?;
private parent;
constructor(callee?: LogicAction.Actions, parent?: RenderableNode | null, child?: RenderableNode);
setParent(parent: RenderableNode | null): this;
setChild(child: RenderableNode | null): this;
getChild(): RenderableNode | null;
getParent(): RenderableNode | null;
/**
* Public method for setting the content of the node
* should only be called when changing the state in-game
*/
addChild(child: RenderableNode | null): this;
removeChild(child: RenderableNode | null): this;
/**
* Remove this node from the parent's children
*/
remove(): this;
hasChild(): boolean;
}
export declare class RootNode extends ContentNode {
constructor();
setParent(_: RenderableNode | null): this;
remove(): this;
forEach(callback: (node: RenderableNode) => void): void;
}
export type TreeNodeData = {
id: string;
data: any;
};