41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
"""List dwarf-buildable units grouped by tier."""
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def main() -> int:
|
|
units_dir = Path("public/games/age-of-dwarves/data/units")
|
|
if not units_dir.is_dir():
|
|
print(f"missing: {units_dir}", file=sys.stderr)
|
|
return 2
|
|
tiers: dict[int, list[tuple[str, str, str]]] = {}
|
|
for path in sorted(units_dir.iterdir()):
|
|
if not path.suffix == ".json" or path.name == "manifest.json":
|
|
continue
|
|
try:
|
|
d = json.loads(path.read_text())
|
|
except Exception:
|
|
continue
|
|
# Unit JSON files contain either a single dict or a list of dicts.
|
|
records = d if isinstance(d, list) else [d]
|
|
for rec in records:
|
|
if not isinstance(rec, dict):
|
|
continue
|
|
race = rec.get("race_required") or "any"
|
|
if race not in ("dwarf", "any"):
|
|
continue
|
|
uid = str(rec.get("id") or "")
|
|
if "wild" in uid or uid in ("", "None"):
|
|
continue
|
|
tier = int(rec.get("tier", 0))
|
|
tiers.setdefault(tier, []).append((uid, race, str(rec.get("tech_required", ""))))
|
|
for t in sorted(tiers):
|
|
rows = ", ".join(f"{u}({tech or '-'})" for u, _, tech in tiers[t])
|
|
print(f"tier {t}: {rows}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|