跳转到内容

cli

指定 -datadir 后,cfggen 会读取该目录下可选的 .cfggen-data。这是一个 Properties 文件,无 BOM 时按 UTF-8 读取,有 BOM 时按 BOM 识别 UTF-8、UTF-16 或 UTF-32。把它随配表一起提交,即可在启动命令中省略 -encoding 和 -headrow。

csvEncoding=UTF-8
headRow=2
  • csvEncoding 适用于没有 BOM 的 CSV。优先级为 -encoding → 目录配置 → GBK。
  • headRow 是 CSV 和 Excel 的表头行数,可选 2 或 3。优先级为 -headrow → JVM 属性 configgen.headrow → 目录配置 → 2。
  • 内置 GUI 的编码和表头字段留空时沿用上述规则。
  • 文件里的编码或表头值无效时,cfggen 会报出文件路径和错误值并退出。

在仓库根目录运行 genjar.bat 构建主包,再运行 gentoolsjar.bat。后者使用主包做 -h 启动检查,检查通过后更新 cfggen-tools.jar 和 cfggen-excel-write.jar。运行 fastexcelcheck 或通过 MCP 编辑 Excel 时,三个同版本 JAR 需放在同一目录。

Terminal window
java -jar cfggen-tools.jar -tool "csvencoding,datadir=example/config"
java -jar cfggen-tools.jar -tool "csvencoding,datadir=example/config,to=UTF-8,fix"

csvencoding 递归检查 datadir 下的 CSV,默认为当前目录。带 UTF-8、UTF-16 或 UTF-32 BOM 的文件直接跳过。无 BOM 的文件会列出与工具尝试的源编码相关的 ICU4J 候选和置信分,例如源编码 GBK 对应的 ICU4J 候选 GB18030。加上 fix 才会写回。

目标编码依次取工具参数 to、目录 .cfggen-data 的 csvEncoding、当前 locale 对应的编码,最后回退到 UTF-8。简中使用 GBK,繁中使用 Big5,日文使用 Windows-31J,韩文使用 Windows-949。当前 locale 可用全局 -locale 指定。

工具会严格尝试目标编码、UTF-8、GBK 和 locale 对应的编码。只有这些候选得到唯一文本且目标编码能无损表示时,才会转换。如果结果有歧义,可通过工具参数 source 指定该目录内无 BOM CSV 的原编码,再运行检查确认结果。

修复前会检查整个目录。所有无 BOM 的 CSV 都能按目标编码无损保存时,修复才会写回并更新或创建 .cfggen-data 的 csvEncoding。如果有无法判断或无法转换的文件,本次修复会在写入前停止。

csvEncoding 已经等价时,工具会保留原配置文件。需要更新时,Java Properties 会保留其他属性的值,并以 UTF-8 重新写出文件,原有注释和排版会随之丢弃。

Terminal window
java -jar cfggen-tools.jar -tool "fastexcelcheck,datadir=example/config"

fastexcelcheck 比对 FastExcel 和 POI 在同一数据目录上的读表结果。工具参数 csvencoding 和 headrow 默认分别为 GBK 和 2。运行 java -jar cfggen-tools.jar -h 可查看两个工具的参数。

Terminal window
java -jar cfggen-tools.jar -datadir example/config -gen mcpserver

工具包从同目录加载 cfggen.jar。-gen mcpserver 的 port、watch 和 postrun 参数沿用原有用法。

