- 加入 Godot 基础试玩、画风展示和通孔验证场景 - 支持自由放球、多层叠放、墙壁、锥口球洞及固定 +5 m/s 定向加速方块 - 保存 Blender 源资产、模型导出、资源制作脚本和关卡编辑存档逻辑 - 按七类目录归档工程,集中 zsh 启动入口并补充 AGENTS.md 文件索引 - 同步设计规则、依赖锁定、验证报告和目录迁移记录 验证:目录迁移后的资源导入与四个场景加载通过;本次提交前检查暂存内容,未重复运行整套物理测试。
107 lines
4.8 KiB
Python
107 lines
4.8 KiB
Python
"""IntoHole native playtest launcher. Use the project's uv-managed environment."""
|
|
from __future__ import annotations
|
|
import argparse
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
GAME = ROOT / 'godot_engine'
|
|
VALIDATION = ROOT / 'playtest/artifacts/baseline'
|
|
|
|
|
|
def executable(name: str) -> Path:
|
|
override = os.environ.get(f'INTOHOLE_{name.upper()}')
|
|
candidates = [override] if override else []
|
|
if name == 'blender':
|
|
candidates += ['/Applications/Blender.app/Contents/MacOS/Blender', shutil.which('blender')]
|
|
else:
|
|
candidates += [str(ROOT/'godot_engine/bin/godot'), str(ROOT/'godot_engine/bin/Godot.app/Contents/MacOS/Godot')]
|
|
candidates += ['/Applications/Godot.app/Contents/MacOS/Godot', shutil.which('godot')]
|
|
for base in [Path('/Applications'), Path.home() / 'Applications']:
|
|
if base.exists():
|
|
for app in sorted(base.glob('*Godot*.app'), reverse=True):
|
|
candidates.append(str(app/'Contents/MacOS/Godot'))
|
|
for candidate in candidates:
|
|
if candidate and Path(candidate).is_file():
|
|
# Blender needs its real bundle path to locate Python/resources.
|
|
return Path(candidate).resolve()
|
|
raise SystemExit(f'{name} executable not found. Set INTOHOLE_{name.upper()}.')
|
|
|
|
|
|
def run(command: list[str | Path], name: str, live=False) -> None:
|
|
VALIDATION.mkdir(parents=True, exist_ok=True)
|
|
command = list(map(str, command))
|
|
print('Running:', ' '.join(command), flush=True)
|
|
if live:
|
|
subprocess.run(command, cwd=ROOT, check=True)
|
|
else:
|
|
log = VALIDATION / f'{name}.log'
|
|
with log.open('w') as stream:
|
|
result = subprocess.run(command, cwd=ROOT, stdout=stream, stderr=subprocess.STDOUT, timeout=180)
|
|
text = log.read_text(errors='replace')
|
|
if result.returncode or 'SCRIPT ERROR:' in text:
|
|
print(text[-10000:])
|
|
raise SystemExit(result.returncode or 1)
|
|
print(f'Log: {log}')
|
|
|
|
|
|
def import_assets(godot: Path) -> None:
|
|
run([godot, '--headless', '--path', GAME, '--log-file', VALIDATION/'import_engine.log', '--import'], 'import')
|
|
|
|
|
|
def build() -> None:
|
|
run([executable('blender'), '--background', '--factory-startup', '--python-exit-code', '1', '--python', ROOT/'assets/collections/baseline/source/build.py'], 'asset_build')
|
|
import_assets(executable('godot'))
|
|
report = json.loads((VALIDATION/'geometry_report.json').read_text())
|
|
for asset in report['assets']:
|
|
flag = 'OK' if asset['declared_size_compliant'] else 'PROTOTYPE EXCEEDS DECLARED SIZE'
|
|
print(f"{asset['id']}: {asset['size_m']} m — {flag}")
|
|
|
|
|
|
def ensure_imported(godot: Path) -> None:
|
|
if not (ROOT/'assets/collections/baseline/catalog.json').exists():
|
|
build()
|
|
elif not (GAME/'.godot').exists():
|
|
import_assets(godot)
|
|
|
|
|
|
def main() -> None:
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('command', nargs='?', default='play', choices=['doctor','build','play','merge','test','capture'])
|
|
args = parser.parse_args()
|
|
godot = executable('godot')
|
|
if args.command == 'doctor':
|
|
print('Python:', sys.executable)
|
|
for name in ['blender','godot']:
|
|
path = executable(name)
|
|
print(f'{name}: {path}')
|
|
subprocess.run([str(path), '--version'], check=True)
|
|
return
|
|
if args.command == 'build':
|
|
build()
|
|
return
|
|
ensure_imported(godot)
|
|
common = [godot, '--path', GAME, '--log-file', VALIDATION/'playtest_engine.log']
|
|
if args.command == 'play':
|
|
run(common+['--scene','res://playtest/baseline/scenes/main.tscn'],'playtest',live=True)
|
|
elif args.command == 'merge':
|
|
scenarios = json.loads((ROOT/'playtest/baseline/data/scenarios.json').read_text())
|
|
index = next(i for i, scenario in enumerate(scenarios) if scenario['id'] == 'dual_merge')
|
|
run(common+['--scene','res://playtest/baseline/scenes/main.tscn','--',f'--scenario={index}'],'merge',live=True)
|
|
elif args.command == 'test':
|
|
import_assets(godot)
|
|
run(common+['--headless','--fixed-fps','120','--script','res://playtest/baseline/checks/validate_physics.gd'],'physics_test')
|
|
run(common+['--headless','--fixed-fps','120','--script','res://playtest/baseline/checks/validate_playtest.gd'],'playtest_test')
|
|
run(common+['--headless','--fixed-fps','120','--script','res://playtest/baseline/checks/validate_merge.gd'],'merge_test')
|
|
print('Validation reports:', VALIDATION)
|
|
else:
|
|
run(common+['--scene','res://playtest/baseline/scenes/main.tscn','--',f'--capture={VALIDATION / "playtest_preview.png"}'],'capture')
|
|
print('Preview:', VALIDATION/'playtest_preview.png')
|
|
|
|
if __name__ == '__main__':
|
|
main()
|