EventPlugin

View source

ExtendsPlugin

Registers one typed Events resource with an ECS App.

The configured payload constructor identifies both the Events resource and this plugin instance. By default, pending events become readable automatically after each application update. Set autoClearEvent to false and call Events#clear when the application wants to publish a batch. Use one plugin instance for each payload constructor that the app publishes.

Examples

import { App } from '@wimaengine/app'
import { CorePlugin } from '@wimaengine/core'
import { EventPlugin } from '@wimaengine/event'
import { ReflectPlugin } from '@wimaengine/reflect'

class DamageEvent {}

const app = new App()
app
  .registerPlugin(new ReflectPlugin())
  .registerPlugin(new CorePlugin())
  .registerPlugin(new EventPlugin({ event: DamageEvent }))
  .run()

Constructor


constructor<T>(options: EventPluginOptions<T>)

View source

Creates an event plugin for one payload constructor.

EventPlugin#autoClearEvent defaults to true. The configured Events resource is staged when the plugin is registered with an app.

Type Parameters

T

Parameters

NameDescriptionDefault
options

Event constructor and optional automatic-clear setting.

—

Properties


readonlyevent: Constructor<T>

View source

Constructor for the payload represented by this plugin.

The constructor identifies the payload type for this plugin’s typed Events resource and contributes to the plugin’s identity.

readonlyautoClearEvent: boolean

View source

Whether pending events are published automatically after each application update.

This defaults to true. When false, application code controls when pending events become readable by calling Events#clear.

Methods


register(app: App): void

View source

Registers this plugin’s typed Events resource with an app.

The method stages an empty Events resource for the configured payload constructor in the app’s default world.

If EventPlugin#autoClearEvent is enabled, pending events are published automatically after each application update. With the option disabled, application code decides when to call Events#clear.

Parameters

NameDescriptionDefault
app

App to configure.

—

requires(): TypeId[]

View source

Returns the plugin dependencies required by this plugin.

The app checks these IDs before final setup. Register CorePlugin and ReflectPlugin before this plugin; registering EventPlugin does not install them automatically.

Returns

Required plugin TypeId values.

name(): TypeId

View source

Returns this plugin’s identity for its configured event payload.

Event plugins configured with different payload constructors have distinct identities. Registering a second plugin for the same payload constructor is rejected by the app.

Returns

Generic plugin TypeId.