Event Handling
Event
Event Handler
- class BBEventHandler(mod_identity, event_type, handler)
Bases:
objectHandles events when they occur.
- Parameters:
mod_identity (Union[str, BBModIdentity]) – The identity of the mod that owns this handler.
event_type (Type[BBEvent]) – The type of event being handled.
handler (Callable[[BBEvent], BBRunResult]) – The function that handles events.
- Raises:
RuntimeError – When event_function is None.
TypeError – When event_function is not a callable function.
AssertionError – When the event_function is missing the event_data argument, when the event_function contains a self or cls argument, or when more than one argument is found.
- property event_type
The type of events this handler waits for.
- Returns:
An event type.
- Return type:
Type[BBEvent]
- property handler
The function invoked when the handler handles an event.
- Returns:
A function invoked upon handling events.
- Return type:
Callable[[BBEvent], BBRunResult]
- property mod_identity
The identity of the mod that owns this handler.
- Returns:
A mod identity.
- Return type:
Event Handler Registry
- class BBEventHandlerRegistry(*args, **kwargs)
Bases:
objectRegister event handlers and dispatch events to those handlers. Usage: @BBEventHandlerRegistry().register(ModIdentity(), BBEvent()) def _bbl_handle_on_zone_load_event(event: BBEvent):
@BBEventHandlerRegistry().register(ModIdentity(), BBEvent()) def _bbl_handle_on_zone_load_event(event: BBEvent):
- dispatch(event)
Dispatch an event to all listening handlers.
- Parameters:
event (BBEvent) – An event to dispatch.
- Returns:
The result of dispatching the event.
- Return type:
- static register(mod_identity, event_type)
Register a function as a handler of events.
- Parameters:
mod_identity (BBModIdentity) – The identity of the mod that owns the handler.
event_type (Type[BBEvent]) – The type of event being handled.
- Returns:
A function that will handle events.
- Return type:
Callable[[Callable[[BBEvent], TestResult]], Callable[[BBEvent], TestResult]]
- register_handler(mod_identity, event_type, handler)
Register a handler of events.
- Parameters:
mod_identity (BBModIdentity) – The identity of the mod that owns the handler.
event_type (Type[BBEvent]) – The type of events to be handled.
handler (Callable[[BBEvent], TestResult]) – A function listening for events.
- Returns:
An event handler that will receive events.
- Return type:
- unregister_handler(event_handler)
Unregister a handler manually from receiving events.
- Parameters:
event_handler (BBEventHandler) – The event handler being unregistered.