Terminal window
Usage: java -jar cfggen.jar [options] [-tool toolName[,param=value...]] -datadir <dir> [-gen genName[,param=value...]]
or: java -jar cfggen.jar [-h] (print help)
or: java -jar cfggen.jar -gui (launch GUI)
Parameters can be in any order, but -datadir is required when using generators.
以下tool/gen参数之间由,分割,参数名和参数取值之间由=或:分割
-----language & logging options
-locale locale, default system locale
-v verbose,级别1,输出统计和warning信息
-vv verbose,级别2,输出额外信息
-p profiler,内存和时间监测
-pp profiler,内存监测前加gc
-nowarn 不打印警告信息,默认打印
-weakwarn 打印弱警告,默认不打印
-----tools
-tool xmltocfg 迁移(把之前的.xml改为.cfg)
datadir=.
-tool bytesview
bytes=base.bytes
match=null
-tool term 查看术语,或检查术语使用情况
todo=null
term=null
check ,默认为false
checkall ,默认为false
-tool translate 根据相似语句和相关术语翻译todo文件
source=中文
target=英文
todo=language/_todo_en.xlsx
term=null
ai=ai.json
prompt=null
batch=10
-tool schematocsv
datadir=.
-----schema & data
-datadir 配表根目录,目录下有文件config.cfg
-headrow CSV/Excel 表头行数,可选 2 或 3。覆盖 configgen.headrow 和 .cfggen-data 中的 headRow,内置默认值为 2。
-encoding CSV 编码。覆盖 .cfggen-data 中的 csvEncoding,内置默认值为 GBK。CSV 文件有 BOM 时优先使用 BOM。
-----i18n support
-i18nfile 国际化需要的文件,如果不用国际化,就不要配置
-langswitchdir 国际化并且可随时切换语言
-defaultlang langswitchdir设置时有效,表示默认的语言,默认为zh_cn
-----generators
-gen verify 检验数据
unreferenced ,默认为false
entry ,默认为false
-gen search 搜索数据
own=null
to=null
q=null
int <num> [num]... : Search for integers (supports hex 0x)
str <substring> : Search for strings containing substring
ref <table[key]> [skip] : Search references to a .key
sl [name] : List matching schema names
sll [name] : List matching schemas with data (limit 100)
slljson [name] : List matching schemas in JSON format
h / help : Show this help
q / exit : Quit
-gen i18n 生成翻译文件(方案1:by 文本)
file=../i18n/en.csv 生成文件
-gen i18nbyid 生成翻译文件(方案2:by id)
dir=../i18n/en 目录
backup=../backup 备份目录
checkWrite 测试fastexcel的xlsx文件写入是否正确(用再读取一次,然后比较的方式),默认为false
-gen java 生成java代码
own=null
dir=config 目录
pkg=config 包名
encoding=UTF-8 生成代码文件的编码
noSealed ,默认为false
builders=null 指向txt文件,每行是一个table,对这些table生成对应的builder
configgenDir=null 复制configgen genjava源文件到{configgenDir}/configgen/genjava/,可选
jspecify 生成 JSpecify 注解,在 package-info.java 中声明 @NullMarked,默认关闭
schemaNumPerFile=100 当配表数量过多时生成的ConfigCodeSchema会超过java编译器限制,用此参数来分文
beautifulName 美化由snake_case名派生的标识符:类名/getter转PascalCase(factory_animation_type->FactoryAnimationType),enum常量转SCREAMING_SNAKE_CASE,后缀_Entry/_Detail保留,默认false保持原行为
prefix= 生成类的前缀,默认为空
-gen cs 生成c#代码
own=null
dir=Config 目录
pkg=Config 包名
encoding=UTF-8 生成文件的编码
prefix=D 生成类的前缀
serverText ,默认为false
unity ,默认为false
implicitUsings 项目已启用 .NET 隐式 using 时省略对应指令,默认false
-gen bytes 生成c#/ts/go代码需要的数据
own=null
dir=.
cipher= xor加密
pack=base 主文件为 <pack>.bytes,Mod 应指定独立包名
requires= 多个直接依赖用分号分隔
deps= 按加载顺序给出依赖包路径,多个用分号分隔
langSeparated 额外语言输出 <pack>_<language>.bytes,默认为false
-gen lua 生成lua代码(数据也是代码)
own=null
dir=. 生成代码所在目录
pkg=cfg 模块名称
encoding=UTF-8 编码
emmylua 是否生成EmmyLua相关的注解,默认为false
preload 是否一开始就全部加载配置,默认用到的时候再加载,默认为false
sharedEmptyTable ,默认为false
shared 是否提取非空的公共table,默认为false
packBool ,默认为false
rForOldShared ,默认为false
noStr ,默认为false
mkCfgDir=null
-gen ts 生成typescript代码
own=null
dir=.
pkg=Config
encoding=UTF-8 ts文件编码
serverText ,默认为false
-gen go 生成go代码
own=null
dir=config
pkg=config
serverText ,默认为false
mod=null
-gen gd
own=null
dir=config
prefix=Data
-gen tsschema 生成特定table的schema(用ts来表达)
own=null
table=
dst=. 目标目录
encoding=UTF-8 生成的ts文件编码
-gen json 把特定table里数据输出为json
own=null
tables= 表名,;分割
dst=. JSON 文件输出目录,实际输出路径须在数据目录(-datadir)之外
例如表 a.b 固定输出到 dst 下的 a/_b/ 目录
dst 必须为空,或包含 .cfggen-output 普通标记文件
同一批次内向 dst 生成的文件都会保留,批次成功后清理其余旧文件
-gen server 为cfgeditor编辑器提供server
own=null
port=3456 为cfgeditor.exe提供服务的端口
note=_note.csv 非json记录的标注存储位置
watch=0 x>0表示数据文件修改x秒后自动重载配置
postrun=null xx.bat或xx.sh,用于重载配置后的额外动作, .bat最开始多行的注释可有':: -gen '用当前上下文生成,.sh则是'# -gen '
-gen byai 批量生成单个table的数据
cfg=ai.json 同-gen server里的aiCfg
ask=ask.txt 问题,每行生成一个json
table=skill.buff 表名称
retry=1 重试llm次数,默认1代表不重试
Terminal window
genjar.bat # 生成cfggen.jar
genexceljar.bat # 生成 cfggen-excel-write.jar
gentoolsjar.bat # 生成 cfggen-tools.jar 和 cfggen-excel-write.jar
Terminal window
cd example/java
genjava.bat
run.bat
genjava.bat
@echo off
setlocal
cd /d "%~dp0" || exit /b 1
call "%~dp0..\cfggen_common.bat" || exit /b 1
rem Refresh this example's generated support sources when upgrading the generator.
if exist "configgen\genjava\*.java" del /q "configgen\genjava\*.java"
rem bytes defaults to the versioned blocks format and pack=base.
%CFGGEN% -datadir ../config -gen java,own:-noserver,dir:.,builders:../config/builders.txt,configgendir:.,beautifulName,jspecify -gen bytes,own:-noserver
if errorlevel 1 exit /b %errorlevel%
rem A mod shares the schema and exports only its own records, with the same field filter.
%CFGGEN% -datadir ../config_mod -schema ../config -gen bytes,own:-noserver,pack:demo-mod,requires:base,deps:base.bytes
exit /b %errorlevel%
Terminal window
cd example/lua
genlua.bat
run.bat
genlua.bat
@rem rm -rf common
cd /d "%~dp0" || exit /b 1
call "%~dp0..\cfggen_common.bat" || exit /b 1
%CFGGEN% -datadir ../config -gen lua,dir:.,emmylua,sharedEmptyTable,shared,mkcfgdir:common
Terminal window
cd example/cs
gencs.bat
run.bat
gencs.bat
@echo off
setlocal
cd /d "%~dp0" || exit /b 1
call "%~dp0..\cfggen_common.bat" || exit /b 1
if exist "Config\Loader.cs" del /q "Config\Loader.cs"
rem Build dependencies need a plain package; runtime packages keep the XOR example.
%CFGGEN% -datadir ../config -gen cs,prefix:D,dir:.,encoding:UTF-8,implicitUsings -gen bytes,dir:obj/base-pack -gen bytes,cipher:xyz
if errorlevel 1 exit /b %errorlevel%
%CFGGEN% -datadir ../config_mod -schema ../config -gen bytes,pack:demo-mod,requires:base,deps:obj/base-pack/base.bytes,cipher:xyz
exit /b %errorlevel%
Terminal window
cd example/go
gengo.bat
run.bat
gengo.bat
cd /d "%~dp0" || exit /b 1
call "%~dp0..\cfggen_common.bat" || exit /b 1
for %%f in (stream.go package.go LoadErrors.go) do if exist config\%%f del /q config\%%f
%CFGGEN% -datadir ../config -gen go,dir:. -gen bytes
Terminal window
cd example/ts
gents.bat
run.bat
gents.bat
cd /d "%~dp0" || exit /b 1
call "%~dp0..\cfggen_common.bat" || exit /b 1
if exist "ConfigUtil.ts" del /q "ConfigUtil.ts"
%CFGGEN% -datadir ../config -gen ts -gen bytes