76 lines
No EOL
2.5 KiB
Python
76 lines
No EOL
2.5 KiB
Python
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from psx_extract_wdl import extract, summarize
|
|
|
|
|
|
def find_wdl_files(root: Path) -> list[Path]:
|
|
return sorted(
|
|
path
|
|
for path in root.rglob("*")
|
|
if path.is_file() and path.suffix.lower() == ".wdl"
|
|
)
|
|
|
|
|
|
def build_index_entry(root: Path, path: Path, summary: dict[str, object]) -> dict[str, object]:
|
|
relative_path = path.relative_to(root)
|
|
sprite_bundles = summary.get("sprite_bundles", [])
|
|
return {
|
|
"source": relative_path.as_posix(),
|
|
"stem": path.stem,
|
|
"kind": summary["kind"],
|
|
"region_count": len(summary.get("regions", [])),
|
|
"tim_count": len(summary.get("tim_hits", [])),
|
|
"sprite_bundle_count": len(sprite_bundles),
|
|
}
|
|
|
|
|
|
def run_batch(input_root: Path, output_root: Path) -> list[dict[str, object]]:
|
|
files = find_wdl_files(input_root)
|
|
if not files:
|
|
raise SystemExit(f"no .WDL files found under {input_root}")
|
|
|
|
index: list[dict[str, object]] = []
|
|
for path in files:
|
|
relative_parent = path.relative_to(input_root).parent
|
|
target_root = output_root / relative_parent
|
|
summary = extract(path, target_root)
|
|
|
|
log_path = target_root / path.stem / "summary.txt"
|
|
log_path.write_text(summarize(path, summary) + "\n", encoding="ascii")
|
|
index.append(build_index_entry(input_root, path, summary))
|
|
|
|
index_path = output_root / "index.json"
|
|
index_path.parent.mkdir(parents=True, exist_ok=True)
|
|
index_path.write_text(json.dumps(index, indent=2), encoding="ascii")
|
|
return index
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description="Extract all Crusader PSX WDL files under a directory tree.")
|
|
parser.add_argument("input_root", type=Path, help="Root directory to scan for .WDL files")
|
|
parser.add_argument(
|
|
"--output",
|
|
type=Path,
|
|
default=Path("out") / "psx_wdl_disc",
|
|
help="Directory where extracted per-file outputs are written",
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
index = run_batch(args.input_root, args.output)
|
|
print(f"input_root: {args.input_root}")
|
|
print(f"output_root: {args.output}")
|
|
print(f"wdl_files: {len(index)}")
|
|
for entry in index:
|
|
print(
|
|
f" {entry['source']}: kind={entry['kind']} tims={entry['tim_count']} "
|
|
f"sprite_bundles={entry['sprite_bundle_count']}"
|
|
)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main()) |