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
228 lines
No EOL
7.7 KiB
Python
228 lines
No EOL
7.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test for Issue #84: Add pos property to Frame and Sprite
|
|
|
|
This test verifies that Frame and Sprite now have a 'pos' property that
|
|
returns and accepts Vector objects, similar to Caption and Entity.
|
|
"""
|
|
|
|
import mcrfpy
|
|
import sys
|
|
|
|
def test_frame_pos_property():
|
|
"""Test pos property on Frame"""
|
|
print("=== Testing Frame pos Property ===")
|
|
|
|
tests_passed = 0
|
|
tests_total = 0
|
|
|
|
# Test 1: Get pos property
|
|
tests_total += 1
|
|
try:
|
|
frame = mcrfpy.Frame(10, 20, 100, 50)
|
|
pos = frame.pos
|
|
if hasattr(pos, 'x') and hasattr(pos, 'y') and pos.x == 10 and pos.y == 20:
|
|
print(f"✓ PASS: frame.pos returns Vector({pos.x}, {pos.y})")
|
|
tests_passed += 1
|
|
else:
|
|
print(f"✗ FAIL: frame.pos incorrect: {pos}")
|
|
except AttributeError as e:
|
|
print(f"✗ FAIL: pos property not accessible: {e}")
|
|
|
|
# Test 2: Set pos with Vector
|
|
tests_total += 1
|
|
try:
|
|
vec = mcrfpy.Vector(30, 40)
|
|
frame.pos = vec
|
|
if frame.x == 30 and frame.y == 40:
|
|
print(f"✓ PASS: frame.pos = Vector sets position correctly")
|
|
tests_passed += 1
|
|
else:
|
|
print(f"✗ FAIL: pos setter failed: x={frame.x}, y={frame.y}")
|
|
except Exception as e:
|
|
print(f"✗ FAIL: pos setter with Vector error: {e}")
|
|
|
|
# Test 3: Set pos with tuple
|
|
tests_total += 1
|
|
try:
|
|
frame.pos = (50, 60)
|
|
if frame.x == 50 and frame.y == 60:
|
|
print(f"✓ PASS: frame.pos = tuple sets position correctly")
|
|
tests_passed += 1
|
|
else:
|
|
print(f"✗ FAIL: pos setter with tuple failed: x={frame.x}, y={frame.y}")
|
|
except Exception as e:
|
|
print(f"✗ FAIL: pos setter with tuple error: {e}")
|
|
|
|
# Test 4: Verify pos getter reflects changes
|
|
tests_total += 1
|
|
try:
|
|
frame.x = 70
|
|
frame.y = 80
|
|
pos = frame.pos
|
|
if pos.x == 70 and pos.y == 80:
|
|
print(f"✓ PASS: pos property reflects x/y changes")
|
|
tests_passed += 1
|
|
else:
|
|
print(f"✗ FAIL: pos doesn't reflect changes: {pos.x}, {pos.y}")
|
|
except Exception as e:
|
|
print(f"✗ FAIL: pos getter after change error: {e}")
|
|
|
|
return tests_passed, tests_total
|
|
|
|
def test_sprite_pos_property():
|
|
"""Test pos property on Sprite"""
|
|
print("\n=== Testing Sprite pos Property ===")
|
|
|
|
tests_passed = 0
|
|
tests_total = 0
|
|
|
|
texture = mcrfpy.Texture("assets/kenney_tinydungeon.png", 16, 16)
|
|
|
|
# Test 1: Get pos property
|
|
tests_total += 1
|
|
try:
|
|
sprite = mcrfpy.Sprite(10, 20, texture, 0, 1.0)
|
|
pos = sprite.pos
|
|
if hasattr(pos, 'x') and hasattr(pos, 'y') and pos.x == 10 and pos.y == 20:
|
|
print(f"✓ PASS: sprite.pos returns Vector({pos.x}, {pos.y})")
|
|
tests_passed += 1
|
|
else:
|
|
print(f"✗ FAIL: sprite.pos incorrect: {pos}")
|
|
except AttributeError as e:
|
|
print(f"✗ FAIL: pos property not accessible: {e}")
|
|
|
|
# Test 2: Set pos with Vector
|
|
tests_total += 1
|
|
try:
|
|
vec = mcrfpy.Vector(30, 40)
|
|
sprite.pos = vec
|
|
if sprite.x == 30 and sprite.y == 40:
|
|
print(f"✓ PASS: sprite.pos = Vector sets position correctly")
|
|
tests_passed += 1
|
|
else:
|
|
print(f"✗ FAIL: pos setter failed: x={sprite.x}, y={sprite.y}")
|
|
except Exception as e:
|
|
print(f"✗ FAIL: pos setter with Vector error: {e}")
|
|
|
|
# Test 3: Set pos with tuple
|
|
tests_total += 1
|
|
try:
|
|
sprite.pos = (50, 60)
|
|
if sprite.x == 50 and sprite.y == 60:
|
|
print(f"✓ PASS: sprite.pos = tuple sets position correctly")
|
|
tests_passed += 1
|
|
else:
|
|
print(f"✗ FAIL: pos setter with tuple failed: x={sprite.x}, y={sprite.y}")
|
|
except Exception as e:
|
|
print(f"✗ FAIL: pos setter with tuple error: {e}")
|
|
|
|
# Test 4: Verify pos getter reflects changes
|
|
tests_total += 1
|
|
try:
|
|
sprite.x = 70
|
|
sprite.y = 80
|
|
pos = sprite.pos
|
|
if pos.x == 70 and pos.y == 80:
|
|
print(f"✓ PASS: pos property reflects x/y changes")
|
|
tests_passed += 1
|
|
else:
|
|
print(f"✗ FAIL: pos doesn't reflect changes: {pos.x}, {pos.y}")
|
|
except Exception as e:
|
|
print(f"✗ FAIL: pos getter after change error: {e}")
|
|
|
|
return tests_passed, tests_total
|
|
|
|
def test_consistency_with_caption_entity():
|
|
"""Test that pos property is consistent across all UI elements"""
|
|
print("\n=== Testing Consistency with Caption/Entity ===")
|
|
|
|
tests_passed = 0
|
|
tests_total = 0
|
|
|
|
# Test 1: Caption pos property (should already exist)
|
|
tests_total += 1
|
|
try:
|
|
font = mcrfpy.Font("assets/JetbrainsMono.ttf")
|
|
caption = mcrfpy.Caption((10, 20), "Test", font)
|
|
pos = caption.pos
|
|
if hasattr(pos, 'x') and hasattr(pos, 'y'):
|
|
print(f"✓ PASS: Caption.pos works as expected")
|
|
tests_passed += 1
|
|
else:
|
|
print(f"✗ FAIL: Caption.pos doesn't return Vector")
|
|
except Exception as e:
|
|
print(f"✗ FAIL: Caption.pos error: {e}")
|
|
|
|
# Test 2: Entity draw_pos property (should already exist)
|
|
tests_total += 1
|
|
try:
|
|
entity = mcrfpy.Entity((10, 20))
|
|
pos = entity.draw_pos
|
|
if hasattr(pos, 'x') and hasattr(pos, 'y'):
|
|
print(f"✓ PASS: Entity.draw_pos works as expected")
|
|
tests_passed += 1
|
|
else:
|
|
print(f"✗ FAIL: Entity.draw_pos doesn't return Vector")
|
|
except Exception as e:
|
|
print(f"✗ FAIL: Entity.draw_pos error: {e}")
|
|
|
|
# Test 3: All pos properties return same type
|
|
tests_total += 1
|
|
try:
|
|
texture = mcrfpy.Texture("assets/kenney_tinydungeon.png", 16, 16)
|
|
frame = mcrfpy.Frame(10, 20, 100, 50)
|
|
sprite = mcrfpy.Sprite(10, 20, texture, 0, 1.0)
|
|
|
|
frame_pos = frame.pos
|
|
sprite_pos = sprite.pos
|
|
|
|
if (type(frame_pos).__name__ == type(sprite_pos).__name__ == 'Vector'):
|
|
print(f"✓ PASS: All pos properties return Vector type")
|
|
tests_passed += 1
|
|
else:
|
|
print(f"✗ FAIL: Inconsistent pos property types")
|
|
except Exception as e:
|
|
print(f"✗ FAIL: Type consistency check error: {e}")
|
|
|
|
return tests_passed, tests_total
|
|
|
|
def run_test(runtime):
|
|
"""Timer callback to run the test"""
|
|
try:
|
|
print("=== Testing pos Property for Frame and Sprite (Issue #84) ===\n")
|
|
|
|
frame_passed, frame_total = test_frame_pos_property()
|
|
sprite_passed, sprite_total = test_sprite_pos_property()
|
|
consistency_passed, consistency_total = test_consistency_with_caption_entity()
|
|
|
|
total_passed = frame_passed + sprite_passed + consistency_passed
|
|
total_tests = frame_total + sprite_total + consistency_total
|
|
|
|
print(f"\n=== SUMMARY ===")
|
|
print(f"Frame tests: {frame_passed}/{frame_total}")
|
|
print(f"Sprite tests: {sprite_passed}/{sprite_total}")
|
|
print(f"Consistency tests: {consistency_passed}/{consistency_total}")
|
|
print(f"Total tests passed: {total_passed}/{total_tests}")
|
|
|
|
if total_passed == total_tests:
|
|
print("\nIssue #84 FIXED: pos property added to Frame and Sprite!")
|
|
print("\nOverall result: PASS")
|
|
else:
|
|
print("\nIssue #84: Some tests failed")
|
|
print("\nOverall result: FAIL")
|
|
|
|
except Exception as e:
|
|
print(f"\nTest error: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
print("\nOverall result: FAIL")
|
|
|
|
sys.exit(0)
|
|
|
|
# Set up the test scene
|
|
mcrfpy.createScene("test")
|
|
mcrfpy.setScene("test")
|
|
|
|
# Schedule test to run after game loop starts
|
|
mcrfpy.setTimer("test", run_test, 100) |