event_bus module

class core.gameCreation.event_bus.EventBus

Bases: object

A simple event bus for subscribing to and emitting events within the game.

classmethod emit(event_type, data)

Emit an event to all relevant subscribers.

If ‘position’ and ‘world’ are present in data, notifies entities at the position and those within line-of-sight. Otherwise, performs a global broadcast.

Parameters:
  • event_type (str) – The type of event to emit.

  • data (dict) – The event data, must be a dict. Should contain ‘position’ and ‘world’ for spatial events.

classmethod reset()

Reset the event bus, clearing all subscribers.

Emits a warning via the application logger.

classmethod subscribe(event_type, callback)

Subscribe a callback to a specific event type.

Parameters:
  • event_type (str) – The type of event to subscribe to.

  • callback (callable) – The function to call when the event is emitted.

classmethod unsubscribe(event_type, callback)

Unsubscribe a callback from a specific event type.

Parameters:
  • event_type (str) – The type of event to unsubscribe from.

  • callback (callable) – The function to remove from the subscriber list.