magicciv/tools/strip-legacy-biomes.py
Natalie e5b9d10b61 feat(@projects/@magic-civilization): add lab and hud system components
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
2026-05-01 22:23:54 -04:00

65 lines
2 KiB
Python

#!/usr/bin/env python3
"""Remove the legacy `biomes[]` array key from flora and fauna species JSON files.
The `substrate_climate[]` array (added by migrate-flora-biomes.py and
migrate-fauna-biomes.py) is now the canonical ecology key. The `biomes[]`
array was retained during the transition period while p2-50 save-format
coordination was pending. That blocker is resolved (mc-save crate landed);
this script completes the removal.
Usage:
python3 tools/strip-legacy-biomes.py [--dry-run]
Modifies in-place:
public/resources/ecology/flora/species/*.json
public/resources/ecology/fauna/species/*.json
"""
import json
import sys
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent
FLORA_DIR = REPO_ROOT / "public/resources/ecology/flora/species"
FAUNA_DIR = REPO_ROOT / "public/resources/ecology/fauna/species"
DRY_RUN = "--dry-run" in sys.argv
def strip_biomes_from_dir(species_dir: Path) -> tuple[int, int]:
"""Remove `biomes` key from all JSON files in directory.
Returns (files_modified, files_skipped).
"""
modified = 0
skipped = 0
for path in sorted(species_dir.glob("*.json")):
text = path.read_text(encoding="utf-8")
data = json.loads(text)
if "biomes" not in data:
skipped += 1
continue
del data["biomes"]
if not DRY_RUN:
path.write_text(
json.dumps(data, indent=2, ensure_ascii=False) + "\n",
encoding="utf-8",
)
modified += 1
return modified, skipped
def main() -> None:
if DRY_RUN:
print("[dry-run] No files will be written.")
flora_mod, flora_skip = strip_biomes_from_dir(FLORA_DIR)
fauna_mod, fauna_skip = strip_biomes_from_dir(FAUNA_DIR)
print(f"Flora: {flora_mod} modified, {flora_skip} already clean")
print(f"Fauna: {fauna_mod} modified, {fauna_skip} already clean")
print(f"Total: {flora_mod + fauna_mod} files stripped of legacy biomes[]")
if __name__ == "__main__":
main()