the low-hanging fruit of pre-existing issues and standardizing the
Python interfaces
Special thanks to Claude Code, ~100k output tokens for this merge
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
commit 99f301e3a0
Author: John McCardle <mccardle.john@gmail.com>
Date: Sat Jul 5 16:25:32 2025 -0400
Add position tuple support and pos property to UI elements
closes #83, closes #84
- Issue #83: Add position tuple support to constructors
- Frame and Sprite now accept both (x, y) and ((x, y)) forms
- Also accept Vector objects as position arguments
- Caption and Entity already supported tuple/Vector forms
- Uses PyVector::from_arg for flexible position parsing
- Issue #84: Add pos property to Frame and Sprite
- Added pos getter that returns a Vector
- Added pos setter that accepts Vector or tuple
- Provides consistency with Caption and Entity which already had pos properties
- All UI elements now have a uniform way to get/set positions as Vectors
Both features improve API consistency and make it easier to work with positions.
commit 2f2b488fb5
Author: John McCardle <mccardle.john@gmail.com>
Date: Sat Jul 5 16:18:10 2025 -0400
Standardize sprite_index property and add scale_x/scale_y to UISprite
closes #81, closes #82
- Issue #81: Standardized property name to sprite_index across UISprite and UIEntity
- Added sprite_index as the primary property name
- Kept sprite_number as a deprecated alias for backward compatibility
- Updated repr() methods to use sprite_index
- Updated animation system to recognize both names
- Issue #82: Added scale_x and scale_y properties to UISprite
- Enables non-uniform scaling of sprites
- scale property still works for uniform scaling
- Both properties work with the animation system
All existing code using sprite_number continues to work due to backward compatibility.
commit 5a003a9aa5
Author: John McCardle <mccardle.john@gmail.com>
Date: Sat Jul 5 16:09:52 2025 -0400
Fix multiple low priority issues
closes #12, closes #80, closes #95, closes #96, closes #99
- Issue #12: Set tp_new to NULL for GridPoint and GridPointState to prevent instantiation from Python
- Issue #80: Renamed Caption.size to Caption.font_size for semantic clarity
- Issue #95: Fixed UICollection repr to show actual derived types instead of generic UIDrawable
- Issue #96: Added extend() method to UICollection for API consistency with UIEntityCollection
- Issue #99: Exposed read-only properties for Texture (sprite_width, sprite_height, sheet_width, sheet_height, sprite_count, source) and Font (family, source)
All issues have corresponding tests that verify the fixes work correctly.
commit e5affaf317
Author: John McCardle <mccardle.john@gmail.com>
Date: Sat Jul 5 15:50:09 2025 -0400
Fix critical issues: script loading, entity types, and color properties
- 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
84 lines
No EOL
3.2 KiB
Python
84 lines
No EOL
3.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test for Issue #37: Windows scripts subdirectory not checked for .py files
|
|
|
|
This test checks if the game can find and load scripts/game.py from different working directories.
|
|
On Windows, this often fails because fopen uses relative paths without resolving them.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
import tempfile
|
|
import shutil
|
|
|
|
def test_script_loading():
|
|
# Create a temporary directory to test from
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
print(f"Testing from directory: {tmpdir}")
|
|
|
|
# Get the build directory (assuming we're running from the repo root)
|
|
build_dir = os.path.abspath("build")
|
|
mcrogueface_exe = os.path.join(build_dir, "mcrogueface")
|
|
if os.name == "nt": # Windows
|
|
mcrogueface_exe += ".exe"
|
|
|
|
# Create a simple test script that the game should load
|
|
test_script = """
|
|
import mcrfpy
|
|
print("TEST SCRIPT LOADED SUCCESSFULLY")
|
|
mcrfpy.createScene("test_scene")
|
|
"""
|
|
|
|
# Save the original game.py
|
|
game_py_path = os.path.join(build_dir, "scripts", "game.py")
|
|
game_py_backup = game_py_path + ".backup"
|
|
if os.path.exists(game_py_path):
|
|
shutil.copy(game_py_path, game_py_backup)
|
|
|
|
try:
|
|
# Replace game.py with our test script
|
|
os.makedirs(os.path.dirname(game_py_path), exist_ok=True)
|
|
with open(game_py_path, "w") as f:
|
|
f.write(test_script)
|
|
|
|
# Test 1: Run from build directory (should work)
|
|
print("\nTest 1: Running from build directory...")
|
|
result = subprocess.run(
|
|
[mcrogueface_exe, "--headless", "-c", "print('Test 1 complete')"],
|
|
cwd=build_dir,
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=5
|
|
)
|
|
if "TEST SCRIPT LOADED SUCCESSFULLY" in result.stdout:
|
|
print("✓ Test 1 PASSED: Script loaded from build directory")
|
|
else:
|
|
print("✗ Test 1 FAILED: Script not loaded from build directory")
|
|
print(f"stdout: {result.stdout}")
|
|
print(f"stderr: {result.stderr}")
|
|
|
|
# Test 2: Run from temporary directory (often fails on Windows)
|
|
print("\nTest 2: Running from different working directory...")
|
|
result = subprocess.run(
|
|
[mcrogueface_exe, "--headless", "-c", "print('Test 2 complete')"],
|
|
cwd=tmpdir,
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=5
|
|
)
|
|
if "TEST SCRIPT LOADED SUCCESSFULLY" in result.stdout:
|
|
print("✓ Test 2 PASSED: Script loaded from different directory")
|
|
else:
|
|
print("✗ Test 2 FAILED: Script not loaded from different directory")
|
|
print(f"stdout: {result.stdout}")
|
|
print(f"stderr: {result.stderr}")
|
|
print("\nThis is the bug described in Issue #37!")
|
|
|
|
finally:
|
|
# Restore original game.py
|
|
if os.path.exists(game_py_backup):
|
|
shutil.move(game_py_backup, game_py_path)
|
|
|
|
if __name__ == "__main__":
|
|
test_script_loading() |