"""解析 Godot 的 user:// 根目录——与 game/override.cfg 的隔离口径同一份。 无 override.cfg(主工作区)→ %APPDATA%/Godot/app_userdata/; 有 override.cfg(代码面 worktree,由 tools/setup_worktree_userdir.sh 生成)→ %APPDATA%/。 """ import os import re from pathlib import Path def _project_name(repo_root: Path) -> str: text = (Path(repo_root) / "game" / "project.godot").read_text(encoding="utf-8", errors="replace") m = re.search(r'^config/name="([^"]*)"', text, re.M) return m.group(1) if m else "DungeonSweeperVerticalSlice" def resolve_user_dir(repo_root: Path) -> Path: base = Path(os.environ.get("APPDATA") or (Path.home() / "AppData" / "Roaming")) override = Path(repo_root) / "game" / "override.cfg" if override.is_file(): text = override.read_text(encoding="utf-8", errors="replace") custom = re.search(r'^config/use_custom_user_dir=true\s*$', text, re.M) name = re.search(r'^config/custom_user_dir_name="([^"]*)"', text, re.M) if custom and name and name.group(1): return base / name.group(1) return base / "Godot" / "app_userdata" / _project_name(Path(repo_root))