forked from genewildish/Mainline
- Rename VERTICAL camera mode to FEED (rapid single-item view) - Add SCROLL camera mode with float accumulation for smooth movie-credits style scrolling - Add estimate_block_height() for cheap layout calculation without full rendering - Replace ViewportFilterStage with layout-aware filtering that tracks camera position - Add render caching to FontStage to avoid re-rendering items - Fix CameraStage to use global canvas height for scrolling bounds - Add horizontal padding in Camera.apply() to prevent ghosting - Add get_dimensions() to MultiDisplay for proper viewport sizing - Fix PygameDisplay to auto-detect viewport from window size - Update presets to use scroll camera with appropriate speeds
69 lines
1.5 KiB
Python
69 lines
1.5 KiB
Python
from engine.camera import Camera, CameraMode
|
|
|
|
|
|
def test_camera_vertical_default():
|
|
"""Test default vertical camera."""
|
|
cam = Camera()
|
|
assert cam.mode == CameraMode.FEED
|
|
assert cam.x == 0
|
|
assert cam.y == 0
|
|
|
|
|
|
def test_camera_vertical_factory():
|
|
"""Test vertical factory method."""
|
|
cam = Camera.feed(speed=2.0)
|
|
assert cam.mode == CameraMode.FEED
|
|
assert cam.speed == 2.0
|
|
|
|
|
|
def test_camera_horizontal():
|
|
"""Test horizontal camera."""
|
|
cam = Camera.horizontal(speed=1.5)
|
|
assert cam.mode == CameraMode.HORIZONTAL
|
|
cam.update(1.0)
|
|
assert cam.x > 0
|
|
|
|
|
|
def test_camera_omni():
|
|
"""Test omnidirectional camera."""
|
|
cam = Camera.omni(speed=1.0)
|
|
assert cam.mode == CameraMode.OMNI
|
|
cam.update(1.0)
|
|
assert cam.x > 0
|
|
assert cam.y > 0
|
|
|
|
|
|
def test_camera_floating():
|
|
"""Test floating camera with sinusoidal motion."""
|
|
cam = Camera.floating(speed=1.0)
|
|
assert cam.mode == CameraMode.FLOATING
|
|
y_before = cam.y
|
|
cam.update(0.5)
|
|
y_after = cam.y
|
|
assert y_before != y_after
|
|
|
|
|
|
def test_camera_reset():
|
|
"""Test camera reset."""
|
|
cam = Camera.vertical()
|
|
cam.update(1.0)
|
|
assert cam.y > 0
|
|
cam.reset()
|
|
assert cam.x == 0
|
|
assert cam.y == 0
|
|
|
|
|
|
def test_camera_custom_update():
|
|
"""Test custom update function."""
|
|
call_count = 0
|
|
|
|
def custom_update(camera, dt):
|
|
nonlocal call_count
|
|
call_count += 1
|
|
camera.x += int(10 * dt)
|
|
|
|
cam = Camera.custom(custom_update)
|
|
cam.update(1.0)
|
|
assert call_count == 1
|
|
assert cam.x == 10
|