validate_mounted_ground_offsets.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env python3
  2. """
  3. Validate that mounted troop configs do not carry per-unit ground offsets.
  4. """
  5. from __future__ import annotations
  6. import json
  7. import sys
  8. from pathlib import Path
  9. MOUNTED_IDS = {"horse_swordsman", "horse_archer", "horse_spearman"}
  10. DATA_ROOT = Path(__file__).resolve().parent.parent / "assets" / "data"
  11. def load_troops(path: Path) -> list[dict]:
  12. with path.open("r", encoding="utf-8") as f:
  13. data = json.load(f)
  14. return data.get("troops", [])
  15. def main() -> int:
  16. files = [DATA_ROOT / "troops" / "base.json"]
  17. files.extend(sorted((DATA_ROOT / "nations").glob("*.json")))
  18. errors = []
  19. for path in files:
  20. for troop in load_troops(path):
  21. troop_id = troop.get("id")
  22. if troop_id not in MOUNTED_IDS:
  23. continue
  24. visuals = troop.get("visuals", {})
  25. val = visuals.get("selection_ring_ground_offset")
  26. if val not in (None, 0, 0.0):
  27. errors.append(
  28. f"{path}: {troop_id} has non-zero selection_ring_ground_offset {val}"
  29. )
  30. if errors:
  31. for err in errors:
  32. print(err, file=sys.stderr)
  33. return 1
  34. print("Mounted ground offsets are empty/zero across configs.")
  35. return 0
  36. if __name__ == "__main__":
  37. raise SystemExit(main())