cocos-farm/tools/generate_cocos4_project.py

71 lines
2.0 KiB
Python

#!/usr/bin/env python3
"""Generate first-stage Cocos-facing scene data from source evidence.
The Cocos 4 alpha CLI on this machine cannot currently build because of a
native ABI mismatch. This script therefore writes source-backed scene data that
can be consumed by a later Cocos 4 scene writer once the CLI/runtime is fixed.
"""
from __future__ import annotations
import json
from pathlib import Path
from typing import Any
PROJECT = Path(__file__).resolve().parents[1]
SOURCE_NODES = PROJECT / "source_export/source_nodes.json"
def read_json(path: Path) -> Any:
with path.open("r", encoding="utf-8") as fh:
return json.load(fh)
def mkdir_keep(path: Path) -> None:
path.mkdir(parents=True, exist_ok=True)
keep = path / ".gitkeep"
if not keep.exists():
keep.write_text("", encoding="utf-8")
def main() -> None:
data = read_json(SOURCE_NODES)
for rel in [
"assets/scenes",
"assets/prefabs",
"assets/scripts",
"assets/scripts/mock",
"assets/resources",
"assets/bundles",
"assets/textures",
"assets/spine",
"assets/audio",
"assets/configs",
"assets/i18n",
"artifacts/cocos_capture",
"artifacts/visual_compare",
]:
mkdir_keep(PROJECT / rel)
scene = {
"format": "cocos4_stage1_source_scene",
"status": "source_backed_intermediate_scene_data",
"design_resolution": data["design_resolution"],
"nodes": {
"startup": data["canvas_and_cameras"],
"backgrounds": data["background_nodes"],
"land_candidates": data["land_candidates"],
"house_and_doghouse": data["house_and_doghouse"],
"bottom_menu": data["bottom_menu_nodes"],
},
"blockers": data["blockers"],
}
out = PROJECT / "assets/scenes/main_stage1.source_scene.json"
out.write_text(json.dumps(scene, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
print(out)
if __name__ == "__main__":
main()