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:
John McCardle 2026-04-09 22:19:02 -04:00
commit 6d5e99a114
52 changed files with 372 additions and 533 deletions

View file

@ -17,12 +17,12 @@ def test_click_callback_signature(pos, button, action):
results.append(("on_click pos is Vector", False))
print(f"FAIL: on_click receives {type(pos).__name__} instead of Vector: {pos}")
# Verify button and action types
if isinstance(button, str) and isinstance(action, str):
results.append(("on_click button/action are strings", True))
# Verify button and action types (enums since #306)
if isinstance(button, mcrfpy.MouseButton) and isinstance(action, mcrfpy.InputState):
results.append(("on_click button/action are enums", True))
print(f"PASS: button={button!r}, action={action!r}")
else:
results.append(("on_click button/action are strings", False))
results.append(("on_click button/action are enums", False))
print(f"FAIL: button={type(button).__name__}, action={type(action).__name__}")
# #230 - Hover callbacks now receive only (pos), not (pos, button, action)
@ -112,7 +112,7 @@ print("\n--- Simulating callback calls ---")
# Test that the callbacks are set up correctly
# on_click still takes (pos, button, action)
test_click_callback_signature(mcrfpy.Vector(150, 150), "left", "start")
test_click_callback_signature(mcrfpy.Vector(150, 150), mcrfpy.MouseButton.LEFT, mcrfpy.InputState.PRESSED)
# #230 - Hover callbacks now take only (pos)
test_on_enter_callback_signature(mcrfpy.Vector(100, 100))
test_on_exit_callback_signature(mcrfpy.Vector(300, 300))