Files
uconsole_asw_game/tests/test_silhouettes.py
T
Claude b813115069 Start screen, animated silhouettes, web solo side choice (1.3.6)
The start screen becomes an animated night hunt: the frigate F-217 with
turning radar, funnel smoke, bow wave and towed array, the helicopter with
its dipping sonar, and a submarine below the layer that lights up when the
hull sonar pulse reaches it; the title carries "by Dominik Bornhäußer" and
the version. The same scene, dimmed, lies behind the main menu. A shared
silhouette library (src/ui/silhouettes.py) draws detailed class profiles
that pitch, turn radar and rotors and trail a wake; the periscope and the
bridge binoculars use it. In Remote Crew solo mode the New Game dialog now
picks the side (frigate or submarine). Station shortcuts, manual PDFs and
the contact-analysis images are regenerated.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AS36Eg72iLviiSVbCUVNAi
2026-09-28 08:10:28 +00:00

43 lines
1.7 KiB
Python

import pygame
import pytest
from src.ui import horizon, silhouettes
@pytest.mark.parametrize("cls", sorted(silhouettes.PROFILES))
def test_profiles_stay_in_hull_units(cls):
profile = silhouettes.PROFILES[cls]
for poly in [profile["hull"], *profile["blocks"]]:
assert len(poly) >= 3
assert all(0.0 <= u <= 1.0 and -0.1 <= v <= 0.7 for u, v in poly)
@pytest.mark.parametrize("cls", ["warship", "merchant", "unknown", "aircraft", "torpedo",
"mystery"])
@pytest.mark.parametrize("width", [3, 24, 180])
def test_outline_draws_every_class_near_its_bearing(cls, width):
surface = pygame.Surface((400, 300), pygame.SRCALPHA)
horizon.draw_outline(surface, cls, 200, 200, width, (200, 200, 200, 255), 1.5)
rect = surface.get_bounding_rect()
assert rect.w > 0
# Rotor disc, bow wave and wake may reach past the hull.
assert rect.left >= 200 - width // 2 - 12 - width * 0.2
assert rect.right <= 200 + width // 2 + 12 + width * 0.4
@pytest.mark.parametrize("cls", ["warship", "aircraft", "submarine"])
def test_silhouettes_animate_with_the_display_clock(cls):
frames = []
for t in (0.0, 0.37):
surface = pygame.Surface((400, 300))
silhouettes.draw_profile(surface, cls, 200, 200, 240, (200, 200, 200), t=t,
rim=(90, 160, 160))
frames.append(pygame.image.tobytes(surface, "RGB"))
assert frames[0] != frames[1]
def test_facing_mirrors_the_profile():
left = silhouettes.frame_for("warship", 200, 100, 100, facing=-1).point(0.0, 0.0)
right = silhouettes.frame_for("warship", 200, 100, 100, facing=1).point(0.0, 0.0)
assert left[0] < 200 < right[0]