summaryrefslogtreecommitdiff
path: root/txtgameengine/input/callbacks.py
diff options
context:
space:
mode:
authorJonas Bernard <public.jbernard@web.de>2021-04-24 04:19:39 +0200
committerJonas Bernard <public.jbernard@web.de>2021-04-24 04:19:39 +0200
commita0a40e9259b9e8be4e677c8c29dfdfb89eb81ce8 (patch)
tree47768e46da3e6682acf6b72dddabaef78d0bfeb8 /txtgameengine/input/callbacks.py
parent635185baac3a2a9c5e50971d994ca7bcdec1d495 (diff)
downloadtxtgameengine-a0a40e9259b9e8be4e677c8c29dfdfb89eb81ce8.tar.gz
txtgameengine-a0a40e9259b9e8be4e677c8c29dfdfb89eb81ce8.tar.bz2
txtgameengine-a0a40e9259b9e8be4e677c8c29dfdfb89eb81ce8.zip
Progress at night
Diffstat (limited to 'txtgameengine/input/callbacks.py')
-rw-r--r--txtgameengine/input/callbacks.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/txtgameengine/input/callbacks.py b/txtgameengine/input/callbacks.py
new file mode 100644
index 0000000..476c103
--- /dev/null
+++ b/txtgameengine/input/callbacks.py
@@ -0,0 +1,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)