git4subeditor 0.1.20__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yinjie
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,227 @@
1
+ Metadata-Version: 2.4
2
+ Name: git4subeditor
3
+ Version: 0.1.20
4
+ Summary: Convert Barotrauma .sub submarine files into Git-friendly text
5
+ Keywords: barotrauma,submarine,git,modding
6
+ Author: Yinjie
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.13
11
+ Requires-Dist: prompt-toolkit>=3.0
12
+ Requires-Dist: pytest>=8.0 ; extra == 'dev'
13
+ Requires-Dist: ruff>=0.17 ; extra == 'dev'
14
+ Requires-Python: >=3.13
15
+ Project-URL: Homepage, https://github.com/Yinjie1/Git4SubEditor
16
+ Project-URL: Repository, https://github.com/Yinjie1/Git4SubEditor
17
+ Project-URL: Issues, https://github.com/Yinjie1/Git4SubEditor/issues
18
+ Provides-Extra: dev
19
+ Description-Content-Type: text/markdown
20
+
21
+ # Git4SubEditor
22
+ > Git for Submarine Editor
23
+
24
+ 一个 CLI 工具, 把 Barotrauma 的 `.sub` 潜艇文件转换为适合 Git 版本追踪的文本格式, 也支持将其转回 `.sub` 文件.
25
+
26
+ > [!warning]
27
+ > 如果你打算将此程序应用于你正在开发的项目, 请先进行**备份**, 以免发生不可挽回的灾难性事故.
28
+
29
+ > [!note]
30
+ > **后续计划**
31
+ > - [ ] 我希望能集成一个Git GUI到游戏中, 并直接在潜艇编辑器中可视化不同版本潜艇的差异, 但我不熟悉这个游戏的接口, 也不会C#/Lua, 如果有感兴趣的大佬可以试试.
32
+ > - [x] 自动初始化工作区 `git4subeditor init`, 自动添加 `.gitignore` 等
33
+ > - [x] 多语言
34
+ > - [ ] agent skill, 让 ai 根据 `git diff` 拟定提交说明等
35
+ > - [x] 历史记录
36
+ > - [x] Tab 补全
37
+
38
+ ## 为什么需要 Git
39
+ 1. Git 的版本控制, 并不是每个版本都备份一个副本, 而是记录两个版本间的 diff, 这样不仅版本仓库体积非常小, 而且可以很方便地看出每次都做了哪些改动. 又或者哪天搞砸了, 也可以回退到之前的任意版本.
40
+ > 就像 Git 官网里提到的: "Git 能高效地存储仓库历史. 截至 2025 年, 当前版本的 Linux 内核源代码大小为 1.7 GB. Git 仅用 5.5 GB 就存储了 Linux 项目的完整历史 (140 万次提交)."
41
+ 2. 可以上传到远程托管平台, 如 Github, Gitee 等, 这是一种更安全的"云同步", 同时也方便进行多人合作开发.
42
+
43
+ ## 为什么需要这个工具
44
+
45
+ 1. `.sub` 实际上是 gzip 压缩的单个 `xml` 文件. 直接提交 `.sub` 时, Git 只能看到二进制文件发生了变化, 无法审查具体改动.
46
+ 2. 解压后的 `xml` 中, 潜艇预览图是以源码的形式存放在根节点的 `previewimage` 属性里, 往往会让第一行长达几十万字符. 只要改动附近的内容(例如每次改动潜艇, 同一行`checkval`的值都会变化), 就会产生巨大的单行 diff.
47
+ > `checkval` 是潜艇保存时写入的随机整数, 用于多人战役校验潜艇文件; 本工具不会修改它, 因此每次在游戏中保存后, 根节点仍会出现一行 `checkval` 变化.
48
+ 1. 此外在 `xml` 中, 由于游戏内部把一些属性当作无序集合保存, 而每次保存潜艇, 这些值的顺序都可能变化, 导致大量无意义 diff.
49
+
50
+
51
+ ## 该程序做了什么
52
+ 将潜艇 `.sub` 文件解压并转成 Git 友好的 `xml` 文件, 也支持将 `xml` 打包成 `.sub`
53
+ 1. 将预览图单独导出, 并相对链接引用预览图, 以防每次改动潜艇都要巨大的单行 diff.
54
+ 2. 自动按字母顺序排序下列属性的值, 以防每次保存潜艇顺序改变导致大量无意义 diff
55
+ - Tags
56
+ - requireditem 的 items
57
+ - excludedidentifiers
58
+ - DisallowedUpgrades
59
+ - DisallowAttachingOverTags
60
+ - ContainableRestrictions
61
+ - idcardtags
62
+ - outposttags
63
+
64
+ ---
65
+
66
+ ## 安装教程 (Windows)
67
+ > [!tip]
68
+ > 要是实在不会, 就把该文档发给 ai, 让 ai 帮忙装.
69
+
70
+ ### 1. 安装 Git for Windows
71
+ 直接到 Git [官网](https://git-scm.com/install/windows)上下载
72
+ ### 2. 安装 Python 环境(可选)
73
+ 安装包管理工具 [uv](https://docs.astral.sh/uv/), 打开 CMD/PowerShell:
74
+ ```bash
75
+ winget install uv
76
+ # 检查是否安装成功
77
+ uv --version
78
+ ```
79
+ uv 默认把解释器/包/工具都装在C盘, 如果想改安装目录, 可以改环境变量`UV_CACHE_DIR`, `UV_PYTHON_INSTALL_DIR`, `UV_TOOL_BIN_DIR`, `UV_TOOL_DIR`, 运行以下命令检查是否修改成功:
80
+ ```bash
81
+ uv python dir
82
+ uv cache dir
83
+ uv tool dir
84
+ ```
85
+ 运行以下命令并重启终端, 来把`UV_TOOL_BIN_DIR`添加到PATH:
86
+ ```bash
87
+ uv tool update-shell
88
+ ```
89
+ 安装一个 Python 解释器:
90
+ ```bash
91
+ # 最后一个是版本, 版本不要太低
92
+ uv python install 3.15
93
+ ```
94
+ ### 3. 安装 Git4SubEditor
95
+ 从 GitHub 安装到 uv 的独立工具环境, 不会污染 Python 全局环境:
96
+
97
+ ```bash
98
+ uv tool install "git4subeditor @ git+https://github.com/Yinjie1/Git4SubEditor.git"
99
+ # 检查是否安装成功
100
+ uv tool list
101
+ git4subeditor --version
102
+ ```
103
+
104
+ ---
105
+
106
+ ## 快速开始
107
+ 你的潜艇Mod目录位于`Barotrauma\LocalMods\`中, 可以在游戏内的模组选择界面, 点击你的潜艇Mod右侧的"笔"图标快速打开.
108
+ 运行这个工具需在当前Mod目录或子目录下打开终端(右键目录背景->在终端中打开), 反正必须确保终端的工作目录是在你要修改的Mod的目录.
109
+ ### 1. 初始化工作目录
110
+ Mod目录中需要有一个 Git 仓库, 如果没有, 可以运行以下命令初始化仓库:
111
+ ```bash
112
+ git init
113
+ ```
114
+ 接着运行以下命令, 初始化 git4subeditor 项目:
115
+ ```bash
116
+ git4subeditor init
117
+ ```
118
+ 此过程会自动生成/修改 `.gitignore` 文件, 确保 Git 忽略追踪 `*.sub`, `*.bak`, `*.png`, `history` 这4种文件, 你也可以手动添加你要忽略的文件.
119
+ 还会生成一个项目配置文件 `git4subeditor.xml`, 里面储存了用户偏好及已注册潜艇信息:
120
+ ```xml
121
+ <?xml version='1.0' encoding='utf-8'?>
122
+ <git4subeditor>
123
+ <projectName>test</projectName>
124
+ <language>cn</language>
125
+ <gitRepo>../..</gitRepo>
126
+ <modRoot>../..</modRoot>
127
+ <version>0.1.19</version>
128
+ <submarines>
129
+ <submarine name="自定义名称" path="../../test/Git test.sub" preview="../../test/Git test.png" hash="..." />
130
+ <submarine path="../Git test2.sub" preview="../Git test2.png" hash="..." />
131
+ <submarine path="Git test3.sub" preview="Git test3.png" hash="..." />
132
+ <submarine path="tttt/Git test3.sub" preview="tttt/Git test4.png" hash="..." />
133
+ </submarines>
134
+ </git4subeditor>
135
+ ```
136
+ ### 2. 交互模式
137
+ 该程序提供 CLI 模式和交互模式, 前者适合 ai 使用, 后者提供了人类可读的界面, 并且交互逻辑更加简单, 还提供了命令补全和历史记录功能, 运行以下命令启动交互模式:
138
+ ```bash
139
+ git4subeditor
140
+ ```
141
+ 你将会看到如以下的界面
142
+ ```
143
+ ██████╗ ██╗████████╗ ██╗ ██╗ by Yinjie
144
+ ██╔════╝ ██║╚══██╔══╝ ██║ ██║ 0.1.19
145
+ ██║ ███╗██║ ██║ ███████║
146
+ ██║ ██║██║ ██║ ╚════██║
147
+ ╚██████╔╝██║ ██║ ██║
148
+ ╚═════╝ ╚═╝ ╚═╝ ╚═╝
149
+
150
+ ███████╗██╗ ██╗██████╗ ███████╗██████╗ ██╗████████╗ ██████╗ ██████╗
151
+ ██╔════╝██║ ██║██╔══██╗██╔════╝██╔══██╗██║╚══██╔══╝██╔═══██╗██╔══██╗
152
+ ███████╗██║ ██║██████╔╝█████╗ ██║ ██║██║ ██║ ██║ ██║██████╔╝
153
+ ╚════██║██║ ██║██╔══██╗██╔══╝ ██║ ██║██║ ██║ ██║ ██║██╔══██╗
154
+ ███████║╚██████╔╝██████╔╝███████╗██████╔╝██║ ██║ ╚██████╔╝██║ ██║
155
+ ╚══════╝ ╚═════╝ ╚═════╝ ╚══════╝╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝
156
+
157
+ 项目: test | Git 仓库: ../.. | 模组根目录: ../..
158
+ CWD: path_to/current_work_directory
159
+ ../..
160
+ ├── ../../test
161
+ │ └── 自定义名称: Git test.sub
162
+ └── ..
163
+ ├── Git test2: Git test2.sub (M)
164
+ └── .
165
+ ├── Git test3: Git test3.sub
166
+ └── tttt
167
+ └── Git test4: Git test4.sub (U)
168
+
169
+ 命令:
170
+ init 初始化/更新工作区
171
+ tree 递归搜索并显示仓库下所有潜艇
172
+ export <file.sub> [-o DIR] 解压 .sub 并转为 Git 友好的 XML
173
+ pack <file.xml> [-o FILE] 打包 XML 为 .sub
174
+ unpack <file.sub> [-o DIR] 仅解压 .sub 为原始 XML
175
+ q 退出交互模式
176
+
177
+ Tab 补全 · ↑↓ 历史 · Ctrl-R 搜索 · Ctrl-D 退出 · ? 帮助
178
+ g4s:test>
179
+ ```
180
+ 其中的潜艇 `.sub` 文件目录树, 是以 **Git 仓库**所在目录为根目录递归搜索得到的, 目录以相对路径显示. 示例中的目录结构是为了展示刻意制造的, 不建议搞这么复杂.
181
+ 其中未注册潜艇带有红色标识 `(U)`. 已注册潜艇在初始化或 `export` 时, 会自动计算并记录哈希值到 `git4subeditor.xml` 中, 生成目录树时会再次计算哈希, 若潜艇发生改动, 哈希会发生改变, 发生改动的潜艇带有黄色标识 `(M)`.
182
+ ### 3. sub 转 XML
183
+ 若你的潜艇文件为`test.sub`, 执行命令:
184
+ ```bash
185
+ # 交互模式
186
+ export "test.sub"
187
+ # CLI 模式
188
+ git4subeditor export "test.sub"
189
+ ```
190
+ 将会得到2个文件: `test.xml`, `test.png`. 其中`test.xml`就是 Git 要追踪的文件.
191
+ 如果已经进行项目初始化(即当前目录有 `git4subeditor.xml`), 可通过以下命令自动导出所有发生改动的已注册 `.sub` 文件:
192
+ ```bash
193
+ # 交互模式
194
+ export
195
+ # CLI 模式
196
+ git4subeditor export
197
+ ```
198
+
199
+ ### 4. 用 Git 管理 XML
200
+ > [!tip]
201
+ > 要是实在不会, 就让 ai 帮忙弄, ai 很擅长使用 CLI. 像提交, 回退版本, 比较两个版本的差异, 写提交说明, 都可以问 ai.
202
+
203
+ 该程序不集成操作 Git 仓库的功能, 因为已经有很多成熟的 Git GUI 工具, 重写一遍不仅工作量大, 而且可能还更难用, bug更多, 把仓库搞坏就麻烦了.
204
+ 对于不熟悉命令行的小白, 可以安装一些集成了 Git GUI 的 IDE, 用以**可视化差异**与**提交**修改. 我建议用 [VSCode](https://code.visualstudio.com/Download) (选System Installer), Git for Windows 也自带了一个 GUI, 但没那么好用.
205
+ 关于 Git 的使用, 可以看这个快速入门[教程](https://chriswenchen.github.io/theory-computing-physics-guide/docs/git), 最常用的就几个 CLI 命令:
206
+ ```bash
207
+ # 初始化版本库
208
+ git init
209
+ # 查看未提交改动(按q退出)
210
+ git diff HEAD
211
+ # 暂存所有改动
212
+ git add .
213
+ # 查看状态
214
+ git status
215
+ # 提交暂存区的内容到版本库
216
+ git commit -m "这里写提交说明"
217
+ ```
218
+
219
+ ### 5. XML 转 sub
220
+ 如果要回退版本, 用 Git 把 `xml` 回退到指定的版本, 再用以下命令转成 `.sub`文件:
221
+ ```bash
222
+ # 交互模式
223
+ pack "test.xml"
224
+ # CLI 模式
225
+ git4subeditor pack "test.xml"
226
+ ```
227
+ 如果 `test.sub` 已存在, 会先备份为: `test.sub.bak` (给你一个后悔的机会), 然后覆盖写入新的 `test.sub`.
@@ -0,0 +1,207 @@
1
+ # Git4SubEditor
2
+ > Git for Submarine Editor
3
+
4
+ 一个 CLI 工具, 把 Barotrauma 的 `.sub` 潜艇文件转换为适合 Git 版本追踪的文本格式, 也支持将其转回 `.sub` 文件.
5
+
6
+ > [!warning]
7
+ > 如果你打算将此程序应用于你正在开发的项目, 请先进行**备份**, 以免发生不可挽回的灾难性事故.
8
+
9
+ > [!note]
10
+ > **后续计划**
11
+ > - [ ] 我希望能集成一个Git GUI到游戏中, 并直接在潜艇编辑器中可视化不同版本潜艇的差异, 但我不熟悉这个游戏的接口, 也不会C#/Lua, 如果有感兴趣的大佬可以试试.
12
+ > - [x] 自动初始化工作区 `git4subeditor init`, 自动添加 `.gitignore` 等
13
+ > - [x] 多语言
14
+ > - [ ] agent skill, 让 ai 根据 `git diff` 拟定提交说明等
15
+ > - [x] 历史记录
16
+ > - [x] Tab 补全
17
+
18
+ ## 为什么需要 Git
19
+ 1. Git 的版本控制, 并不是每个版本都备份一个副本, 而是记录两个版本间的 diff, 这样不仅版本仓库体积非常小, 而且可以很方便地看出每次都做了哪些改动. 又或者哪天搞砸了, 也可以回退到之前的任意版本.
20
+ > 就像 Git 官网里提到的: "Git 能高效地存储仓库历史. 截至 2025 年, 当前版本的 Linux 内核源代码大小为 1.7 GB. Git 仅用 5.5 GB 就存储了 Linux 项目的完整历史 (140 万次提交)."
21
+ 2. 可以上传到远程托管平台, 如 Github, Gitee 等, 这是一种更安全的"云同步", 同时也方便进行多人合作开发.
22
+
23
+ ## 为什么需要这个工具
24
+
25
+ 1. `.sub` 实际上是 gzip 压缩的单个 `xml` 文件. 直接提交 `.sub` 时, Git 只能看到二进制文件发生了变化, 无法审查具体改动.
26
+ 2. 解压后的 `xml` 中, 潜艇预览图是以源码的形式存放在根节点的 `previewimage` 属性里, 往往会让第一行长达几十万字符. 只要改动附近的内容(例如每次改动潜艇, 同一行`checkval`的值都会变化), 就会产生巨大的单行 diff.
27
+ > `checkval` 是潜艇保存时写入的随机整数, 用于多人战役校验潜艇文件; 本工具不会修改它, 因此每次在游戏中保存后, 根节点仍会出现一行 `checkval` 变化.
28
+ 1. 此外在 `xml` 中, 由于游戏内部把一些属性当作无序集合保存, 而每次保存潜艇, 这些值的顺序都可能变化, 导致大量无意义 diff.
29
+
30
+
31
+ ## 该程序做了什么
32
+ 将潜艇 `.sub` 文件解压并转成 Git 友好的 `xml` 文件, 也支持将 `xml` 打包成 `.sub`
33
+ 1. 将预览图单独导出, 并相对链接引用预览图, 以防每次改动潜艇都要巨大的单行 diff.
34
+ 2. 自动按字母顺序排序下列属性的值, 以防每次保存潜艇顺序改变导致大量无意义 diff
35
+ - Tags
36
+ - requireditem 的 items
37
+ - excludedidentifiers
38
+ - DisallowedUpgrades
39
+ - DisallowAttachingOverTags
40
+ - ContainableRestrictions
41
+ - idcardtags
42
+ - outposttags
43
+
44
+ ---
45
+
46
+ ## 安装教程 (Windows)
47
+ > [!tip]
48
+ > 要是实在不会, 就把该文档发给 ai, 让 ai 帮忙装.
49
+
50
+ ### 1. 安装 Git for Windows
51
+ 直接到 Git [官网](https://git-scm.com/install/windows)上下载
52
+ ### 2. 安装 Python 环境(可选)
53
+ 安装包管理工具 [uv](https://docs.astral.sh/uv/), 打开 CMD/PowerShell:
54
+ ```bash
55
+ winget install uv
56
+ # 检查是否安装成功
57
+ uv --version
58
+ ```
59
+ uv 默认把解释器/包/工具都装在C盘, 如果想改安装目录, 可以改环境变量`UV_CACHE_DIR`, `UV_PYTHON_INSTALL_DIR`, `UV_TOOL_BIN_DIR`, `UV_TOOL_DIR`, 运行以下命令检查是否修改成功:
60
+ ```bash
61
+ uv python dir
62
+ uv cache dir
63
+ uv tool dir
64
+ ```
65
+ 运行以下命令并重启终端, 来把`UV_TOOL_BIN_DIR`添加到PATH:
66
+ ```bash
67
+ uv tool update-shell
68
+ ```
69
+ 安装一个 Python 解释器:
70
+ ```bash
71
+ # 最后一个是版本, 版本不要太低
72
+ uv python install 3.15
73
+ ```
74
+ ### 3. 安装 Git4SubEditor
75
+ 从 GitHub 安装到 uv 的独立工具环境, 不会污染 Python 全局环境:
76
+
77
+ ```bash
78
+ uv tool install "git4subeditor @ git+https://github.com/Yinjie1/Git4SubEditor.git"
79
+ # 检查是否安装成功
80
+ uv tool list
81
+ git4subeditor --version
82
+ ```
83
+
84
+ ---
85
+
86
+ ## 快速开始
87
+ 你的潜艇Mod目录位于`Barotrauma\LocalMods\`中, 可以在游戏内的模组选择界面, 点击你的潜艇Mod右侧的"笔"图标快速打开.
88
+ 运行这个工具需在当前Mod目录或子目录下打开终端(右键目录背景->在终端中打开), 反正必须确保终端的工作目录是在你要修改的Mod的目录.
89
+ ### 1. 初始化工作目录
90
+ Mod目录中需要有一个 Git 仓库, 如果没有, 可以运行以下命令初始化仓库:
91
+ ```bash
92
+ git init
93
+ ```
94
+ 接着运行以下命令, 初始化 git4subeditor 项目:
95
+ ```bash
96
+ git4subeditor init
97
+ ```
98
+ 此过程会自动生成/修改 `.gitignore` 文件, 确保 Git 忽略追踪 `*.sub`, `*.bak`, `*.png`, `history` 这4种文件, 你也可以手动添加你要忽略的文件.
99
+ 还会生成一个项目配置文件 `git4subeditor.xml`, 里面储存了用户偏好及已注册潜艇信息:
100
+ ```xml
101
+ <?xml version='1.0' encoding='utf-8'?>
102
+ <git4subeditor>
103
+ <projectName>test</projectName>
104
+ <language>cn</language>
105
+ <gitRepo>../..</gitRepo>
106
+ <modRoot>../..</modRoot>
107
+ <version>0.1.19</version>
108
+ <submarines>
109
+ <submarine name="自定义名称" path="../../test/Git test.sub" preview="../../test/Git test.png" hash="..." />
110
+ <submarine path="../Git test2.sub" preview="../Git test2.png" hash="..." />
111
+ <submarine path="Git test3.sub" preview="Git test3.png" hash="..." />
112
+ <submarine path="tttt/Git test3.sub" preview="tttt/Git test4.png" hash="..." />
113
+ </submarines>
114
+ </git4subeditor>
115
+ ```
116
+ ### 2. 交互模式
117
+ 该程序提供 CLI 模式和交互模式, 前者适合 ai 使用, 后者提供了人类可读的界面, 并且交互逻辑更加简单, 还提供了命令补全和历史记录功能, 运行以下命令启动交互模式:
118
+ ```bash
119
+ git4subeditor
120
+ ```
121
+ 你将会看到如以下的界面
122
+ ```
123
+ ██████╗ ██╗████████╗ ██╗ ██╗ by Yinjie
124
+ ██╔════╝ ██║╚══██╔══╝ ██║ ██║ 0.1.19
125
+ ██║ ███╗██║ ██║ ███████║
126
+ ██║ ██║██║ ██║ ╚════██║
127
+ ╚██████╔╝██║ ██║ ██║
128
+ ╚═════╝ ╚═╝ ╚═╝ ╚═╝
129
+
130
+ ███████╗██╗ ██╗██████╗ ███████╗██████╗ ██╗████████╗ ██████╗ ██████╗
131
+ ██╔════╝██║ ██║██╔══██╗██╔════╝██╔══██╗██║╚══██╔══╝██╔═══██╗██╔══██╗
132
+ ███████╗██║ ██║██████╔╝█████╗ ██║ ██║██║ ██║ ██║ ██║██████╔╝
133
+ ╚════██║██║ ██║██╔══██╗██╔══╝ ██║ ██║██║ ██║ ██║ ██║██╔══██╗
134
+ ███████║╚██████╔╝██████╔╝███████╗██████╔╝██║ ██║ ╚██████╔╝██║ ██║
135
+ ╚══════╝ ╚═════╝ ╚═════╝ ╚══════╝╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝
136
+
137
+ 项目: test | Git 仓库: ../.. | 模组根目录: ../..
138
+ CWD: path_to/current_work_directory
139
+ ../..
140
+ ├── ../../test
141
+ │ └── 自定义名称: Git test.sub
142
+ └── ..
143
+ ├── Git test2: Git test2.sub (M)
144
+ └── .
145
+ ├── Git test3: Git test3.sub
146
+ └── tttt
147
+ └── Git test4: Git test4.sub (U)
148
+
149
+ 命令:
150
+ init 初始化/更新工作区
151
+ tree 递归搜索并显示仓库下所有潜艇
152
+ export <file.sub> [-o DIR] 解压 .sub 并转为 Git 友好的 XML
153
+ pack <file.xml> [-o FILE] 打包 XML 为 .sub
154
+ unpack <file.sub> [-o DIR] 仅解压 .sub 为原始 XML
155
+ q 退出交互模式
156
+
157
+ Tab 补全 · ↑↓ 历史 · Ctrl-R 搜索 · Ctrl-D 退出 · ? 帮助
158
+ g4s:test>
159
+ ```
160
+ 其中的潜艇 `.sub` 文件目录树, 是以 **Git 仓库**所在目录为根目录递归搜索得到的, 目录以相对路径显示. 示例中的目录结构是为了展示刻意制造的, 不建议搞这么复杂.
161
+ 其中未注册潜艇带有红色标识 `(U)`. 已注册潜艇在初始化或 `export` 时, 会自动计算并记录哈希值到 `git4subeditor.xml` 中, 生成目录树时会再次计算哈希, 若潜艇发生改动, 哈希会发生改变, 发生改动的潜艇带有黄色标识 `(M)`.
162
+ ### 3. sub 转 XML
163
+ 若你的潜艇文件为`test.sub`, 执行命令:
164
+ ```bash
165
+ # 交互模式
166
+ export "test.sub"
167
+ # CLI 模式
168
+ git4subeditor export "test.sub"
169
+ ```
170
+ 将会得到2个文件: `test.xml`, `test.png`. 其中`test.xml`就是 Git 要追踪的文件.
171
+ 如果已经进行项目初始化(即当前目录有 `git4subeditor.xml`), 可通过以下命令自动导出所有发生改动的已注册 `.sub` 文件:
172
+ ```bash
173
+ # 交互模式
174
+ export
175
+ # CLI 模式
176
+ git4subeditor export
177
+ ```
178
+
179
+ ### 4. 用 Git 管理 XML
180
+ > [!tip]
181
+ > 要是实在不会, 就让 ai 帮忙弄, ai 很擅长使用 CLI. 像提交, 回退版本, 比较两个版本的差异, 写提交说明, 都可以问 ai.
182
+
183
+ 该程序不集成操作 Git 仓库的功能, 因为已经有很多成熟的 Git GUI 工具, 重写一遍不仅工作量大, 而且可能还更难用, bug更多, 把仓库搞坏就麻烦了.
184
+ 对于不熟悉命令行的小白, 可以安装一些集成了 Git GUI 的 IDE, 用以**可视化差异**与**提交**修改. 我建议用 [VSCode](https://code.visualstudio.com/Download) (选System Installer), Git for Windows 也自带了一个 GUI, 但没那么好用.
185
+ 关于 Git 的使用, 可以看这个快速入门[教程](https://chriswenchen.github.io/theory-computing-physics-guide/docs/git), 最常用的就几个 CLI 命令:
186
+ ```bash
187
+ # 初始化版本库
188
+ git init
189
+ # 查看未提交改动(按q退出)
190
+ git diff HEAD
191
+ # 暂存所有改动
192
+ git add .
193
+ # 查看状态
194
+ git status
195
+ # 提交暂存区的内容到版本库
196
+ git commit -m "这里写提交说明"
197
+ ```
198
+
199
+ ### 5. XML 转 sub
200
+ 如果要回退版本, 用 Git 把 `xml` 回退到指定的版本, 再用以下命令转成 `.sub`文件:
201
+ ```bash
202
+ # 交互模式
203
+ pack "test.xml"
204
+ # CLI 模式
205
+ git4subeditor pack "test.xml"
206
+ ```
207
+ 如果 `test.sub` 已存在, 会先备份为: `test.sub.bak` (给你一个后悔的机会), 然后覆盖写入新的 `test.sub`.
@@ -0,0 +1,56 @@
1
+ [build-system]
2
+ requires = ["uv_build>=0.13.7,<0.14"]
3
+ build-backend = "uv_build"
4
+
5
+ [project]
6
+ name = "git4subeditor"
7
+ version = "0.1.20"
8
+ description = "Convert Barotrauma .sub submarine files into Git-friendly text"
9
+ readme = "README.md"
10
+ requires-python = ">=3.13"
11
+ dependencies = ["prompt_toolkit>=3.0"]
12
+ keywords = [
13
+ "barotrauma",
14
+ "submarine",
15
+ "git",
16
+ "modding",
17
+ ]
18
+ classifiers = [
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.13",
21
+ ]
22
+ license = "MIT"
23
+ license-files = ["LICENSE"]
24
+
25
+ [[project.authors]]
26
+ name = "Yinjie"
27
+
28
+ [project.scripts]
29
+ git4subeditor = "git4subeditor.cli:main"
30
+
31
+ [project.urls]
32
+ Homepage = "https://github.com/Yinjie1/Git4SubEditor"
33
+ Repository = "https://github.com/Yinjie1/Git4SubEditor"
34
+ Issues = "https://github.com/Yinjie1/Git4SubEditor/issues"
35
+
36
+ [project.optional-dependencies]
37
+ dev = [
38
+ "pytest>=8.0",
39
+ "ruff>=0.17",
40
+ ]
41
+
42
+ [tool.pytest.ini_options]
43
+ testpaths = ["tests"]
44
+
45
+ [tool.ruff]
46
+ target-version = "py313"
47
+ line-length = 88
48
+
49
+ [tool.ruff.lint]
50
+ select = [
51
+ "B",
52
+ "E",
53
+ "F",
54
+ "I",
55
+ "UP",
56
+ ]
@@ -0,0 +1,43 @@
1
+ [build-system]
2
+ requires = ["uv_build>=0.13.7,<0.14"]
3
+ build-backend = "uv_build"
4
+
5
+ [project]
6
+ name = "git4subeditor"
7
+ version = "0.1.20"
8
+ description = "Convert Barotrauma .sub submarine files into Git-friendly text"
9
+ readme = "README.md"
10
+ requires-python = ">=3.13"
11
+ dependencies = ["prompt_toolkit>=3.0"]
12
+ keywords = ["barotrauma", "submarine", "git", "modding"]
13
+ classifiers = [
14
+ "Programming Language :: Python :: 3",
15
+ "Programming Language :: Python :: 3.13",
16
+ ]
17
+ authors = [{ name = "Yinjie" }]
18
+ license = "MIT"
19
+ license-files = ["LICENSE"]
20
+
21
+ [project.scripts]
22
+ git4subeditor = "git4subeditor.cli:main"
23
+
24
+ [project.urls]
25
+ Homepage = "https://github.com/Yinjie1/Git4SubEditor"
26
+ Repository = "https://github.com/Yinjie1/Git4SubEditor"
27
+ Issues = "https://github.com/Yinjie1/Git4SubEditor/issues"
28
+
29
+ [project.optional-dependencies]
30
+ dev = [
31
+ "pytest>=8.0",
32
+ "ruff>=0.17",
33
+ ]
34
+
35
+ [tool.pytest.ini_options]
36
+ testpaths = ["tests"]
37
+
38
+ [tool.ruff]
39
+ target-version = "py313"
40
+ line-length = 88
41
+
42
+ [tool.ruff.lint]
43
+ select = ["B", "E", "F", "I", "UP"]
@@ -0,0 +1,41 @@
1
+ """Utilities for version-controlling Barotrauma submarine files."""
2
+
3
+ from git4subeditor.gitformat import (
4
+ PREVIEW_ATTRIBUTE,
5
+ PREVIEW_LINK_ATTRIBUTE,
6
+ ExportResult,
7
+ embed_preview_image,
8
+ export_sub,
9
+ extract_preview_image,
10
+ pack_sub,
11
+ parse_xml,
12
+ serialize_xml,
13
+ )
14
+ from git4subeditor.subfile import (
15
+ SubFileError,
16
+ decode_xml,
17
+ decompress_sub,
18
+ read_sub_bytes,
19
+ unpack_sub,
20
+ validate_xml,
21
+ )
22
+
23
+ __all__ = [
24
+ "PREVIEW_ATTRIBUTE",
25
+ "PREVIEW_LINK_ATTRIBUTE",
26
+ "ExportResult",
27
+ "SubFileError",
28
+ "decode_xml",
29
+ "decompress_sub",
30
+ "embed_preview_image",
31
+ "export_sub",
32
+ "extract_preview_image",
33
+ "pack_sub",
34
+ "parse_xml",
35
+ "read_sub_bytes",
36
+ "serialize_xml",
37
+ "unpack_sub",
38
+ "validate_xml",
39
+ ]
40
+
41
+ __version__ = "0.1.20"
@@ -0,0 +1,6 @@
1
+ """Run the git4subeditor application."""
2
+
3
+ from git4subeditor.cli import main
4
+
5
+ if __name__ == "__main__":
6
+ raise SystemExit(main())