McRogueFace/tests/docs/test_quickstart_main_menu.py
Frick 23afae69ad Add API verification test suite and documentation
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>
2026-01-15 04:05:32 +00:00

74 lines
1.8 KiB
Python

#!/usr/bin/env python3
"""Test for quickstart.md 'Main Menu' example.
Original (DEPRECATED - lines 82-125):
mcrfpy.createScene("main_menu")
ui = mcrfpy.sceneUI("main_menu")
bg = mcrfpy.Frame(0, 0, 1024, 768, fill_color=(20, 20, 40))
title = mcrfpy.Caption((312, 100), "My Awesome Game", font, fill_color=(255, 255, 100))
button_frame.click = start_game
mcrfpy.setScene("main_menu")
Modern equivalent below.
"""
import mcrfpy
from mcrfpy import automation
import sys
# Create scene using modern API
scene = mcrfpy.Scene("main_menu")
scene.activate()
mcrfpy.step(0.01)
# Load font
font = mcrfpy.Font("assets/JetbrainsMono.ttf")
# Add background using modern Frame API (keyword args)
bg = mcrfpy.Frame(
pos=(0, 0),
size=(1024, 768),
fill_color=mcrfpy.Color(20, 20, 40)
)
scene.children.append(bg)
# Add title using modern Caption API
title = mcrfpy.Caption(
pos=(312, 100),
text="My Awesome Game",
font=font,
fill_color=mcrfpy.Color(255, 255, 100)
)
title.font_size = 48
title.outline = 2
title.outline_color = mcrfpy.Color(0, 0, 0)
scene.children.append(title)
# Create button frame
button_frame = mcrfpy.Frame(
pos=(362, 300),
size=(300, 80),
fill_color=mcrfpy.Color(50, 150, 50)
)
# Button caption
button_caption = mcrfpy.Caption(
pos=(90, 25), # Centered in button
text="Start Game",
fill_color=mcrfpy.Color(255, 255, 255)
)
button_caption.font_size = 24
button_frame.children.append(button_caption)
# Click handler using modern on_click (3 args: x, y, button)
def start_game(x, y, button):
print("Starting the game!")
button_frame.on_click = start_game
scene.children.append(button_frame)
# Render and screenshot
mcrfpy.step(0.1)
automation.screenshot("/opt/goblincorps/repos/McRogueFace/tests/docs/screenshots/quickstart_main_menu.png")
print("PASS - quickstart main menu")
sys.exit(0)