mirror of
https://github.com/db9979/uconsole_asw_game.git
synced 2026-12-05 20:34:16 +01:00
Sonar: drop the header status chips and legend lines, one row of four main keys, TAS/VDS state only while it matters. Top bars show station and clock only, the chart header only its scale. The submarine's threat box shows only fresh threats (a triangle marks stale ones). Degrees as °, whole-degree courses, turn radius only while turning. Fix the TMA header overlap and the truncated submarine tab, tube and alarm lines. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013avduxLno5MbDHZbRz1ggf
226 lines
9.2 KiB
Python
226 lines
9.2 KiB
Python
"""Semantic workstation layout checks at the native 1280x720 canvas."""
|
|
|
|
from types import SimpleNamespace as NS
|
|
import random
|
|
|
|
import pygame
|
|
|
|
from src.core import config
|
|
from src.core.i18n import Translator, localize
|
|
from src.ship.damage import DamageModel
|
|
from src.ui import layout, stations_view, weapons_view
|
|
|
|
|
|
def test_weapons_panel_has_fixed_solution_readiness_inventory_and_active_sections(monkeypatch):
|
|
pygame.font.init()
|
|
monkeypatch.setattr(config, "STATION_RECT", (640, 30, 640, 510))
|
|
titles = []
|
|
original = layout.box
|
|
|
|
def record(screen, rect, title="", **kwargs):
|
|
titles.append((title, pygame.Rect(rect)))
|
|
return original(screen, rect, title, **kwargs)
|
|
|
|
monkeypatch.setattr(layout, "box", record)
|
|
game = NS(
|
|
screen=pygame.Surface((1280, 720)), target=None,
|
|
torpedo_readiness=lambda: ("ROHRE BEREIT", config.COLOR_OK),
|
|
torpedo_count=4, torpedo_total=4, torpedo_depth=50.0,
|
|
torpedoes=[], roe="FREIGABE", station_page=0, flak_authorized=True,
|
|
helo=NS(torps=2, buoys_left=6, airborne=False, state="HANGAR"),
|
|
)
|
|
|
|
# Page 0: solution + stages
|
|
weapons_view.draw_weapons_panel(game)
|
|
names_p0 = {title for title, _ in titles}
|
|
assert "panel.fire_solution" in names_p0
|
|
assert "panel.engagement_stages" in names_p0
|
|
assert all(rect.left >= 640 and rect.right <= 1280 for _, rect in titles)
|
|
assert all(rect.top >= 30 and rect.bottom <= 540 for _, rect in titles)
|
|
|
|
# Page 1: inventory + active + controls
|
|
titles.clear()
|
|
game.station_page = 1
|
|
weapons_view.draw_weapons_panel(game)
|
|
names_p1 = {title for title, _ in titles}
|
|
assert "panel.inventory" in names_p1
|
|
assert "panel.active_weapons" in names_p1
|
|
assert "panel.engagement" in names_p1
|
|
assert all(rect.left >= 640 and rect.right <= 1280 for _, rect in titles)
|
|
assert all(rect.top >= 30 and rect.bottom <= 540 for _, rect in titles)
|
|
|
|
|
|
def test_weapons_panel_shows_tma_evidence_and_engagement_stages(monkeypatch):
|
|
pygame.font.init()
|
|
monkeypatch.setattr(config, "STATION_RECT", (640, 30, 640, 510))
|
|
lines = []
|
|
original_line = layout.blit_line
|
|
original_block = layout.blit_block
|
|
original_status = layout.status_line
|
|
|
|
def record_line(screen, text, *args, **kwargs):
|
|
lines.append(localize(text))
|
|
return original_line(screen, text, *args, **kwargs)
|
|
|
|
def record_block(screen, text, *args, **kwargs):
|
|
lines.append(localize(text))
|
|
return original_block(screen, text, *args, **kwargs)
|
|
|
|
def record_status(screen, x, y, w, label, value, *args, **kwargs):
|
|
lines.append(f"{localize(label)} {localize(value)}")
|
|
return original_status(screen, x, y, w, label, value, *args, **kwargs)
|
|
|
|
monkeypatch.setattr(layout, "blit_line", record_line)
|
|
monkeypatch.setattr(layout, "blit_block", record_block)
|
|
monkeypatch.setattr(layout, "status_line", record_status)
|
|
contact = NS(id=3, display_label="U-Boot", bearing=80.0, range_est=6.0,
|
|
confidence=.8, range_source="tma", last_seen=90.0,
|
|
range_sigma_nm=1.2, depth_est=None, player_class="U_BOOT",
|
|
tma_course=145.0, tma_speed=7.0, tma_quality=.72)
|
|
game = NS(
|
|
screen=pygame.Surface((1280, 720)), target=contact, sim_t=100.0,
|
|
torpedo_readiness=lambda: ("FEUER FREI", config.COLOR_OK),
|
|
_contact_range_fresh=lambda c: True,
|
|
weapon_classification=lambda c: c.player_class,
|
|
torpedo_count=4, torpedo_total=4, torpedo_depth=50.0,
|
|
torpedoes=[], roe="STD", station_page=0, flak_authorized=True,
|
|
helo=NS(torps=2, buoys_left=6, airborne=False, state="HANGAR"),
|
|
)
|
|
weapons_view.draw_weapons_panel(game)
|
|
assert any("TMA 145.0° / 7.0 kn Q72%" in line
|
|
for line in lines)
|
|
assert "Target ASSIGNED" in lines
|
|
assert "Fix VALID" in lines
|
|
assert "ROE AUTHORIZED" in lines
|
|
assert "Weapon READY" in lines
|
|
|
|
|
|
def test_engine_native_layout_uses_two_equal_work_columns(monkeypatch):
|
|
pygame.font.init()
|
|
monkeypatch.setattr(config, "STATION_RECT", (0, 30, 1280, 510))
|
|
boxes = []
|
|
original = layout.box
|
|
|
|
def record(screen, rect, title="", **kwargs):
|
|
boxes.append((title, pygame.Rect(rect)))
|
|
return original(screen, rect, title, **kwargs)
|
|
|
|
monkeypatch.setattr(layout, "box", record)
|
|
ship = NS(
|
|
telegraph="HALF", order_idx=2, course=90.0, target_course=95.0,
|
|
speed=10.0, target_speed=10.0,
|
|
cavitating=False, roll=1.0, pitch=.5, quiet_mode=False,
|
|
fuel_kg=400_000.0, fuel_capacity_kg=500_000.0,
|
|
fuel_burn_kg_h=lambda: 1000.0, fuel_endurance_h=lambda: 400.0,
|
|
fuel_range_nm=lambda: 4000.0,
|
|
rpm=lambda: 120.0, noise_level=lambda: .3,
|
|
passive_sonar_range_nm=lambda *args: 15.0,
|
|
)
|
|
damage = DamageModel(random.Random(1))
|
|
game = NS(screen=pygame.Surface((1280, 720)), ship=ship, damage=damage,
|
|
world=NS(sea_state=2), sonar_mode="BOW")
|
|
|
|
stations_view.draw_engine_view(game)
|
|
|
|
columns = {title: rect for title, rect in boxes}
|
|
assert columns["panel.engine_order"].right < columns["panel.propulsion"].left
|
|
assert abs(columns["panel.engine_order"].w - columns["panel.propulsion"].w) <= 1
|
|
|
|
|
|
def test_damage_native_layout_has_selected_detail_panel(monkeypatch):
|
|
pygame.font.init()
|
|
monkeypatch.setattr(config, "STATION_RECT", (0, 30, 1280, 510))
|
|
titles = []
|
|
original = layout.box
|
|
|
|
def record(screen, rect, title="", **kwargs):
|
|
titles.append(title)
|
|
return original(screen, rect, title, **kwargs)
|
|
|
|
monkeypatch.setattr(layout, "box", record)
|
|
damage = DamageModel(random.Random(2))
|
|
damage.compartments["sonar"].state = "FLUTEND"
|
|
damage.compartments["sonar"].flood = 42.0
|
|
cursor = list(damage.compartments).index("sonar")
|
|
game = NS(screen=pygame.Surface((1280, 720)), damage=damage,
|
|
dmg_cursor=cursor, dmg_team=1, station_page=1)
|
|
|
|
stations_view.draw_damage_view(game)
|
|
|
|
assert "panel.selection_actions" in titles
|
|
|
|
|
|
def test_helicopter_regions_are_shared_bounded_and_adapt_to_large_text(monkeypatch):
|
|
pygame.font.init()
|
|
monkeypatch.setattr(config, "STATION_RECT", (640, 30, 640, 510))
|
|
normal_game = NS(preferences=NS(large_text=False))
|
|
large_game = NS(preferences=NS(large_text=True))
|
|
normal = stations_view.helicopter_regions(normal_game, page=0)
|
|
large = stations_view.helicopter_regions(large_game, page=0)
|
|
normal_rules = stations_view.helicopter_regions(normal_game, page=1)
|
|
station = pygame.Rect(config.STATION_RECT)
|
|
|
|
for regions in (normal, large):
|
|
assert station.contains(regions["status"])
|
|
assert station.contains(regions["resources"])
|
|
assert regions["status"].bottom < regions["resources"].top
|
|
assert regions["rules"].w == 0 and regions["rules"].h == 0
|
|
assert station.contains(normal_rules["rules"])
|
|
assert normal_rules["rules"].h >= 100
|
|
assert normal_rules["status"].w == 0 and normal_rules["status"].h == 0
|
|
assert large["status"].h > normal["status"].h
|
|
layout.configure_for(large_text=False)
|
|
|
|
|
|
def test_large_text_helicopter_resource_lines_have_full_text_bounds(monkeypatch):
|
|
pygame.font.init()
|
|
monkeypatch.setattr(config, "STATION_RECT", (640, 30, 640, 510))
|
|
game = NS(
|
|
screen=pygame.Surface((1280, 720)), preferences=NS(large_text=True),
|
|
helo=NS(state="HANGAR", airborne=False, fuel_s=1800.0, x=0.0, y=0.0,
|
|
course=0.0, torps=2, buoys_left=6),
|
|
ship=NS(x=0.0, y=0.0, course=0.0), buoys=[],
|
|
_helo_waypoint_polar=lambda: (0.0, 10.0),
|
|
)
|
|
calls = []
|
|
original = layout.blit_line
|
|
|
|
def record(screen, text, rect, color, size=14, align="left"):
|
|
if text in {"helo.air_torpedoes", "helo.sonobuoys_ready",
|
|
"helo.sonobuoys_active", "panel.datalink",
|
|
"2", "6", "0", "helo.standby"}:
|
|
calls.append((text, pygame.Rect(rect), size))
|
|
return original(screen, text, rect, color, size=size, align=align)
|
|
|
|
monkeypatch.setattr(layout, "blit_line", record)
|
|
stations_view.draw_helicopter_view(game)
|
|
assert len(calls) == 8
|
|
for _, rect, size in calls:
|
|
assert rect.h >= layout.font(size).get_linesize()
|
|
for label, value in zip(calls[::2], calls[1::2]):
|
|
assert label[1].bottom <= value[1].top
|
|
layout.configure_for(large_text=False)
|
|
|
|
|
|
def test_helicopter_status_rendered_rows_are_inside_card(monkeypatch):
|
|
pygame.font.init()
|
|
monkeypatch.setattr(config, "STATION_RECT", (640, 30, 640, 510))
|
|
game = NS(
|
|
screen=pygame.Surface((1280, 720)), preferences=NS(large_text=True),
|
|
helo=NS(state="AUF", airborne=True, fuel_s=1200.0, x=3.0, y=-4.0,
|
|
course=275.0, torps=2, buoys_left=6),
|
|
ship=NS(x=0.0, y=0.0, course=25.0), buoys=[],
|
|
_helo_waypoint_polar=lambda: (80.0, 12.0),
|
|
)
|
|
status = stations_view.helicopter_regions(game, page=0)["status"]
|
|
|
|
with layout.capture_text() as rendered:
|
|
stations_view.draw_helicopter_view(game, tr=Translator("en").t)
|
|
|
|
flight_rows = [item for item in rendered
|
|
if "Flight course" in item["text"] or "Flugkurs" in item["text"]]
|
|
assert flight_rows
|
|
assert all(status.contains(item["rect"]) for item in flight_rows)
|
|
assert stations_view.helicopter_regions(game, page=1)["rules"].h >= 100
|
|
layout.configure_for(large_text=False)
|