Skip to content

Commit d83a3e4

Browse files
author
REME
committed
2026-04-02 调试、热重载
1 parent 136ac22 commit d83a3e4

3 files changed

Lines changed: 154 additions & 4 deletions

File tree

Basics/01 - 环境配置/README.md

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ https://github.com/freude916/sts2-quickRestart/blob/main/README.md
2525

2626
## 选择文本编辑器
2727

28-
选择一个文本编辑器。可以使用[Visual Studio Code](https://code.visualstudio.com/)或者[Rider](https://www.jetbrains.com/zh-cn/rider/download/?section=windows)推荐新手使用Rider)。另外也可以使用 Visual Studio等其他 IDE。以下只介绍 VS Code 的配置方法。
28+
选择一个文本编辑器。可以使用[Visual Studio Code](https://code.visualstudio.com/)或者[Rider](https://www.jetbrains.com/zh-cn/rider/download/?section=windows)<b>强烈推荐</b>新手使用Rider)。另外也可以使用Visual Studio等其他 IDE。以下只介绍 VS Code 的配置方法。
2929

30-
## 安装VS Code插件
30+
## 安装VS Code插件(可选)
3131

3232
安装[C# Dev Kit](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csdevkit)。你还可以安装[Godot Tools](https://marketplace.visualstudio.com/items?itemName=geequlim.godot-tools)等插件。
3333

34+
记得打开设置把自动保存开了。
35+
3436
![alt text](../../images/image2.png)
3537

3638
## 参考官方文档
@@ -76,6 +78,7 @@ https://github.com/freude916/sts2-quickRestart/blob/main/README.md
7678
```xml
7779
<Project Sdk="Godot.NET.Sdk/4.5.1">
7880
<PropertyGroup>
81+
<!-- 如果你安装了10.0并遇到问题,改下这里 -->
7982
<TargetFramework>net9.0</TargetFramework>
8083
<ImplicitUsings>true</ImplicitUsings>
8184
<LangVersion>12.0</LangVersion>
@@ -173,4 +176,54 @@ public class Entry
173176

174177
## 不启动Godot打包(可选)
175178

176-
Godot支持命令行导出pck(首先你需要添加一个导出配置),例如使用终端命令:`"{你的godot.exe的路径}" --headless --export-pack "{你的导出配置的名字,例如Windows Desktop}" "{杀戮尖塔根目录}/mods/{你的modid}/{你的modid}.pck"`,参考 https://docs.godotengine.org/zh-cn/4.x/tutorials/editor/command_line_tutorial.html#exporting 。你可以把这个命令保存成一个cmd或者csproj里的target,自行搜索相关配置说明。
179+
Godot支持命令行导出pck(首先你需要添加一个导出配置),例如使用终端命令:`"{你的godot.exe的路径}" --headless --export-pack "{你的导出配置的名字,例如Windows Desktop}" "{杀戮尖塔根目录}/mods/{你的modid}/{你的modid}.pck"`,参考 https://docs.godotengine.org/zh-cn/4.x/tutorials/editor/command_line_tutorial.html#exporting 。你可以把这个命令保存成一个cmd或者csproj里的target。
180+
181+
例如在你的`.csproj`文件里添加`GodoExe``ExportPck`的内容:
182+
183+
```xml
184+
<Project Sdk="Godot.NET.Sdk/4.5.1">
185+
<PropertyGroup>
186+
<TargetFramework>net9.0</TargetFramework>
187+
<ImplicitUsings>true</ImplicitUsings>
188+
<LangVersion>12.0</LangVersion>
189+
<Nullable>enable</Nullable>
190+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
191+
192+
<Sts2Dir>D:/Files/Softwares/Steam/steamapps/common/Slay the Spire 2</Sts2Dir>
193+
<!-- 新增 -->
194+
<GodotExe>D:/Files/Projects/godot/Godot_v4.5.1-stable_mono_win64/Godot_v4.5.1-stable_mono_win64/Godot_v4.5.1-stable_mono_win64.exe</GodotExe>
195+
<Sts2DataDir>$(Sts2Dir)/data_sts2_windows_x86_64</Sts2DataDir>
196+
</PropertyGroup>
197+
198+
<ItemGroup>
199+
<Reference Include="sts2">
200+
<HintPath>$(Sts2DataDir)/sts2.dll</HintPath>
201+
<Private>false</Private>
202+
</Reference>
203+
204+
<Reference Include="0Harmony">
205+
<HintPath>$(Sts2DataDir)/0Harmony.dll</HintPath>
206+
<Private>false</Private>
207+
</Reference>
208+
</ItemGroup>
209+
210+
<Target Name="Copy Mod" AfterTargets="PostBuildEvent">
211+
<Message Text="Copying mod to Slay the Spire 2 mods folder..." Importance="high" />
212+
<MakeDir Directories="$(Sts2Dir)/mods/" />
213+
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(Sts2Dir)/mods/$(MSBuildProjectName)/" />
214+
<Copy SourceFiles="$(MSBuildProjectName).json" DestinationFolder="$(Sts2Dir)/mods/$(MSBuildProjectName)/" />
215+
</Target>
216+
217+
<!-- 新增 -->
218+
<Target Name="ExportPck">
219+
<Message Text="Copying PCK to Slay the Spire 2 mods folder..." Importance="high" />
220+
<Exec Command="&quot;$(GodotExe)&quot; --headless --export-pack &quot;Windows Desktop&quot; &quot;$(Sts2Dir)/mods/$(MSBuildProjectName)/$(MSBuildProjectName).pck&quot;"
221+
EnvironmentVariables="IsInnerGodotExport=true;MSBUILDDISABLENODEREUSE=1"
222+
ContinueOnError="WarnAndContinue" />
223+
</Target>
224+
</Project>
225+
```
226+
227+
然后控制台输入`dotnet build -t:ExportPck`即可连PCK一起导出。输入`dotnet build`仅编译dll。
228+
229+
方法不限。你也可以使用`tasks.json`

Basics/03 - BaseLib接口/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
https://github.com/Alchyr/BaseLib-StS2
44

55
> 由于目前`BaseLib`尚处于开发阶段,如果只打patch不添加新内容可以不使用。
6-
> 以下内容使用baselib0.2.1,游戏测试分支。
6+
> 以下内容使用baselib0.2.3,游戏测试分支。
77
88
先依赖baselib才能查看这里里面的文章。
99

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
## VSCode
2+
3+
`csproj`文件里添加这段:(放在`Project`里面即可)
4+
5+
```xml
6+
<!-- 其余内容省略 -->
7+
<Sts2DataDir>$(Sts2Dir)/data_sts2_windows_x86_64</Sts2DataDir>
8+
</PropertyGroup>
9+
10+
<!-- 新增 -->
11+
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
12+
<Optimize>false</Optimize>
13+
<DebugType>portable</DebugType>
14+
</PropertyGroup>
15+
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
16+
<Optimize>true</Optimize>
17+
<DebugType>none</DebugType>
18+
<PathMap>$(AppOutputBase)=.\</PathMap>
19+
</PropertyGroup>
20+
21+
<ItemGroup>
22+
<Reference Include="sts2">
23+
<HintPath>$(Sts2DataDir)/sts2.dll</HintPath>
24+
<Private>false</Private>
25+
</Reference>
26+
<!-- 其余内容省略 -->
27+
```
28+
29+
在项目根目录创建一个`.vscode`文件夹。
30+
31+
* 在其中放一个`launch.json`文件:
32+
33+
```json
34+
{
35+
"version": "0.2.0",
36+
"configurations": [
37+
{
38+
"name": "Run Debug",
39+
"type": "coreclr",
40+
"request": "launch",
41+
"preLaunchTask": "build",
42+
"program": "${config:sts2.installDir}/${config:sts2.gameExeName}",
43+
"cwd": "${config:sts2.installDir}",
44+
"console": "internalConsole",
45+
"stopAtEntry": false
46+
}
47+
]
48+
}
49+
```
50+
51+
* 然后放一个`tasks.json`文件:
52+
53+
```json
54+
{
55+
"version": "2.0.0",
56+
"tasks": [
57+
{
58+
"label": "build",
59+
"type": "process",
60+
"command": "dotnet",
61+
"args": [
62+
"build",
63+
"${workspaceFolder}/${config:sts2.modId}.csproj",
64+
"-c",
65+
"Debug",
66+
"--nologo"
67+
],
68+
"group": "build",
69+
"problemMatcher": "$msCompile"
70+
}
71+
]
72+
}
73+
```
74+
75+
* 然后放一个`settings.json`文件:(路径、名字改成你自己的)
76+
77+
```json
78+
{
79+
"sts2.installDir": "D:/Steam/steamapps/common/Slay the Spire 2",
80+
"sts2.gameExeName": "SlayTheSpire2.exe",
81+
"sts2.modId": "test"
82+
}
83+
```
84+
85+
* 接着打开vscode的设置(`ctrl+,`),查找`Csharp › Experimental › Debug: Hot Reload``[实验性] 在调试时启用 C# 热重载。`)并启用。
86+
87+
* 然后按F5启动就可以。
88+
89+
* 当你修改代码后,点击测试表盘中的火焰图标(🔥)应用热重载。<b>热重载功能有限,不能有增删函数等过大改动。</b>
90+
91+
* 资源PCK不能通过这个方式热重载。
92+
93+
* 如果你进不了游戏提示不通过steam,记得在根目录创建一个`steam_appid.txt`,里面写`2868840`
94+
95+
## Rider
96+
97+
TODO:我没有Rider

0 commit comments

Comments
 (0)