|
1 | 1 | """Contains everything related to input processing""" |
2 | 2 |
|
| 3 | +import logging |
3 | 4 | import sys |
4 | 5 | from collections import defaultdict |
5 | 6 | from enum import Enum, auto |
| 7 | +from typing import Optional |
6 | 8 |
|
| 9 | +from pokete.base.input import key |
7 | 10 | from pokete.util import liner |
8 | 11 |
|
9 | 12 | from .event import _ev |
@@ -60,7 +63,7 @@ class Action(Enum): |
60 | 63 | INTERACT = auto() |
61 | 64 |
|
62 | 65 | @property |
63 | | - def mapping(self): |
| 66 | + def mapping(self) -> str: |
64 | 67 | """Returns the current mapped char""" |
65 | 68 | return get_mapping(self, hotkey_mappings) |
66 | 69 |
|
@@ -102,7 +105,7 @@ def get_x_strength(self) -> int: |
102 | 105 | ACTION_DIRECTIONS = (Action.LEFT, Action.RIGHT, Action.UP, Action.DOWN) |
103 | 106 | ACTION_UP_DOWN = (Action.UP, Action.DOWN) |
104 | 107 |
|
105 | | -hotkey_mappings = { |
| 108 | +hotkey_mappings: dict[str, ActionList] = { |
106 | 109 | "1": ActionList([Action.ACT_1, Action.DECK, Action.CHOOSE_ATTACK]), |
107 | 110 | "2": ActionList( |
108 | 111 | [ |
@@ -167,12 +170,13 @@ def get_x_strength(self) -> int: |
167 | 170 | } |
168 | 171 |
|
169 | 172 |
|
170 | | -def get_mapping(action, keys): |
| 173 | +def get_mapping(action: Action, keys: dict[str, ActionList]) -> str: |
171 | 174 | """Returns the current mapped char""" |
172 | | - for key, actions_list in keys.items(): |
| 175 | + for _key, actions_list in keys.items(): |
173 | 176 | if action in actions_list: |
174 | | - return key |
175 | | - return None |
| 177 | + return _key |
| 178 | + logging.warning("Unset mapping for Action '%s'", action.name) |
| 179 | + return "" |
176 | 180 |
|
177 | 181 |
|
178 | 182 | def hotkeys_save(): |
@@ -227,13 +231,16 @@ def hotkeys_from_save(ctx, save, version_change): |
227 | 231 |
|
228 | 232 |
|
229 | 233 | # Returns an action, then clears input; all input is valid to read only once |
230 | | -def get_action() -> ActionList: |
| 234 | +def get_action() -> tuple[ActionList, Optional[key.Key]]: |
231 | 235 | """Returns the current actions list""" |
232 | 236 | retval = EMPTY_ACTIONLIST |
233 | 237 | raw_input = _ev.get() |
234 | | - if raw_input == "exit": |
| 238 | + if raw_input is None: |
| 239 | + return retval, None |
| 240 | + if raw_input == key.EXIT: |
235 | 241 | raise KeyboardInterrupt |
236 | | - if raw_input in hotkey_mappings: |
237 | | - retval = hotkey_mappings[raw_input] |
| 242 | + marshall_input = raw_input.marshall() |
| 243 | + if marshall_input in hotkey_mappings: |
| 244 | + retval = hotkey_mappings[marshall_input] |
238 | 245 | _ev.clear() |
239 | | - return retval |
| 246 | + return retval, raw_input |
0 commit comments