mirror of
https://github.com/db9979/uconsole_asw_game.git
synced 2026-12-06 12:54:18 +01:00
Add src/physics/ship_dynamics.py with hull/propeller data in data/loadouts/ownship_hull.json, calibrated at load time against the 1.0.0 references (top speed, 92 s to 90 % of FULL, 92 s stop, 1.2 deg/s at FULL, cavitation at 15 kn, cubic fuel law): - Surge from propeller thrust (linear K_T(J)) against quadratic resistance and added resistance in waves; three exactly integrable regimes (load-up programme, governed, reverse-pitch braking) keep the result independent of the step size. - Cavitation from the cavitation number at the screw depth (earlier when pitching lifts the stern); physical shaft rpm; fuel from shaft power. - First-order Nomoto steering (turn circle ~0.4 NM at all speeds). - 1-DOF roll/pitch driven by a Pierson-Moskowitz wave slope, turn heel, list and speed-dependent fin stabilizers. - Displacement from fuel and floodwater; hydrostatic draft plus Barrass squat feed swept grounding. - Jammed rudder when the aft steering-gear room is destroyed, stabilizers lost with a destroyed hull compartment. - Saved wake ring with bubble decay for later sensor/weapon phases. Deviations (rpm display values, HALF turn rate) are recorded in tests/calibration/deviations.json. Manual EN/DE updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
136 lines
6.6 KiB
Python
136 lines
6.6 KiB
Python
import json
|
|
import hashlib
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
import tarfile
|
|
import zipfile
|
|
from importlib import resources
|
|
from pathlib import Path
|
|
|
|
|
|
ROOT = Path(__file__).parents[1]
|
|
TEMPLATE_NAMES = {
|
|
"mission.json",
|
|
"unit_aircraft.json",
|
|
"unit_animal.json",
|
|
"unit_decoy.json",
|
|
"unit_sub.json",
|
|
"unit_surface.json",
|
|
"unit_torpedo.json",
|
|
}
|
|
CONTACT_NAMES = {
|
|
"acoustics.json", "aircraft.json", "animals.json", "civilians.json",
|
|
"decoys.json", "sources.json", "subs.json", "torpedoes.json", "warships.json",
|
|
}
|
|
LOADOUT_NAMES = {"air_defense.json", "ownship.json", "ownship_hull.json"}
|
|
CONTACT_ANALYSIS_MANIFEST = json.loads(
|
|
(ROOT / "data/contact_analysis/manifest.json").read_text(encoding="utf-8"))
|
|
CONTACT_ANALYSIS_NAMES = {
|
|
"manifest.json", *(item["filename"] for item in CONTACT_ANALYSIS_MANIFEST["assets"]),
|
|
}
|
|
CONTACT_ANALYSIS_HASHES = {
|
|
item["filename"]: item["sha256"] for item in CONTACT_ANALYSIS_MANIFEST["assets"]
|
|
}
|
|
|
|
|
|
def test_editor_templates_are_importlib_resources():
|
|
package = resources.files("data.editor_templates")
|
|
assert {item.name for item in package.iterdir() if item.name.endswith(".json")} == TEMPLATE_NAMES
|
|
assert json.loads(package.joinpath("mission.json").read_text(encoding="utf-8"))["version"] == 1
|
|
contacts = resources.files("data.contacts")
|
|
assert {item.name for item in contacts.iterdir() if item.name.endswith(".json")} == CONTACT_NAMES
|
|
loadouts = resources.files("data.loadouts")
|
|
assert {item.name for item in loadouts.iterdir() if item.name.endswith(".json")} == LOADOUT_NAMES
|
|
analysis = resources.files("data.contact_analysis")
|
|
analysis_names = {item.name for item in analysis.iterdir()
|
|
if item.name != "__init__.py" and item.is_file()}
|
|
assert analysis_names == CONTACT_ANALYSIS_NAMES
|
|
for name, digest in CONTACT_ANALYSIS_HASHES.items():
|
|
assert hashlib.sha256(analysis.joinpath(name).read_bytes()).hexdigest() == digest
|
|
|
|
|
|
def test_source_and_wheel_contain_editor_templates(tmp_path):
|
|
subprocess.run(
|
|
[sys.executable, "-m", "build", "--sdist", "--wheel",
|
|
"--outdir", str(tmp_path), str(ROOT)],
|
|
cwd=tmp_path, check=True, capture_output=True, text=True)
|
|
wheel = next(tmp_path.glob("u_jagd-*.whl"))
|
|
with zipfile.ZipFile(wheel) as archive:
|
|
wheel_names = set(archive.namelist())
|
|
for name in TEMPLATE_NAMES:
|
|
assert f"data/editor_templates/{name}" in wheel_names
|
|
for name in ("index.html", "app.js", "style.css", "voice.js", "voice-worklet.js",
|
|
"sonar-audio-worklet.js"):
|
|
assert f"data/commander/{name}" in wheel_names
|
|
for name in CONTACT_NAMES:
|
|
assert f"data/contacts/{name}" in wheel_names
|
|
for name in LOADOUT_NAMES:
|
|
assert f"data/loadouts/{name}" in wheel_names
|
|
wheel_analysis = {name.removeprefix("data/contact_analysis/")
|
|
for name in wheel_names
|
|
if name.startswith("data/contact_analysis/")
|
|
and name != "data/contact_analysis/__init__.py"}
|
|
assert wheel_analysis == CONTACT_ANALYSIS_NAMES
|
|
with zipfile.ZipFile(wheel) as archive:
|
|
for name in CONTACT_ANALYSIS_NAMES:
|
|
assert archive.read(f"data/contact_analysis/{name}") == \
|
|
(ROOT / "data/contact_analysis" / name).read_bytes()
|
|
assert any(name.endswith(".dist-info/licenses/THIRD_PARTY_NOTICES.md")
|
|
for name in wheel_names)
|
|
assert any(name.endswith("-1.0.0.dist-info/METADATA") for name in wheel_names)
|
|
|
|
source = next(tmp_path.glob("u_jagd-*.tar.gz"))
|
|
with tarfile.open(source) as archive:
|
|
source_names = set(archive.getnames())
|
|
for name in TEMPLATE_NAMES:
|
|
assert any(path.endswith(f"/data/editor_templates/{name}") for path in source_names)
|
|
for name in ("index.html", "app.js", "style.css", "voice.js", "voice-worklet.js",
|
|
"sonar-audio-worklet.js"):
|
|
assert any(path.endswith(f"/data/commander/{name}") for path in source_names)
|
|
for name in CONTACT_NAMES:
|
|
assert any(path.endswith(f"/data/contacts/{name}") for path in source_names)
|
|
for name in LOADOUT_NAMES:
|
|
assert any(path.endswith(f"/data/loadouts/{name}") for path in source_names)
|
|
source_analysis = {Path(name).name for name in source_names
|
|
if "/data/contact_analysis/" in name
|
|
and not name.endswith("/__init__.py")}
|
|
assert source_analysis == CONTACT_ANALYSIS_NAMES
|
|
with tarfile.open(source) as archive:
|
|
for name in CONTACT_ANALYSIS_NAMES:
|
|
member = next(item for item in archive.getmembers()
|
|
if item.name.endswith(f"/data/contact_analysis/{name}"))
|
|
assert archive.extractfile(member).read() == \
|
|
(ROOT / "data/contact_analysis" / name).read_bytes()
|
|
assert any(path.endswith("/THIRD_PARTY_NOTICES.md") for path in source_names)
|
|
for name in ("install-hotspot-helper.sh",
|
|
"io.github.db9979.u-jagd.hotspot.policy",
|
|
"u-jagd-hotspot-helper"):
|
|
assert any(path.endswith(f"/packaging/uconsole/{name}") for path in source_names)
|
|
for name in ("docs/station-shortcuts.de.md",
|
|
"docs/station-shortcuts.de.pdf",
|
|
"tools/build_station_shortcuts_pdf.py"):
|
|
assert any(path.endswith("/" + name) for path in source_names)
|
|
|
|
installed = tmp_path / "installed"
|
|
subprocess.run(
|
|
[sys.executable, "-m", "pip", "install", "--no-deps", "--target",
|
|
str(installed), str(wheel)],
|
|
cwd=tmp_path, check=True, capture_output=True, text=True)
|
|
environment = os.environ.copy()
|
|
environment["PYTHONPATH"] = str(installed)
|
|
subprocess.run(
|
|
[sys.executable, "-c",
|
|
"from importlib import resources; "
|
|
"assert resources.files('data.editor_templates').joinpath('mission.json').is_file(); "
|
|
"from src.core.version import APP_VERSION; assert APP_VERSION == '1.0.0'; "
|
|
"from src.commander.server import CommanderServer; "
|
|
"server=CommanderServer(); server.start('127.0.0.1',0); server.stop(); "
|
|
"assert resources.files('data.commander').joinpath('app.js').is_file(); "
|
|
"assert resources.files('data.contacts').joinpath('sources.json').is_file(); "
|
|
"assert resources.files('data.loadouts').joinpath('ownship.json').is_file(); "
|
|
"from src.data.contact_analysis import load_contact_analysis_assets; "
|
|
"routes=load_contact_analysis_assets(); "
|
|
f"assert len(routes) == {len(CONTACT_ANALYSIS_NAMES)}"],
|
|
cwd=tmp_path, env=environment, check=True, capture_output=True, text=True)
|