- Issue #37: Fix Windows scripts subdirectory not checked - Updated executeScript() to use executable_path() from platform.h - Scripts now load correctly when working directory differs from executable - Issue #76: Fix UIEntityCollection returns wrong type - Updated UIEntityCollectionIter::next() to check for stored Python object - Derived Entity classes now preserve their type when retrieved from collections - Issue #9: Recreate RenderTexture when resized (already fixed) - Confirmed RenderTexture recreation already implemented in set_size() and set_float_member() - Uses 1.5x padding and 4096 max size limit - Issue #79: Fix Color r, g, b, a properties return None - Implemented get_member() and set_member() in PyColor.cpp - Color component properties now work correctly with proper validation - Additional fix: Grid.at() method signature - Changed from METH_O to METH_VARARGS to accept two arguments All fixes include comprehensive tests to verify functionality. closes #37, closes #76, closes #9, closes #79 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
63 lines
No EOL
2.2 KiB
Python
63 lines
No EOL
2.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Example automation script using --exec flag
|
|
Usage: ./mcrogueface game.py --exec example_automation.py
|
|
"""
|
|
import mcrfpy
|
|
from mcrfpy import automation
|
|
|
|
class GameAutomation:
|
|
def __init__(self):
|
|
self.frame_count = 0
|
|
self.test_phase = 0
|
|
print("Automation: Initialized")
|
|
|
|
def periodic_test(self):
|
|
"""Called every second to perform automation tasks"""
|
|
self.frame_count = mcrfpy.getFrame()
|
|
|
|
print(f"Automation: Running test at frame {self.frame_count}")
|
|
|
|
# Take periodic screenshots
|
|
if self.test_phase % 5 == 0:
|
|
filename = f"automation_screenshot_{self.test_phase}.png"
|
|
automation.screenshot(filename)
|
|
print(f"Automation: Saved {filename}")
|
|
|
|
# Simulate user input based on current scene
|
|
scene = mcrfpy.currentScene()
|
|
print(f"Automation: Current scene is '{scene}'")
|
|
|
|
if scene == "main_menu" and self.test_phase < 5:
|
|
# Click start button
|
|
automation.click(512, 400)
|
|
print("Automation: Clicked start button")
|
|
elif scene == "game":
|
|
# Perform game actions
|
|
if self.test_phase % 3 == 0:
|
|
automation.hotkey("i") # Toggle inventory
|
|
print("Automation: Toggled inventory")
|
|
else:
|
|
# Random movement
|
|
import random
|
|
key = random.choice(["w", "a", "s", "d"])
|
|
automation.keyDown(key)
|
|
automation.keyUp(key)
|
|
print(f"Automation: Pressed '{key}' key")
|
|
|
|
self.test_phase += 1
|
|
|
|
# Stop after 20 tests
|
|
if self.test_phase >= 20:
|
|
print("Automation: Test suite complete")
|
|
mcrfpy.delTimer("automation_test")
|
|
# Could also call mcrfpy.quit() to exit the game
|
|
|
|
# Create automation instance
|
|
automation_instance = GameAutomation()
|
|
|
|
# Register periodic timer
|
|
mcrfpy.setTimer("automation_test", automation_instance.periodic_test, 1000)
|
|
|
|
print("Automation: Script loaded - tests will run every second")
|
|
print("Automation: The game and automation share the same Python environment") |