Handler
The Handler
class is responsible for handling messages and performing various actions on the context. It provides methods for handling single and multiple messages, getting the action handler, updating other nodes in the network, spawning and removing actors, updating actors with input, creating and removing entities, and manipulating components of entities.
Example Usage
// Create a new handler instanceconst handler = new Handler(context, options, actions);
// Handle a single messagehandler.one(message, extendOptions);
// Handle multiple messageshandler.many(messages, extendOptions);
// Get the action handlerconst [handler, symbol] = handler.getActionHandler(action, options);
// Get the symbol actionconst symbolAction = handler.getSymbolAction(action);
// Update other nodes in the networkhandler.updater(extendOptions, tick);
// Spawn an actorhandler.spawnActor(id, extendOptions);
// Despawn an actorhandler.removeActor(id, extendOptions);
// Update an actor with inputhandler.actorInput(id, input, tick, extendOptions);
// Create an entityhandler.createEntity(id, extendOptions);
// Remove an entityhandler.removeEntity(id, extendOptions);
// Set a component to an entityhandler.upsertComponent(id, key, value, tick, extendOptions);
// Change a component of an entityhandler.changeComponent(id, key, value, tick, extendOptions);
// Remove a component from an entityhandler.removeComponent(id, key, extendOptions);
// Query componentsconst components = handler.queryComponents(query);
Methods
one(message: Message | any[], extendOptions: Options | any)
: Handles a single message.many(message: Message | any[], extendOptions: Options | any)
: Handles multiple messages.getActionHandler(action: string | number): [Function, string]
: Gets the action handler.getSymbolAction(action: string | number): any
: Gets the symbol action.updater(extendOptions: OptionsProps | any, tick: number = now()): Promise<any[]>
: Updates other nodes in the network.spawnActor(id: string, extendOptions: OptionsProps | any): Promise<boolean> | boolean
: Spawns an actor.removeActor(id: string, extendOptions: OptionsProps | any): Promise<boolean> | boolean
: Despawns an actor.actorInput(id: string, input: any, tick: number = now(), extendOptions: OptionsProps | any): Promise<number> | number
: Updates an actor with an input.createEntity(id: string, extendOptions: OptionsProps | any): Promise<boolean> | boolean
: Creates an entity.removeEntity(id: string, extendOptions: OptionsProps | any): Promise<boolean> | boolean
: Removes an entity.upsertComponent(id: string, key: string, value: any, tick: number = now(), extendOptions: OptionsProps | any): Promise<any> | void
: Sets a component to an entity.changeComponent(id: string, key: string, value: any, tick: number = now(), extendOptions: OptionsProps | any): Promise<any> | void
: Changes a component of an entity.removeComponent(id: string, key: any, extendOptions: OptionsProps | any): Promise<boolean> | boolean
: Removes a component from an entity.queryComponents(query: any): Set<any>
: Queries components.
Fields
context: Context
: The context for the handler.options: Options
: The options for the handler.store: AsyncStorage | Storage
: The store for the context of the handler.