90 lines
3.4 KiB
Python
90 lines
3.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Test for registerPyAction - Related to issue #2 (review necessity)"""
|
|
import mcrfpy
|
|
from mcrfpy import automation
|
|
from datetime import datetime
|
|
|
|
action_calls = {"test_action": 0, "another_action": 0}
|
|
|
|
def test_action_handler():
|
|
"""Handler for test_action"""
|
|
action_calls["test_action"] += 1
|
|
print(f"test_action called: {action_calls['test_action']} times")
|
|
|
|
def another_action_handler():
|
|
"""Handler for another_action"""
|
|
action_calls["another_action"] += 1
|
|
print(f"another_action called: {action_calls['another_action']} times")
|
|
|
|
def test_registerPyAction():
|
|
"""Test registerPyAction functionality (Alpha Blocker Issue #2)"""
|
|
print("Testing registerPyAction (Issue #2 - Review necessity)...")
|
|
print("This is marked as an Alpha Blocker - may need removal")
|
|
|
|
# Register actions
|
|
try:
|
|
mcrfpy.registerPyAction("test_action", test_action_handler)
|
|
print("✓ Registered test_action")
|
|
|
|
mcrfpy.registerPyAction("another_action", another_action_handler)
|
|
print("✓ Registered another_action")
|
|
except Exception as e:
|
|
print(f"✗ registerPyAction failed: {e}")
|
|
print("FAIL")
|
|
return
|
|
|
|
# Test registerInputAction to map keys to actions
|
|
try:
|
|
# These are SFML key codes - may need adjustment
|
|
mcrfpy.registerInputAction(0, "test_action") # Key A
|
|
mcrfpy.registerInputAction(1, "another_action") # Key B
|
|
print("✓ Registered input mappings")
|
|
except Exception as e:
|
|
print(f"✗ registerInputAction failed: {e}")
|
|
|
|
# Note: In headless mode, we can't easily trigger these actions
|
|
# They would normally be triggered by keyboard input
|
|
|
|
print("\nAnalysis for Issue #2:")
|
|
print("- registerPyAction allows mapping string names to Python callbacks")
|
|
print("- registerInputAction maps keyboard codes to action strings")
|
|
print("- This creates a two-step indirection: key -> action string -> callback")
|
|
print("- Modern approach might be direct key -> callback mapping")
|
|
print("- Or use keypressScene() for all keyboard handling")
|
|
|
|
# Try to trigger actions programmatically if possible
|
|
# This depends on internal implementation
|
|
|
|
def check_results(runtime):
|
|
print(f"\nAction call counts:")
|
|
print(f"- test_action: {action_calls['test_action']}")
|
|
print(f"- another_action: {action_calls['another_action']}")
|
|
|
|
if action_calls["test_action"] > 0 or action_calls["another_action"] > 0:
|
|
print("✓ Actions were triggered")
|
|
else:
|
|
print("✗ No actions triggered (expected in headless mode)")
|
|
|
|
# Take screenshot
|
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
filename = f"test_registerPyAction_issue2_{timestamp}.png"
|
|
automation.screenshot(filename)
|
|
print(f"Screenshot saved: {filename}")
|
|
print("PASS - Test completed, Issue #2 needs review for removal")
|
|
|
|
mcrfpy.delTimer("check_results")
|
|
|
|
# In headless mode, run synchronously
|
|
print("\nAction call counts:")
|
|
print(f"- test_action: {action_calls['test_action']}")
|
|
print(f"- another_action: {action_calls['another_action']}")
|
|
|
|
print("✗ No actions triggered (expected in headless mode)")
|
|
print("PASS - Test completed, Issue #2 needs review for removal")
|
|
|
|
# Run test directly in headless mode
|
|
test_registerPyAction()
|
|
|
|
# Exit cleanly
|
|
import sys
|
|
sys.exit(0) |