Gerador de vídeos narrativos (Godot + FFmpeg), painel Next.js, serviço de voz, Clipador de lives e Publicador para YouTube, TikTok e Instagram. Inclui a leitura das visualizações dos posts para o Dashboard e o botão "Publicar no <rede>" nos cartões das publicações. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
87 lines
3.2 KiB
Python
87 lines
3.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Cria config/<id>.json a partir de uma cena base, com alterações por caminho, e valida na Godot.
|
|
|
|
Economiza tokens: o agente não lê nem reescreve o JSON inteiro para mudar poucos campos.
|
|
|
|
Uso:
|
|
python .claude/skills/cenaforge/scripts/new_scene.py --id ep01-cena02 \\
|
|
--set overlay.title="Um pacote sem remetente." --set rider.travelMeters=36 \\
|
|
--set camera.offset=[1.2,2.8,5.6]
|
|
Opções: --base (padrão config/demo-street.json), --force (sobrescreve), --no-validate.
|
|
Valores são lidos como JSON quando possível (números, listas, true, null); senão, como texto.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import re
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
from _common import REPO_ROOT, find_tool, load_json, rel, utf8_stdout
|
|
|
|
|
|
def parse_value(raw: str):
|
|
try:
|
|
return json.loads(raw)
|
|
except json.JSONDecodeError:
|
|
return raw
|
|
|
|
|
|
def main() -> int:
|
|
utf8_stdout()
|
|
ap = argparse.ArgumentParser(description="Cria uma cena nova a partir de outra.")
|
|
ap.add_argument("--id", required=True)
|
|
ap.add_argument("--base", default="config/demo-street.json")
|
|
ap.add_argument("--set", action="append", default=[], metavar="caminho=valor")
|
|
ap.add_argument("--force", action="store_true")
|
|
ap.add_argument("--no-validate", action="store_true")
|
|
args = ap.parse_args()
|
|
|
|
if not re.fullmatch(r"[a-z0-9][a-z0-9_-]{0,63}", args.id):
|
|
print("id inválido: use minúsculas, números, '-' e '_'")
|
|
return 2
|
|
base = Path(args.base) if Path(args.base).is_absolute() else REPO_ROOT / args.base
|
|
scene = load_json(base)
|
|
scene["id"] = args.id
|
|
for item in args.set:
|
|
if "=" not in item:
|
|
print(f"--set sem '=': {item}")
|
|
return 2
|
|
path, raw = item.split("=", 1)
|
|
keys = path.split(".")
|
|
node = scene
|
|
for k in keys[:-1]:
|
|
if not isinstance(node.get(k), dict):
|
|
print(f"caminho inexistente na cena base: {path}")
|
|
return 2
|
|
node = node[k]
|
|
node[keys[-1]] = parse_value(raw)
|
|
|
|
out = REPO_ROOT / "config" / f"{args.id}.json"
|
|
if out.exists() and not args.force:
|
|
print(f"{rel(out)} já existe (use --force)")
|
|
return 2
|
|
text = json.dumps(scene, ensure_ascii=False, indent=2)
|
|
# Vetores [x, y, z] numa linha só, como nos exemplos do projeto.
|
|
text = re.sub(r"\[\s*([-\d.eE]+),\s*([-\d.eE]+),\s*([-\d.eE]+)\s*\]", r"[\1, \2, \3]", text)
|
|
out.write_text(text + "\n", encoding="utf-8", newline="\n")
|
|
print("criado", rel(out))
|
|
|
|
if args.no_validate:
|
|
return 0
|
|
godot = find_tool("godot")
|
|
if not godot:
|
|
print("Godot não encontrada; validação pulada (pnpm render valida antes de renderizar)")
|
|
return 0
|
|
r = subprocess.run([godot, "--headless", "--path", str(REPO_ROOT / "godot"), "--",
|
|
"--config", str(out), "--validate-only"],
|
|
capture_output=True, text=True, encoding="utf-8", errors="replace")
|
|
lines = [l for l in (r.stdout + r.stderr).splitlines() if l.startswith(("CONFIG_", " - "))]
|
|
print("\n".join(lines) or f"validação saiu com código {r.returncode}")
|
|
return 0 if r.returncode == 0 else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|