-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_desktop.py
More file actions
149 lines (132 loc) · 4.76 KB
/
run_desktop.py
File metadata and controls
149 lines (132 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import argparse
import subprocess
import sys
from pathlib import Path
import sts2_recovery as recover
def default_gui_godot_exe(script_dir: Path) -> Path:
console_exe = recover.find_default_godot(script_dir)
return console_exe.with_name(console_exe.name.replace("_console", ""))
def parse_args() -> argparse.Namespace:
script_dir = Path(__file__).resolve().parent
parser = argparse.ArgumentParser(description="Build and launch the recovered Slay the Spire 2 Godot desktop project.")
parser.add_argument(
"--output-dir",
"-OutputDir",
type=Path,
default=script_dir / "build" / "recovered_project",
help="existing recovered project directory",
)
parser.add_argument(
"--godot-exe",
"-GodotExe",
type=Path,
default=None,
help="path to the Godot executable to launch",
)
parser.add_argument(
"--console",
action="store_true",
help="launch the console Godot executable instead of the GUI executable",
)
parser.add_argument(
"--skip-build",
"-SkipBuild",
action="store_true",
help="skip rebuilding the recovered desktop C# project before launch",
)
parser.add_argument(
"--skip-mod-build",
"-SkipModBuild",
action="store_true",
help="skip rebuilding the repo-owned development mod before launch",
)
parser.add_argument(
"--skip-logo",
action="store_true",
help="skip the intro logo via the repo debug startup flag",
)
parser.add_argument(
"--disable-deferred-startup",
action="store_true",
help="pass --debug-disable-deferred-startup to Godot",
)
parser.add_argument(
"--quit-after",
type=int,
default=0,
help="quit automatically after N seconds",
)
parser.add_argument(
"--log-file",
type=Path,
default=None,
help="optional Godot log file path",
)
parser.add_argument(
"extra_args",
nargs=argparse.REMAINDER,
help="extra arguments forwarded to Godot (prefix with --)",
)
return parser.parse_args()
def main() -> int:
args = parse_args()
script_dir = Path(__file__).resolve().parent
args.output_dir = args.output_dir.resolve()
recovered_project_ready = recover.recovery_has_usable_scaffold(args.output_dir) and (args.output_dir / "project.godot").exists()
if not recovered_project_ready:
print(
"未发现可用的已恢复工程,请先运行 "
"`python .\\recover_sts2_godot.py --force` 完成恢复。",
file=sys.stderr,
)
return 1
if args.godot_exe is None:
requested_godot_exe = recover.find_default_godot(script_dir) if args.console else default_gui_godot_exe(script_dir)
else:
requested_godot_exe = args.godot_exe.resolve()
args.godot_exe = recover.ensure_bundled_tool(
requested_exe=requested_godot_exe,
default_exe=recover.find_default_godot(script_dir) if args.console else default_gui_godot_exe(script_dir),
archive_path=script_dir / "tools" / "Godot_v4.5.1-stable_mono_win64.zip",
extract_root=script_dir / "tools" / "godot451",
label="godot",
)
recover.write_rider_run_assets(args.output_dir, args.godot_exe)
if not args.skip_build:
build_result = recover.build_project(args.output_dir)
if build_result.returncode != 0:
recover.log("desktop_build: FAIL")
return 1
if not args.skip_mod_build:
mod_csproj = recover.write_generated_mod_project(script_dir, args.output_dir)
recover.add_mod_project_to_solution(args.output_dir, mod_csproj)
mod_build_result = recover.build_mod_project(mod_csproj)
if mod_build_result.returncode != 0:
recover.log("desktop_mod_build: FAIL")
return 1
cmd = [
str(args.godot_exe),
"--path",
str(args.output_dir),
]
if args.skip_logo:
cmd.append("--debug-skip-logo")
if args.disable_deferred_startup:
cmd.append("--debug-disable-deferred-startup")
if args.quit_after > 0:
cmd.extend(["--quit-after", str(args.quit_after)])
if args.log_file is not None:
cmd.extend(["--log-file", str(args.log_file.resolve())])
extra_args = list(args.extra_args)
if extra_args and extra_args[0] == "--":
extra_args = extra_args[1:]
cmd.extend(extra_args)
recover.log("$ " + subprocess.list2cmdline(cmd))
completed = subprocess.run(cmd, cwd=str(args.output_dir), check=False)
return completed.returncode
if __name__ == "__main__":
try:
raise SystemExit(main())
except Exception as exc:
print(f"ERROR: {exc}", file=sys.stderr)
raise