escapy.messages
Message providers that map game events to human-readable strings.
Warning
The default dict_message_provider() keys messages by repr(event).
This means that adding, removing, or reordering fields on an event
dataclass will silently invalidate existing message dictionaries. Users
must rebuild their message keys whenever the event schema changes.
- type escapy.messages.MessageProvider = Callable[[Event], str | None]
A callable that returns a display string for an event, or
None.
- escapy.messages.dict_message_provider(messages)[source]
Create a
MessageProviderbacked by a dictionary.Event instances are looked up by their
repr()string. If no matching entry exists,Noneis returned.Note
Because keys are
repr()strings, they are tightly coupled to the exact field names and order of each event dataclass. If the library adds a field to an event in a future release, all dictionary entries for that event type will stop matching. Build your dictionaries by usingrepr()on actual event instances rather than hand-writing the strings:from escapy.events import PickedUpEvent messages = { repr(PickedUpEvent("key")): "You found a rusty key!", }
- Parameters:
messages (dict[str, str]) – Mapping from
repr(event)strings to message text.- Returns:
A
MessageProvidercallable.- Return type: