tuxemon.event.eventengine module
- class tuxemon.event.eventengine.EventEngine(session)[source]
Bases:
object
A class for the event engine. The event engine checks to see if a group of conditions have been met and then executes a set of actions.
Actions in the same MapEvent are not run concurrently, and they can be run over one or several frames. Currently this engine is run in the context of a single map.
Any actions or conditions executed on one map will be reset when the map is changed.
- Parameters:
session (Session) – Object containing the session information.
- check_condition(cond_data)[source]
Check if condition is true of false.
Returns
False
if the condition is not loaded properly.- Parameters:
cond_data (MapCondition) – The condition to check.
- Returns:
The value of the condition.
- Return type:
bool
- check_conditions()[source]
Checks conditions. If any are satisfied, start the MapActions.
Actions may be started during this function.
- Return type:
None
- execute_action(action_name, parameters=None)[source]
Load and execute an action.
This will cause the game to hang if an action waits on game changes.
- Parameters:
action_name (str) – Name of the action.
parameters (Sequence[Any] | None) – Parameters of the action.
- Return type:
None
- get_action(name, parameters=None)[source]
Get an action that is loaded into the engine.
A new instance will be returned each time.
Return
None
if action is not loaded.- Parameters:
name (str) – Name of the action.
parameters (Optional[Sequence[Any]]) – List of parameters that the action accepts.
- Returns:
New instance of the action with the appropriate parameters if that action is loaded.
None
otherwise.- Return type:
Optional[EventAction[Any]]
- get_actions()[source]
Return list of EventActions.
- Return type:
List[Type[EventAction]]
- get_condition(name)[source]
Get a condition that is loaded into the engine.
A new instance will be returned each time.
Return
None
if condition is not loaded.- Parameters:
name (str) – Name of the condition.
- Returns:
New instance of the condition if that condition is loaded.
None
otherwise.- Return type:
EventCondition | None
- get_conditions()[source]
Return list of EventConditions.
- Return type:
List[Type[EventCondition]]
- process_event(event)[source]
Handles player input events.
This function is only called when the player provides input such as pressing a key or clicking the mouse.
Since this is part of a chain of event handlers, the return value from this method becomes input for the next one. Returning
None
signifies that this method has dealt with an event and wants it exclusively. Return the event and others can use it as well.You should return
None
if you have handled input here.- Parameters:
event (PlayerInput) – The event received.
- Returns:
The input event, or
None
to prevent others to receive it.- Return type:
PlayerInput | None
- process_map_event(map_event)[source]
Check the conditions of an event, and execute actions they are met.
Actions will be started, but may finish much later.
- Parameters:
map_event (EventObject) – Event to process.
- Return type:
None
- process_map_events(events)[source]
Process all events in an iterable.
Simple now, may become more complex.
- Parameters:
events (Iterable[EventObject]) – Iterable of events to process.
- Return type:
None
- start_event(map_event)[source]
Begins execution of action list. Conditions are not checked.
- Parameters:
map_event (EventObject) – Event whose actions will be executed.
- Return type:
None
- class tuxemon.event.eventengine.RunningEvent(map_event)[source]
Bases:
object
Manage MapEvents that are used during gameplay.
Running events are considered to have all conditions satisfied. Once started, they will eventually execute all actions of the MapEvent. RunningEvents do not preserve state between calls or maps.
RunningEvents have an action_index. The action_index is the index of the action list of the action currently running. The current_action attribute is the instance of the running action.
Actions being managed by the RunningEvent class can share information using the context dictionary.
- Parameters:
map_event (EventObject) – Event defined in the map containing the information about the actions.
- action_index
- context: Dict[str, Any]
- current_action: EventAction[Any] | None
- current_map_action
- get_next_action()[source]
Get the next action to execute, if any.
Returns MapActions, which are just data from the map, not live objects.
None
will be returned if the MapEvent is finished.- Returns:
Next action to execute.
None
if there isn’t one.- Return type:
MapAction | None
- map_event
- tuxemon.event.eventengine.add_error_context(event, item, session)[source]
Add error information about the involved condition or action.
This should be used as a context manager for code that may fail associated with a particular condition or action.
- Parameters:
event (EventObject) – Event associated with the condition or action.
item (MapCondition | MapAction) – Condition or action that produces the error.
session (Session) – Object containing the session information.
- Return type:
Generator[None, None, None]