Skip to content

Abstract

AbstractInput

class AbstractInput()

Abstract base class for [Input] implementations.

Inheriting from [AbstractInput] was chosen over Protocol, to provide better inferred type relation in subclasses:

handler: Input = Controller[MyAction]()
reveal_type(handler)  # type is: Input[MyAction]

Protocol would have yielded Input[Unknown].

An advantage to using an abstract base class, is partial default behaviour, like get_vector.

capture_states

@abstractmethod
def capture_states() -> None

Capture press state of all Action variants.

Used for monitoring changes over time.

Technical

Should be called at the start of the frame, before actions are checked for.

is_action_pressed

@abstractmethod
def is_action_pressed(action: Action) -> bool

is_action_just_pressed

@abstractmethod
def is_action_just_pressed(action: Action) -> bool

get_vector

def get_vector(
    negative_x: Action,
    positive_x: Action,
    negative_y: Action,
    positive_y: Action,
) -> Vec2