tests/docs/: - API_FINDINGS.md: Comprehensive migration guide from deprecated to modern API - test_*.py: 9 executable tests verifying actual runtime behavior - screenshots/: Visual verification of working examples tests/conftest.py: - Add 'docs' and 'demo' to pytest collection paths Key findings documented: - Entity uses grid_pos= not pos= - Scene API: Scene() + activate() replaces createScene/setScene - scene.children replaces sceneUI() - scene.on_key replaces keypressScene() - mcrfpy.current_scene (property) replaces currentScene() (function) - Timer callback signature: (timer, runtime) - Opacity animation does NOT work on Frame (documented bug) 🤖 Generated with Claude Code (https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
86 lines
2.5 KiB
Python
86 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Test for features/animation.md examples.
|
|
|
|
Tests the modern API equivalents of animation examples.
|
|
"""
|
|
import mcrfpy
|
|
from mcrfpy import automation
|
|
import sys
|
|
|
|
# Setup scene using modern API
|
|
scene = mcrfpy.Scene("animation_demo")
|
|
scene.activate()
|
|
mcrfpy.step(0.01)
|
|
|
|
# Test 1: Basic Animation (lines 9-19)
|
|
frame = mcrfpy.Frame(pos=(0, 0), size=(100, 100))
|
|
frame.fill_color = mcrfpy.Color(255, 0, 0)
|
|
scene.children.append(frame)
|
|
|
|
# Animate x position
|
|
anim = mcrfpy.Animation("x", 500.0, 2.0, "easeInOut")
|
|
anim.start(frame)
|
|
print("Test 1: Basic animation started")
|
|
|
|
# Step forward to run animation
|
|
mcrfpy.step(2.5)
|
|
|
|
# Verify animation completed
|
|
if abs(frame.x - 500.0) < 1.0:
|
|
print("Test 1: PASS - frame moved to x=500")
|
|
else:
|
|
print(f"Test 1: FAIL - frame at x={frame.x}, expected 500")
|
|
sys.exit(1)
|
|
|
|
# Test 2: Multiple simultaneous animations (lines 134-144)
|
|
frame2 = mcrfpy.Frame(pos=(0, 0), size=(100, 100))
|
|
frame2.fill_color = mcrfpy.Color(0, 255, 0)
|
|
scene.children.append(frame2)
|
|
|
|
mcrfpy.Animation("x", 200.0, 1.0, "easeInOut").start(frame2)
|
|
mcrfpy.Animation("y", 150.0, 1.0, "easeInOut").start(frame2)
|
|
mcrfpy.Animation("w", 300.0, 1.0, "easeInOut").start(frame2)
|
|
mcrfpy.Animation("h", 200.0, 1.0, "easeInOut").start(frame2)
|
|
|
|
mcrfpy.step(1.5)
|
|
|
|
if abs(frame2.x - 200.0) < 1.0 and abs(frame2.y - 150.0) < 1.0:
|
|
print("Test 2: PASS - multiple animations completed")
|
|
else:
|
|
print(f"Test 2: FAIL - frame2 at ({frame2.x}, {frame2.y})")
|
|
sys.exit(1)
|
|
|
|
# Test 3: Callback (lines 105-112)
|
|
callback_fired = False
|
|
|
|
def on_complete(animation, target):
|
|
global callback_fired
|
|
callback_fired = True
|
|
print("Test 3: Callback fired!")
|
|
|
|
frame3 = mcrfpy.Frame(pos=(0, 300), size=(50, 50))
|
|
frame3.fill_color = mcrfpy.Color(0, 0, 255)
|
|
scene.children.append(frame3)
|
|
|
|
anim3 = mcrfpy.Animation("x", 300.0, 0.5, "easeInOut", callback=on_complete)
|
|
anim3.start(frame3)
|
|
|
|
mcrfpy.step(1.0)
|
|
|
|
if callback_fired:
|
|
print("Test 3: PASS - callback executed")
|
|
else:
|
|
print("Test 3: FAIL - callback not executed")
|
|
sys.exit(1)
|
|
|
|
# Test 4: NOTE - Opacity animation documented in features/animation.md
|
|
# but DOES NOT WORK on Frame. The property exists but animation
|
|
# system doesn't animate it. This is a DOCS BUG to report.
|
|
# Skipping test 4 - opacity animation not supported.
|
|
print("Test 4: SKIPPED - opacity animation not supported on Frame (docs bug)")
|
|
|
|
# Take screenshot showing animation results
|
|
automation.screenshot("/opt/goblincorps/repos/McRogueFace/tests/docs/screenshots/features_animation.png")
|
|
|
|
print("\nAll animation tests PASS")
|
|
sys.exit(0)
|