summaryrefslogtreecommitdiff
path: root/txtgameengine/input/callbacks.py
blob: 476c10364f3dfe62cb14b2d7466dd2f06f426d72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import typing
from .keyboard import ModKey, KeyboardCallback, KeyboardEvent, KeyboardCallbackBuilder

if typing.TYPE_CHECKING:
    from ..app import TxtGameApp


class CallbackHandler:
    def __init__(self, app: 'TxtGameApp'):
        self.app = app
        self.keyboard_callbacks: typing.List[KeyboardCallback] = []

    def register_keyboard_callback(self, callback: KeyboardCallback):
        self.keyboard_callbacks.append(callback)

    def get_keyboard_input_callback(self, window: typing.Any, keycode: int, scancode: int, action: int, mod_keys: int):
        event = KeyboardEvent(window, keycode, scancode, action, ModKey(mod_keys))
        for callback in self.keyboard_callbacks:
            if event.mod_keys == callback.required_mod_keys:
                continue

            callback.callback(event)

    def get_mouse_move_callback(self, window: typing.Any, pos_x: float, pos_y: float):
        pass

    def get_mouse_click_callback(self, window: typing.Any, button: int, action: int, mod_keys: int):
        pass

    def keyboard_callback(self) -> KeyboardCallbackBuilder:
        return KeyboardCallbackBuilder(self.app)