mirror of
https://github.com/db9979/uconsole_asw_game.git
synced 2026-12-05 12:24:25 +01:00
Core split 4b: display, operator commands and pictures out of game.py
DrawMixin (frame, chrome, overlays, run), OperatorMixin (station commands shared by keys and Remote Crew) and PicturesMixin (OPZ/ELOKA pictures, plot layer, weather and SimLog) leave game.py at 700 lines of composition root. Tests patch module-level names where they are now looked up; Game keeps the re-exports tests import. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
22b5b16c95
commit
6998cf0d8f
9 files changed
+4496
-4413
No files matched your search
+13
-4400
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -69,7 +69,7 @@ def test_eco_display_replaces_the_station_views_while_the_browser_is_live(
|
||||
raise AssertionError("full station view drawn in eco mode")
|
||||
|
||||
for name in ("draw_map_view", "draw_bridge_view", "draw_sonar_view"):
|
||||
monkeypatch.setattr("src.core.game." + name, forbidden)
|
||||
monkeypatch.setattr("src.core.game_draw." + name, forbidden)
|
||||
calls = []
|
||||
monkeypatch.setattr(Game, "draw_eco_display",
|
||||
lambda self: calls.append(self.station))
|
||||
|
||||
@@ -7,6 +7,7 @@ import pygame
|
||||
import pytest
|
||||
|
||||
import src.core.game as game_module
|
||||
from src.core import game_draw
|
||||
from src.core import config
|
||||
from src.core.game import Game
|
||||
from src.core.station import Station
|
||||
@@ -201,8 +202,12 @@ def test_audio_replacement_and_run_shutdown_old_engines(monkeypatch):
|
||||
initial = game.audio
|
||||
monkeypatch.setattr(initial, "shutdown", Mock(wraps=initial.shutdown))
|
||||
replacement = Mock(available=False)
|
||||
monkeypatch.setattr(game_module, "AudioEngine", Mock(return_value=replacement))
|
||||
monkeypatch.setattr(game_module, "save_preferences", Mock())
|
||||
# The engine is constructed by the display half (game_draw); the same
|
||||
# factory mock is visible through both modules.
|
||||
factory = Mock(return_value=replacement)
|
||||
monkeypatch.setattr(game_module, "AudioEngine", factory)
|
||||
monkeypatch.setattr(game_draw, "AudioEngine", factory)
|
||||
monkeypatch.setattr(game_draw, "save_preferences", Mock())
|
||||
game._set_preference("audio", True)
|
||||
old = game_module.AudioEngine.return_value
|
||||
assert game.audio is old
|
||||
@@ -226,7 +231,7 @@ def test_options_apply_global_tooltip_preference_and_language_state(monkeypatch)
|
||||
game = Game(seed=82, audio_enabled=False,
|
||||
preferences=Preferences(language="en", tooltips=True))
|
||||
save = Mock()
|
||||
monkeypatch.setattr(game_module, "save_preferences", save)
|
||||
monkeypatch.setattr(game_draw, "save_preferences", save)
|
||||
game.pinned_tooltip = {"title": "old", "lines": []}
|
||||
game._set_preference("tooltips", False)
|
||||
assert not game.tooltips_enabled and not game.preferences.tooltips
|
||||
@@ -273,7 +278,7 @@ def test_runtime_notices_are_structured_for_bt_listening_and_launches(monkeypatc
|
||||
def test_runtime_language_switch_retranslates_feeds_and_keeps_legacy_strings(monkeypatch):
|
||||
game = Game(seed=87, audio_enabled=False,
|
||||
preferences=Preferences(language="en"))
|
||||
monkeypatch.setattr(game_module, "save_preferences", Mock())
|
||||
monkeypatch.setattr(game_draw, "save_preferences", Mock())
|
||||
structured = message("runtime.helo.return")
|
||||
game.feed.add("12:00", "mission", structured)
|
||||
game.feed.add("12:01", "mission", "Saved")
|
||||
|
||||
@@ -6,6 +6,7 @@ from types import SimpleNamespace
|
||||
import pytest
|
||||
|
||||
import src.core.game as game_module
|
||||
from src.core import game_events
|
||||
from src.core.game import Game
|
||||
from src.core.preferences import Preferences
|
||||
from src.data.catalog import CATALOG
|
||||
@@ -535,9 +536,9 @@ def game():
|
||||
def test_live_traffic_api_test_reports_ok_and_error(game, monkeypatch):
|
||||
"""The options-menu 'API test' row runs both probes in a background
|
||||
thread and stores per-side (status, reason) tuples the overlay reads."""
|
||||
monkeypatch.setattr(game_module, "ais_test_connection",
|
||||
monkeypatch.setattr(game_events, "ais_test_connection",
|
||||
lambda api_key, bbox: (True, None))
|
||||
monkeypatch.setattr(game_module, "adsb_test_connection",
|
||||
monkeypatch.setattr(game_events, "adsb_test_connection",
|
||||
lambda credentials, bbox: (False, "boom"))
|
||||
game._set_preference("aisstream_api_key", "some-key")
|
||||
|
||||
@@ -554,9 +555,9 @@ def test_live_traffic_api_test_reports_ok_and_error(game, monkeypatch):
|
||||
def test_live_traffic_api_test_skips_ais_without_key(game, monkeypatch):
|
||||
called = []
|
||||
monkeypatch.setattr(
|
||||
game_module, "ais_test_connection",
|
||||
game_events, "ais_test_connection",
|
||||
lambda api_key, bbox: called.append(api_key) or (True, None))
|
||||
monkeypatch.setattr(game_module, "adsb_test_connection",
|
||||
monkeypatch.setattr(game_events, "adsb_test_connection",
|
||||
lambda credentials, bbox: (True, None))
|
||||
assert game.preferences.aisstream_api_key == ""
|
||||
|
||||
@@ -569,9 +570,9 @@ def test_live_traffic_api_test_skips_ais_without_key(game, monkeypatch):
|
||||
|
||||
|
||||
def test_live_traffic_test_row_is_reachable_via_navigation(game, monkeypatch):
|
||||
monkeypatch.setattr(game_module, "ais_test_connection",
|
||||
monkeypatch.setattr(game_events, "ais_test_connection",
|
||||
lambda api_key, bbox: (True, None))
|
||||
monkeypatch.setattr(game_module, "adsb_test_connection",
|
||||
monkeypatch.setattr(game_events, "adsb_test_connection",
|
||||
lambda credentials, bbox: (True, None))
|
||||
game._open_administration("live_traffic")
|
||||
assert game.live_traffic_open
|
||||
|
||||
@@ -7,6 +7,7 @@ import random
|
||||
import pytest
|
||||
|
||||
import src.core.game as game_module
|
||||
from src.core import game_events, game_save, save_validate
|
||||
from src.air.flights import Flight
|
||||
from src.core.game import Game
|
||||
from src.data import catalog
|
||||
@@ -121,6 +122,8 @@ def test_snapshot_remains_authoritative_after_packaged_defaults_change(monkeypat
|
||||
original = copy.deepcopy(state["catalog_snapshot"])
|
||||
changed_package = _changed_catalog(original)
|
||||
monkeypatch.setattr(game_module, "CATALOG", changed_package)
|
||||
monkeypatch.setattr(save_validate, "CATALOG", changed_package)
|
||||
monkeypatch.setattr(game_events, "CATALOG", changed_package)
|
||||
|
||||
game.load_state(state)
|
||||
|
||||
@@ -161,7 +164,7 @@ def test_save_reader_rejects_oversize_before_json_parse(tmp_path, monkeypatch):
|
||||
game = Game(seed=2411, start_menu=False)
|
||||
path = tmp_path / "oversize.json"
|
||||
path.write_bytes(b" " * 129)
|
||||
monkeypatch.setattr(game_module, "MAX_SAVE_DOCUMENT_BYTES", 128)
|
||||
monkeypatch.setattr(game_save, "MAX_SAVE_DOCUMENT_BYTES", 128)
|
||||
|
||||
assert not game.load_game(str(path))
|
||||
|
||||
@@ -270,6 +273,8 @@ def test_changed_package_split_run_keeps_snapshot_continuation(monkeypatch):
|
||||
control.load_state(copy.deepcopy(state))
|
||||
changed_package = _changed_catalog(state["catalog_snapshot"])
|
||||
monkeypatch.setattr(game_module, "CATALOG", changed_package)
|
||||
monkeypatch.setattr(save_validate, "CATALOG", changed_package)
|
||||
monkeypatch.setattr(game_events, "CATALOG", changed_package)
|
||||
restored = Game(seed=1, start_menu=False)
|
||||
restored.load_state(copy.deepcopy(state))
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ from src.commander.local import CommanderConsole
|
||||
from src.core import config
|
||||
from src.core.game import Game
|
||||
from src.core import game as game_module
|
||||
from src.core import game_draw
|
||||
import pygame
|
||||
|
||||
|
||||
@@ -221,7 +222,7 @@ def test_host_password_file_is_private_and_reset_is_local(tmp_path):
|
||||
|
||||
def test_web_host_publishes_game_without_local_display_work(tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(config, "SAVE_DIR", str(tmp_path))
|
||||
monkeypatch.setattr(game_module, "save_preferences", lambda prefs: tmp_path / "settings.json")
|
||||
monkeypatch.setattr(game_draw, "save_preferences", lambda prefs: tmp_path / "settings.json")
|
||||
game = Game(seed=31, start_menu=True, fullscreen=False,
|
||||
audio_enabled=False, language="en", web_mode=True)
|
||||
game.world_mode = "fixed"
|
||||
|
||||
Reference in new issue
Block a user