git4subeditor 0.1.20__py3-none-any.whl
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.
- git4subeditor/__init__.py +41 -0
- git4subeditor/__main__.py +6 -0
- git4subeditor/cli.py +683 -0
- git4subeditor/gitformat.py +427 -0
- git4subeditor/l10n.py +107 -0
- git4subeditor/locales/cn.xml +135 -0
- git4subeditor/locales/en.xml +137 -0
- git4subeditor/locales/ru.xml +137 -0
- git4subeditor/repl.py +256 -0
- git4subeditor/subfile.py +189 -0
- git4subeditor/utils.py +122 -0
- git4subeditor/workspace.py +843 -0
- git4subeditor-0.1.20.dist-info/METADATA +227 -0
- git4subeditor-0.1.20.dist-info/RECORD +17 -0
- git4subeditor-0.1.20.dist-info/WHEEL +4 -0
- git4subeditor-0.1.20.dist-info/entry_points.txt +3 -0
- git4subeditor-0.1.20.dist-info/licenses/LICENSE +21 -0
|
@@ -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,17 @@
|
|
|
1
|
+
git4subeditor/__init__.py,sha256=e-HPVIES9lRhcY5ZKZTTqwlalk-hhDc-nllm6JaSjYY,802
|
|
2
|
+
git4subeditor/__main__.py,sha256=50mWt6RKY21_lcORXMZR3ybM8_GgZzlfXELlXG0L9cg,134
|
|
3
|
+
git4subeditor/cli.py,sha256=mkNekFXvDB7yI-p8XZvmt2TFOz6aUCe4bwIrlFNOyr0,21657
|
|
4
|
+
git4subeditor/gitformat.py,sha256=kflvieh291yXZGv4EyQPUcciYDB8mLqDNcrKE0t0YzI,14124
|
|
5
|
+
git4subeditor/l10n.py,sha256=Dh0GZzXrD4N5Jy3oY0fFBvefJcB5ISvgr11tGj0GgV4,3103
|
|
6
|
+
git4subeditor/locales/cn.xml,sha256=Ltm6cSMc9K5tPdjvED2gZopXzQN6yqovJLrPMHiNzRM,8829
|
|
7
|
+
git4subeditor/locales/en.xml,sha256=tV6uS1Xf85mCWKMxpR0WJ4moDcWg74_mmEVhlEVBRo0,9162
|
|
8
|
+
git4subeditor/locales/ru.xml,sha256=hSbpqo3WY6Xz7jhhR_AWaJ2LcDmcCLfm5PoCyvuc-SQ,13348
|
|
9
|
+
git4subeditor/repl.py,sha256=P288cVQteoxqAchxuyLwoTyGxc1eP0eteZ0UsvC6ri0,7852
|
|
10
|
+
git4subeditor/subfile.py,sha256=UD0ATq1hh--S7GFS7KWYmOnkJizITfmM3q2I2xfqE-0,5467
|
|
11
|
+
git4subeditor/utils.py,sha256=5lLJjqqoANQoxzOBwihPMnVOvdfA0GEVXY_y5w9hqOE,4683
|
|
12
|
+
git4subeditor/workspace.py,sha256=JADeb9onhuAz0GtLYN3ZaDvvW4NgY7KpemT9xOdQ4Sc,30365
|
|
13
|
+
git4subeditor-0.1.20.dist-info/licenses/LICENSE,sha256=TUgQviYtxTU6lo0cwLCuPYT3wcvSDyk4d4fsoRRnZug,1062
|
|
14
|
+
git4subeditor-0.1.20.dist-info/WHEEL,sha256=MWx7psoF7KNST9G72pGtiBYuaXRXQXBk9pw5R6FzYko,80
|
|
15
|
+
git4subeditor-0.1.20.dist-info/entry_points.txt,sha256=sRPU4lU95WjZ0HkvwL8bF020Ru4xzBEI1BDH4HITQoY,58
|
|
16
|
+
git4subeditor-0.1.20.dist-info/METADATA,sha256=Mfxsic6QodNWwaLqX-R2z3oAFKaiBykCbvrZvlPNR8w,11312
|
|
17
|
+
git4subeditor-0.1.20.dist-info/RECORD,,
|
|
@@ -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.
|