McRogueFace/tests/unit/test_visual_path.py
John McCardle 9f481a2e4a fix: Update test files to use current API patterns
Migrates test suite to current API:
- Frame(x, y, w, h) → Frame(pos=(x, y), size=(w, h))
- Caption("text", x, y) → Caption(pos=(x, y), text="text")
- caption.size → caption.font_size
- Entity(x, y, ...) → Entity((x, y), ...)
- Grid(w, h, ...) → Grid(grid_size=(w, h), ...)
- cell.color → ColorLayer system

Tests now serve as valid API usage examples.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-29 19:47:48 -05:00

83 lines
No EOL
2.1 KiB
Python

#!/usr/bin/env python3
"""Simple visual test for path highlighting"""
import mcrfpy
import sys
# Colors
WALL_COLOR = mcrfpy.Color(60, 30, 30)
FLOOR_COLOR = mcrfpy.Color(200, 200, 220)
PATH_COLOR = mcrfpy.Color(100, 255, 100)
# Create scene
mcrfpy.createScene("visual_test")
# Create grid
grid = mcrfpy.Grid(grid_x=5, grid_y=5)
grid.fill_color = mcrfpy.Color(0, 0, 0)
# Add color layer for cell coloring
color_layer = grid.add_layer("color", z_index=-1)
def check_render(dt):
"""Timer callback to verify rendering"""
print(f"\nTimer fired after {dt}ms")
# Take screenshot
from mcrfpy import automation
automation.screenshot("visual_path_test.png")
print("Screenshot saved as visual_path_test.png")
# Sample some path cells to verify colors
print("\nSampling path cell colors from grid:")
for x, y in [(1, 1), (2, 2), (3, 3)]:
color = color_layer.at(x, y)
print(f" Cell ({x},{y}): color=({color.r}, {color.g}, {color.b})")
sys.exit(0)
# Initialize all cells as floor
print("Initializing grid...")
for y in range(5):
for x in range(5):
grid.at(x, y).walkable = True
color_layer.set(x, y, FLOOR_COLOR)
# Create entities
e1 = mcrfpy.Entity((0, 0), grid=grid)
e2 = mcrfpy.Entity((4, 4), grid=grid)
e1.sprite_index = 64 # @
e2.sprite_index = 69 # E
print(f"Entity 1 at ({e1.x}, {e1.y})")
print(f"Entity 2 at ({e2.x}, {e2.y})")
# Get path
path = e1.path_to(int(e2.x), int(e2.y))
print(f"\nPath from E1 to E2: {path}")
# Color the path
if path:
print("\nColoring path cells green...")
for x, y in path:
color_layer.set(x, y, PATH_COLOR)
print(f" Set ({x},{y}) to green")
# Set up UI
ui = mcrfpy.sceneUI("visual_test")
ui.append(grid)
grid.position = (50, 50)
grid.size = (250, 250)
# Add title
title = mcrfpy.Caption(pos=(50, 10), text="Path Visualization Test")
title.fill_color = mcrfpy.Color(255, 255, 255)
ui.append(title)
# Set scene
mcrfpy.setScene("visual_test")
# Set timer to check rendering
mcrfpy.setTimer("check", check_render, 500)
print("\nScene ready. Path should be visible in green.")