Remove legacy string enum comparisons from InputState/Key/MouseButton, closes #306
Removed custom __eq__/__ne__ that allowed comparing enums to legacy string names (e.g., Key.ESCAPE == "Escape"). Removed _legacy_names dicts and to_legacy_string() functions. Kept from_legacy_string() in PyKey.cpp as it's used by C++ event dispatch. Updated ~50 Python test/demo/cookbook files to use enum members instead of string comparisons. Also updates grid.position -> grid.pos in files that had both types of changes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
354faca838
commit
6d5e99a114
52 changed files with 372 additions and 533 deletions
|
|
@ -146,21 +146,24 @@ class DemoRunner:
|
|||
self.create_menu()
|
||||
|
||||
def handle_key(key, state):
|
||||
if state != "start":
|
||||
if state != mcrfpy.InputState.PRESSED:
|
||||
return
|
||||
|
||||
# Number keys 1-9 for direct screen access
|
||||
if key in [f"Num{n}" for n in "123456789"]:
|
||||
idx = int(key[-1]) - 1
|
||||
_num_key_map = {mcrfpy.Key.NUM_1: 0, mcrfpy.Key.NUM_2: 1, mcrfpy.Key.NUM_3: 2,
|
||||
mcrfpy.Key.NUM_4: 3, mcrfpy.Key.NUM_5: 4, mcrfpy.Key.NUM_6: 5,
|
||||
mcrfpy.Key.NUM_7: 6, mcrfpy.Key.NUM_8: 7, mcrfpy.Key.NUM_9: 8}
|
||||
if key in _num_key_map:
|
||||
idx = _num_key_map[key]
|
||||
if idx < len(self.screens):
|
||||
mcrfpy.setScene(self.screens[idx].scene_name)
|
||||
|
||||
# ESC returns to menu
|
||||
elif key == "Escape":
|
||||
elif key == mcrfpy.Key.ESCAPE:
|
||||
menu.activate()
|
||||
|
||||
# Q quits
|
||||
elif key == "Q":
|
||||
elif key == mcrfpy.Key.Q:
|
||||
sys.exit(0)
|
||||
|
||||
# Register keyboard handler on menu scene
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue