diff --git a/tools/airdef_assets/catalog.py b/tools/airdef_assets/catalog.py index 117d392..ae3f05f 100644 --- a/tools/airdef_assets/catalog.py +++ b/tools/airdef_assets/catalog.py @@ -165,10 +165,16 @@ def _rest_pitch(entry, where): def load_specs(): """Load the numeric profiles shared by Rust and Python, validating every reference.""" - data = json.loads(SPECS.read_text(encoding="utf-8")) + return validate_specs(json.loads(SPECS.read_text(encoding="utf-8")), load(), + {entry["event"] for entry in load_sounds()}) + + +def validate_specs(data, content, events): + """Check a specs document against the content identities and registered sound events. + + Nothing here names a unit or aircraft kind: a new type only needs its catalog entry. + """ _exact(data, {"shared", "drones", "units", "missiles", "named"}, "specs.json") - events = {entry["event"] for entry in load_sounds()} - content = load() shared = data["shared"] _exact(shared, {"mobility", "flight", "logistics"}, "shared") @@ -280,7 +286,6 @@ def load_specs(): unit_kinds = [] used_missiles = set() - armed = {"Patriot", "Gepard", "Pantsir", "S400", "S500", "IrisT", "Nasams", "Buk", "Tor", "P1sun"} for i, entry in enumerate(data["units"]): where = f"units[{i}]" _exact(entry, {"kind", "key", "name", "missile", "gun", "reload", "scale", "rest_pitch", @@ -334,10 +339,6 @@ def load_specs(): raise ValueError(f"{where}.gun.slew: expected [yaw, pitch]") for j, v in enumerate(gun["slew"]): _number(v, f"{where}.gun.slew[{j}]", 0) - if kind in armed and missile is None and gun is None: - raise ValueError(f"{where}: an armed unit needs missiles or a gun") - if kind not in armed and (missile is not None or gun is not None): - raise ValueError(f"{where}: a support unit has no weapons") if set(drone_kinds) != {entry["kind"] for entry in content["aircraft"]}: raise ValueError("specs.json drones and content.json aircraft disagree") diff --git a/tools/test_gen_assets.py b/tools/test_gen_assets.py index 990b4ae..22b6571 100644 --- a/tools/test_gen_assets.py +++ b/tools/test_gen_assets.py @@ -15,6 +15,7 @@ from PIL import Image TOOLS = Path(__file__).resolve().parent sys.path.insert(0, str(TOOLS)) +from airdef_assets import catalog from airdef_assets import pipeline from airdef_assets import icons import gen_tex @@ -33,6 +34,18 @@ class ContentCatalogTests(unittest.TestCase): self.assertEqual(language[f"item.airdef.{name}"], title) self.assertTrue((root / "airdef-mod/data/airdef/horizon/item" / (name + ".json")).is_file()) + def test_a_new_unit_kind_needs_only_catalog_entries(self): + # The validator must not carry its own list of kind names: a hypothetical unit is + # accepted from a specs row plus its content entry, with no code change. + data = json.loads(json.dumps(catalog.load_specs())) + content = json.loads(json.dumps(catalog.load())) + template = next(entry for entry in data["units"] if entry["gun"] is not None) + added = dict(template, kind="TestGun", key="testgun", name="Test gun") + data["units"].append(added) + content["units"].append({"kind": "TestGun", "item": None}) + events = {entry["event"] for entry in catalog.load_sounds()} + catalog.validate_specs(data, content, events) + class ManifestTests(unittest.TestCase): def test_manifest_rejects_traversal_and_duplicate_paths(self):