UNPKG

blueshell

Version:

A Behavior Tree implementation in modern Javascript

98 lines (97 loc) 2.99 kB
import { BlueshellState, NodeStorage, ResultCode, BaseNode } from '../models'; import { TreePublisher } from '../utils'; /** * Interface that defines what is stored in private node storage at the root */ export interface PrivateNodeStorage { debug: boolean; eventCounter: number | undefined; } /** * Base class of all Nodes. * @author Joshua Chaitin-Pollak */ export declare class Base<S extends BlueshellState, E> implements BaseNode<S, E> { readonly name: string; private _id; private _parent; static treePublisher: TreePublisher<any, any>; static registerTreePublisher<S extends BlueshellState, E>(publisher: TreePublisher<S, E>): void; static registerNodeForDebug<S extends BlueshellState, E>(node: BaseNode<S, E>): void; static unregisterNodeForDebug<S extends BlueshellState, E>(node: BaseNode<S, E>): void; /** * @constructor * @param name The name of the Node. If no name is given, the name of the Class will be used. */ constructor(name?: string); /** * Handles the Event, and invokes `onEvent(state, event)` * @param state The state when the event occured. * @param event The event to handle. * @protected */ handleEvent(state: S, event: E): ResultCode; /** * Return an empty object * @ignore * @param state * @param event */ protected _beforeEvent(state: S, event: E): {}; /** * Logging * @ignore * @param res * @param state * @param event */ protected _afterEvent(res: ResultCode, state: S, event: E): ResultCode; /** * Return true if this Node should proceed handling the event. false otherwise. * @param state * @param event */ protected precondition(state: S, event: E): boolean; /** * Invoked when there is a new event. * @param state * @param event * @return Result. Must be rc.SUCCESS, rc.FAILURE, or rc.RUNNING */ protected onEvent(state: S, event: E): ResultCode; set parent(path: string); get parent(): string; get id(): string; get path(): string; /** * Returns storage unique to this Node, keyed on the Node's path. * @param state */ getNodeStorage(state: S): NodeStorage; /** * Resets the storage unique to this Node, via the Node's path. * If this node is a parent, then also reset all children. * @param state */ resetNodeStorage(state: S): any; /** * @ignore * @param state */ protected _privateStorage(state: S): any; getDebug(state: S): any; getTreeEventCounter(state: S): any; /** * Getter for the previous event seen. * @param state */ getLastEventSeen(state: S): number | undefined; /** * Getter for the result of the last handled Event. * @param state */ getLastResult(state: S): string | undefined; get symbol(): string; } export { Base as Action }; export { Base as Condition };