117 lines
4.7 KiB
Python
117 lines
4.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Validate the frozen MVP fixture against the seed pack and P2 asset manifest."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
from typing import Any, Dict, Iterable, List, Set
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def read_json(path: Path) -> Dict[str, Any]:
|
|
with path.open("r", encoding="utf-8") as handle:
|
|
value = json.load(handle)
|
|
if not isinstance(value, dict):
|
|
raise ValueError(f"expected JSON object: {path}")
|
|
return value
|
|
|
|
|
|
def ids(rows: Iterable[Dict[str, Any]]) -> Set[str]:
|
|
return {str(row["id"]) for row in rows}
|
|
|
|
|
|
def check_required(rows: Iterable[Dict[str, Any]], fields: Iterable[str]) -> List[str]:
|
|
missing: List[str] = []
|
|
for row in rows:
|
|
for field in fields:
|
|
if field not in row:
|
|
missing.append(f"{row.get('id', '<unknown>')}.{field}")
|
|
return missing
|
|
|
|
|
|
def validate(fixture: Dict[str, Any], seed_pack: Dict[str, Any], manifest: Dict[str, Any]) -> Dict[str, Any]:
|
|
checks: List[Dict[str, Any]] = []
|
|
hero_ids = ids(fixture["heroes"])
|
|
enemy_ids = ids(fixture["enemies"])
|
|
pressure_enemy_ids = ids(fixture["validation_pressure_enemies"])
|
|
boss_ids = ids(fixture["bosses"])
|
|
node_ids = ids(fixture["nodes"])
|
|
|
|
required_fields = {
|
|
"heroes": ["id", "signature", "base_atk", "base_spd", "base_dps", "unlock_node_id"],
|
|
"enemies": ["id", "kind", "hp_mult", "armor", "shield_max", "weak_tag"],
|
|
"bosses": ["id", "hp", "armor", "shield_max", "timer_sec", "phase_ids"],
|
|
"nodes": ["id", "node_type", "wave_ids", "reward_id"],
|
|
}
|
|
for group, fields in required_fields.items():
|
|
missing = check_required(fixture[group], fields)
|
|
checks.append({"id": f"required_fields:{group}", "pass": not missing, "missing": missing})
|
|
|
|
manifest_fixture = manifest["content_fixture"]
|
|
checks.append({
|
|
"id": "manifest_fixture_ids",
|
|
"pass": (
|
|
set(manifest_fixture["hero_ids"]) == hero_ids
|
|
and set(manifest_fixture["enemy_ids"]) == enemy_ids
|
|
and set(manifest_fixture["boss_ids"]) == boss_ids
|
|
and set(manifest_fixture["node_ids"]) == node_ids
|
|
),
|
|
"manifest_heroes": manifest_fixture["hero_ids"],
|
|
"fixture_heroes": sorted(hero_ids),
|
|
"manifest_enemies": manifest_fixture["enemy_ids"],
|
|
"fixture_enemies": sorted(enemy_ids),
|
|
})
|
|
|
|
referenced_heroes = set()
|
|
referenced_enemies = set()
|
|
for scenario in seed_pack["scenarios"]:
|
|
referenced_heroes.update(scenario["visible_hero_ids"])
|
|
referenced_enemies.update(scenario["enemy_ids"])
|
|
checks.append({
|
|
"id": "seed_references",
|
|
"pass": (
|
|
referenced_heroes <= hero_ids
|
|
and referenced_enemies <= (enemy_ids | pressure_enemy_ids | boss_ids)
|
|
),
|
|
"unknown_heroes": sorted(referenced_heroes - hero_ids),
|
|
"unknown_enemies": sorted(referenced_enemies - (enemy_ids | pressure_enemy_ids | boss_ids)),
|
|
})
|
|
|
|
asset_rows = manifest["assets"]
|
|
missing_assets = [row["path"] for row in asset_rows if row["status"] != "reference_only" and not (ROOT / row["path"]).exists()]
|
|
checks.append({"id": "asset_paths", "pass": not missing_assets, "missing": missing_assets})
|
|
|
|
vfx_ids = {row["vfx_id"] for row in manifest["procedural_vfx"]}
|
|
checks.append({
|
|
"id": "procedural_vfx_count",
|
|
"pass": len(vfx_ids) == 3 and "vfx.common.hit_light" in vfx_ids and "vfx.common.shield_break" in vfx_ids,
|
|
"count": len(vfx_ids),
|
|
"vfx_ids": sorted(vfx_ids),
|
|
})
|
|
return {"schema": 1, "checks": checks, "pass": all(check["pass"] for check in checks)}
|
|
|
|
|
|
def main(argv: List[str]) -> int:
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--fixture", type=Path, default=Path("data/mvp_content_fixture.json"))
|
|
parser.add_argument("--seed-pack", type=Path, default=Path("data/mvp_validation_seed_pack.json"))
|
|
parser.add_argument("--manifest", type=Path, default=Path("data/mvp_p2_validation_manifest.json"))
|
|
parser.add_argument("--out", type=Path, default=Path("data/mvp_content_validation_results.json"))
|
|
args = parser.parse_args(argv)
|
|
result = validate(read_json(args.fixture), read_json(args.seed_pack), read_json(args.manifest))
|
|
args.out.write_text(json.dumps(result, ensure_ascii=False, sort_keys=True, separators=(",", ":")) + "\n", encoding="utf-8")
|
|
for check in result["checks"]:
|
|
print(f"{check['id']}: {'PASS' if check['pass'] else 'FAIL'}")
|
|
print(f"overall: {'PASS' if result['pass'] else 'FAIL'}")
|
|
print(f"wrote {args.out}")
|
|
return 0 if result["pass"] else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main(sys.argv[1:]))
|