event
FreeBodyEngine.core.event
#
Event(name, *categories)
#
A named, categorized event and the set of callbacks currently
registered to run when it's emitted (see EventManager).
Creates an event named name filed under categories, with no callbacks yet.
EventManager()
#
Bases: Service
The engine's central pub/sub event bus (registered as the "event"
service). An event must be registered (register_event), and optionally
filed under one or more registered categories (register_category),
before callbacks can be attached to it or it can be emitted.
Sets up empty event and category registries.
categories = {}
instance-attribute
#
category_map = {}
instance-attribute
#
events = {}
instance-attribute
#
emit(event, *callback_args, **callback_kwargs)
#
Invokes every callback registered on event with the given
arguments, warning instead if event isn't registered.
query_events(query)
#
Parses query (whitespace-separated selector tokens) and returns
the matching registered Event objects, deduplicated.
Each token may combine:
- #name - selects the event with this exact name.
- ?substring - selects every event whose name contains this substring.
- @category - alongside a #/? selector, restricts those matches
to events filed under this category (repeatable within a token).
A token combining a #name selector with a ?substring selector
(or more than one of either) is invalid and only triggers a
warning - nothing is added for it. A token that is only @category
selector(s), with no #/? name selector, falls back to walking
every registered category rather than filtering to the ones named
in the token.
register_callback(event_name, callable)
#
Registers callable to run whenever event_name is emitted,
warning instead if event_name isn't a registered event at all, or
if callable is already registered on it.
register_category(name, priority=0)
#
Registers a new event category named name at priority,
warning instead if it already exists.
register_event(name, *categorys)
#
Registers a new event named name, filed under categorys (each
of which must already be a registered category - see
register_category).
Warns and aborts without ever creating the event if name is
already taken, or if any of categorys isn't a registered category
- in the latter case, any categories checked before the missing one
will already have had name appended to their category_map
entry, since the abort happens mid-loop.
unregister_callback(event_name, callable)
#
Unregisters callable from event_name's callbacks, warning
instead if event_name isn't a registered event at all, or if
callable isn't currently registered on it.
unregister_event(name)
#
Unregisters the event named name, warning instead if it doesn't
exist.
Note: this reads self.events[name].category, but Event only
defines a categories attribute - as written, this raises
AttributeError whenever name does exist.