Files
uconsole_asw_game/tests/test_less_text.py
T
Claude 9a1258c3a1 1.3.113: full mouse control, chart history, label layout, merchant lanes
- uConsole fully playable by mouse: key-bar legends, station tabs, dials,
  numeric keypad, clickable menu/dialog rows, wheel and right-click cancel
- Charts draw own track, earlier contact positions and bearings (display only)
- Chart labels are placed without overlapping (uConsole and web)
- Cargo ships, tankers and passenger ships run lanes between ports and edge
  exits, give way under COLREG-style rules and flee nearby detonations
  (stateless, no save change)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JrUuYqTA8k76Uf572FDStg
2026-09-30 14:23:05 +00:00

85 lines
3.1 KiB
Python

"""uConsole screens carry less text: short bars, fresh-only alarms, four keys."""
import math
import sys
from pathlib import Path
import pygame
from src.core import uboot_local
from src.core.i18n import localize
from src.core.station import Station
from src.ui import map_view, uboot_view
sys.path.insert(0, str(Path(__file__).parent))
from test_opfor_sub import _crewed # noqa: E402
def _drawn_texts(monkeypatch, module):
texts = []
original = module.layout.blit_line
def record(surface, text, *args, **kwargs):
texts.append(str(localize(text)))
return original(surface, text, *args, **kwargs)
monkeypatch.setattr(module.layout, "blit_line", record)
return texts
def test_frigate_top_bar_names_station_mission_clock_speed_course(monkeypatch):
game, _server, _bridge = _crewed(seed=31)
game.station = Station.SONAR
game.msg_until = 0.0
texts = _drawn_texts(monkeypatch, map_view)
game.draw_top_bar()
assert texts[:9] == ["1 BRIDGE", "2 SONAR", "3 WEAPONS", "4 DAMAGE", "5 CIC",
"6 RADIO", "7 ENGINE", "8 HELO", "9 EW"]
parts = texts[9].split(" · ")
assert parts[0] == game.top_bar_scenario() and parts[1] == game.world.format_time()
assert parts[2] == f"{game.ship.speed:.1f} kn"
assert parts[3] == f"{game.ship.course % 360:03.0f}°"
def test_chart_header_shows_only_the_scale(monkeypatch):
game, _server, _bridge = _crewed(seed=31)
game.station = Station.BRIDGE
texts = _drawn_texts(monkeypatch, map_view)
game.draw()
header = [text for text in texts if text.split()[1:2] == ["NM"]]
assert header and all("|" not in text and "coastal" not in text for text in header)
def test_stale_ping_leaves_only_the_top_bar_marker():
game, _server, _bridge = _crewed(seed=31)
boat = game.opfor
game.local_side = "uboot"
boat.sub.crew.ping_bearing = 259.0
boat.sub.memory["last_ping_age"] = 5.0
rows = uboot_view.threat_rows(game, boat)
assert [fresh for text, _level, fresh in rows
if text["__u_jagd_i18n__"] == "uboot.threat.ping_bearing"] == [True]
assert uboot_view._draw_threat_bar(game.screen, game, boat, 0, 0, 400) > 0
boat.sub.memory["last_ping_age"] = uboot_view.THREAT_FRESH_S + 10.0
rows = uboot_view.threat_rows(game, boat)
assert rows and not any(fresh for _text, _level, fresh in rows)
# Still listed on the threat page, but no box on every station.
assert uboot_view.threats(game, boat)
assert uboot_view._draw_threat_bar(game.screen, game, boat, 0, 0, 400) == 0
boat.sub.memory["last_ping_age"] = math.inf
assert uboot_view._draw_threat_bar(game.screen, game, boat, 0, 0, 400) == 0
def test_submarine_footers_have_at_most_four_keys():
assert max(len(specs) for specs in uboot_view._FOOTERS.values()) <= 4
def test_tube_line_lists_only_tubes_that_are_not_ready():
game, _server, _bridge = _crewed(seed=31)
sub = game.opfor.sub
assert uboot_view.tube_line(sub, busy_only=True) is None
game.local_side = "uboot"
uboot_local.set_local_station(game, "uboot_weapons")
pygame.display.set_mode((1280, 720))
uboot_view.draw(game)