tuxemon.platform.events module
- class tuxemon.platform.events.EventQueueHandler[source]
Bases:
ABC
Event QueueHandler for different platforms.
Only one per game
Sole manager of platform events of type
- abstract process_events()[source]
Process all pygame events.
Should never return pygame-unique events
All events returned should be Tuxemon game specific
This must be the only function to get events from the pygame event queue
- Yields:
Game events.
- Return type:
Generator[PlayerInput, None, None]
- release_controls()[source]
Send virtual input events which release held buttons/axis.
After this frame, held/triggered inputs will return to previous state.
- Yields:
Inputs to release all buttons.
- Return type:
Generator[PlayerInput, None, None]
- class tuxemon.platform.events.InputHandler(event_map=None)[source]
Bases:
ABC
,Generic
[_InputEventType
]Enables basic input device with discrete inputs.
- Parameters:
event_map – Mapping of original identifiers to button identifiers.
- default_input_map: ClassVar[Mapping[int | None, int]]
- get_events()[source]
Update the input state (holding time, etc.) and return player inputs.
- Yields:
Player inputs (before updating their state).
- Return type:
Generator[PlayerInput, None, None]
- press(button, value=1)[source]
Press a button managed by this handler.
- Parameters:
button (int) – Identifier of the button to press.
value (float) – Intensity value used for pressing the button.
- Return type:
None
- abstract process_event(input_event)[source]
Process an input event, such as a Pygame event.
- Parameters:
input_event (_InputEventType) – Input event to process.
- Return type:
None
- release(button)[source]
Release a button managed by this handler.
- Parameters:
button (int) – Identifier of the button to release.
- Return type:
None
- virtual_stop_events()[source]
Send virtual input events simulating released buttons/axis. This is used to force a state to release inputs without changing input state.
- Yields:
Inputs to release all buttons of this handler.
- Return type:
Generator[PlayerInput, None, None]
- class tuxemon.platform.events.PlayerInput(button, value=0, hold_time=0)[source]
Bases:
object
Represents a single player input.
Each instance represents the state of a single input: * have float value 0-1 * are “pressed” when value is above 0, for exactly one frame * are “held” when “pressed” for longer than zero frames Do not manipulate these values. Once created, these objects will not be destroyed. Input managers will set values on these objects. These objects are reused between frames, do not hold references to them.
- Parameters:
button (int) – Identifier of the button that caused this input.
value (Any) – Value associated with the event. For buttons it is the intensity of the press in the range [0, 1]. 0 is not pressed and 1 is fully pressed. Some inputs, such as analog sticks may support intermediate or negative values. Other input may store the unicode key pressed, or the mouse coordinates.
hold_time (int) – The number of frames this input has been hold.
- button
- property held: bool
This will be true as long as button is held down.
- Returns:
Whether the input is being hold.
- hold_time
- property pressed: bool
This is edge triggered, meaning it will only be true once!
- Returns:
Whether the input has been pressed.
- triggered
- value