earwax.action_map module

Provides the ActionMap class.

class earwax.action_map.ActionMap

Bases: object

An object to hold actions.

This class is the answer to the question “What do I do when I have actions I want to be attached to multiple levels?”

You could of course use a for loop, but this class is quicker:

action_map: ActionMap = ActionMap()

@action_map.action(...)

@action_map.action(...)

level: Level = Level(game)
level.add_actions(action_map)
Variables:actions – The actions to be stored on this map.
action(title: str, symbol: Optional[int] = None, mouse_button: Optional[int] = None, modifiers: int = 0, joystick_button: Optional[int] = None, hat_direction: Optional[Tuple[int, int]] = None, interval: Optional[float] = None) → Callable[[Callable[[], Optional[Generator[None, None, None]]]], earwax.action.Action]

Add an action to this object.

For example:

@action_map.action(
    'Walk forwards', symbol=key.W, mouse_button=mouse.RIGHT,
    interval=0.5
)
def walk_forwards():
    # ...

It is possible to use a generator function to have code executed before and after a trigger fires. If you need this behaviour, see the documentation for the func attribute of earwax.Action.

Parameters:
  • title

    The title of the new action.

    This value is currently only used by earwax.ActionMenu.

  • symbol – The resulting action’s symbol attribute.
  • mouse_button – The resulting action’s mouse_button attribute.
  • modifiers – The resulting action’s modifiers attribute.
  • joystick_button – The resulting action’s joystick_button attribute.
  • hat_direction – The resulting action’s hat_direction attribute.
  • interval – The resulting action’s interval attribute.
add_actions(action_map: earwax.action_map.ActionMap) → None

Add the actions from the provided map to this map.

Parameters:action_map – The map whose actions should be appended to this one.