You can create "collections" of events that you can use to freely attach to rooms and perspectives using the EventTarget API.
export class ReducedStew extends EventTarget {
@EventListener("player.murder")
onPlayerMurderEvent(ev: PlayerMurderEvent<Room>) {
}
}
You can use registerEventTarget choose where to apply an event target:
const reducedStewTarget = new ReducedStew;
room.registerEventTarget(reducedStewTarget);
const perspective = room.createPerspective(player);
perspective.registerEventTarget(reducedStewTarget);
Removing an event target is as simple as calling removeEventTarget:
room.removeEventTarget(reducedStewTarget);
For example, if you want to remove an event target when the game ends, you can use:
export class ReducedStew extends EventTarget {
@EventListener("room.gameend")
onRoomGameEnd(ev: RoomGameEndEvent) {
ev.room.removeEventTarget(this);
}
}
The constuctor can be anything you like, useful for creating connections to your main plugin or perspective:
export class ReducedStew extends EventTarget {
constructor(
public readonly myPlugin: ReducedStewPlugin
) {
super();
}
}
const reducedStewTarget = new ReducedStew(this);
Generated using TypeDoc