mirror of
https://github.com/db9979/uconsole_asw_game.git
synced 2026-12-05 12:24:25 +01:00
The ships of Tiefenkontakt (the browser submarine game, Three.js) come over as polygon meshes for our painter: tools/tiefenkontakt/export_models.mts writes the opaque triangles of 22 designs from a Tiefenkontakt checkout, tools/build_tk_models.py snaps, decimates the smooth submarine hulls, joins coplanar faces of one colour, shares a 40-colour palette and keeps the navigation lamps (data/unit_models/tiefenkontakt.json.gz, commit embedded). src/ui/tk_models.py maps catalog types to designs: corvettes, frigates and destroyers up to 160 m, container ships, tankers, bulk carriers, reefers, RoRo/car carriers, general cargo, heavy lift, ferries, tugs, trawlers and all submarines (79 of 111 types); carriers, cruisers, big destroyers, cruise ships, auxiliaries and aircraft keep their own models. Each is stretched to its type's beam and draught; light positions come from the design. The browser loads one module per design (views/tk/<name>.js) and stretches it the same way (parity test in Chromium). uConsole: a detailed partition is built in a background thread on first sight while the flat silhouette shows (model_bsp.tree_if_ready), and eyepiece sprites grow in ~4 % steps (scene_length). By day the models show their paint (scene_vivid), fading to the steel outline at night and in haze, on both renderers. Docs: manual (bridge, editors), changelog, README, notices, AGENTS; screenshots and manual figures regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUgHR8PXDGer54DH6ie
111 lines
4.3 KiB
Python
111 lines
4.3 KiB
Python
"""pytest-Setup: Projektroot auf sys.path + headlose SDL-Treiber."""
|
|
|
|
import os
|
|
import sys
|
|
from tempfile import TemporaryDirectory
|
|
|
|
import pytest
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
os.environ.setdefault("SDL_VIDEODRIVER", "dummy")
|
|
os.environ.setdefault("SDL_AUDIODRIVER", "dummy")
|
|
# The game never asks GitHub for new releases from a test run.
|
|
os.environ.setdefault("U_JAGD_NO_UPDATE_CHECK", "1")
|
|
|
|
|
|
def pytest_configure(config):
|
|
from src.core import config as game_config
|
|
|
|
# Protect collection and session fixtures as well as individual tests.
|
|
saves = TemporaryDirectory(prefix="u-jagd-pytest-")
|
|
config.add_cleanup(saves.cleanup)
|
|
patch = pytest.MonkeyPatch()
|
|
config.add_cleanup(patch.undo)
|
|
patch.setattr(game_config, "SAVE_DIR", saves.name)
|
|
patch.setattr(game_config, "SAVE_PATH", os.path.join(saves.name, "save.json"))
|
|
# Session-wide guard as well: nothing in a test run (collection, threads
|
|
# outliving a test, helpers) may write the real ~/.u-jagd/settings.json.
|
|
from pathlib import Path
|
|
from src.core import preferences as preferences_module
|
|
real_path = preferences_module.default_preferences_path
|
|
|
|
def isolated_path():
|
|
return Path(saves.name) / "settings.json"
|
|
|
|
isolated_path.__wrapped__ = real_path
|
|
patch.setattr(preferences_module, "default_preferences_path", isolated_path)
|
|
|
|
|
|
_BROWSER_MARKS = {}
|
|
|
|
|
|
def drives_browser(path) -> bool:
|
|
"""True for a test module that launches headless Chromium (directly or
|
|
through the ``commander_web`` helpers)."""
|
|
path = str(path)
|
|
if path not in _BROWSER_MARKS:
|
|
try:
|
|
with open(path, encoding="utf-8") as handle:
|
|
text = handle.read()
|
|
except OSError:
|
|
text = ""
|
|
_BROWSER_MARKS[path] = ("chromium" in text or "commander_web" in text)
|
|
return _BROWSER_MARKS[path]
|
|
|
|
|
|
def pytest_collection_modifyitems(config, items):
|
|
"""Mark every test of a module that drives headless Chromium as ``browser``
|
|
so a local iteration can leave them out (``-m "not browser"``)."""
|
|
for item in items:
|
|
if drives_browser(item.fspath):
|
|
item.add_marker(pytest.mark.browser)
|
|
# Under pytest-xdist (``--dist loadgroup``) at most two headless
|
|
# Chromium instances run at once; more of them starve each other
|
|
# of CPU on a four-core host and time out their virtual-time
|
|
# budgets, which makes DOM-probe tests flaky.
|
|
group = sum(map(ord, str(item.fspath))) % 2
|
|
if str(item.fspath).endswith("test_commander_console_browser.py"):
|
|
# The solo console pumps a live game for minutes of wall
|
|
# time; it gets a worker of its own instead of queueing
|
|
# behind other Chromium runs.
|
|
item.add_marker(pytest.mark.xdist_group("browser-console"))
|
|
else:
|
|
item.add_marker(pytest.mark.xdist_group(f"browser-{group}"))
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def isolated_saves(tmp_path, monkeypatch):
|
|
from src.core import config
|
|
from src.core import preferences as preferences_module
|
|
|
|
saves = tmp_path / "saves"
|
|
saves.mkdir()
|
|
monkeypatch.setattr(config, "SAVE_DIR", str(saves))
|
|
monkeypatch.setattr(config, "SAVE_PATH", str(saves / "save.json"))
|
|
monkeypatch.setattr(
|
|
preferences_module, "default_preferences_path",
|
|
lambda: saves / "settings.json")
|
|
# The default graphics level follows the platform ("full" on Windows);
|
|
# tests run against the uConsole default on every runner.
|
|
monkeypatch.setattr(preferences_module, "_default_graphics", lambda: "normal")
|
|
# Model partitions are built at once in tests (the game builds the
|
|
# detailed ones in the background; tests/test_tk_models.py checks that).
|
|
from src.ui import model_bsp
|
|
monkeypatch.setattr(model_bsp, "BACKGROUND", False)
|
|
return saves
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _reference_sea(request):
|
|
"""The mechanics tests place ships and submarines at fixed spots of a
|
|
seed's map and were written against the synthetic reference sea; they
|
|
run in it. A test marked ``real_sea`` sees the real depths and surface
|
|
layer of the sector (``src/world/real_ocean.py``), as the game does."""
|
|
if request.node.get_closest_marker("real_sea"):
|
|
yield
|
|
return
|
|
from src.world import real_ocean
|
|
|
|
with real_ocean.reference_sea():
|
|
yield
|