Files
IntoHole/scripts/python/baseline.py
T
Yanchen bf6c355fa6 feat: 切换至滚动阻力运行模型并更新资产、编辑器与验证
- 物理规则:现行模型仅保留滚动阻力耗能与恢复系数碰撞,风力、空气阻力、静摩擦、动摩擦不再参与运行;确认三球质量 60/330/约890 kg 及水密度、流阻参数
- 定向加速改为真实顶面接触触发的一次性 +5 m/s 速度事件,模型新增渐进式 U 形导槽出口
- 更新球体、滑槽、水/冰/墙、球洞模型与 storybook 目录、物理、实体配置
- 工坊摆放、编辑器、运行适配与检查脚本同步;删除过时的 baseline 三组检查
- 新增谜题设计参考文档、关卡草稿与本轮实验产物
2026-12-05 10:37:31 +08:00

101 lines
4.3 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','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)
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()