-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
273 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#### 自定义导出 | ||
导出类型为`type:custom`,且导出脚本配置为`template:对应的lua脚本`时,程序将执行对应的lua脚本生成数据: | ||
* 项目示例导出csv脚本为:[csv_export](../template/data-gen.lua) | ||
* 项目示例导出csv对应dts脚本为:[dts_export](../template/dts-gen.lua) | ||
|
||
脚本中可以通过打印json查看所有数据结构: | ||
```lua | ||
print(GXE.json_encode(GXE)) | ||
``` | ||
|
||
lua中可以使用的入口为GXE,一下为数据表简单描述: | ||
```golang | ||
type BuildInfo struct { | ||
Imports []string | ||
Output string | ||
Template string | ||
} | ||
|
||
type commonFileDesc struct { | ||
Version string | ||
GoProtoVersion string | ||
HasMessage bool | ||
} | ||
|
||
// 定义表类型(同类型分组) | ||
type DefineTableInfo struct { | ||
StartID int64 | ||
// 类型(enum/struct) | ||
Category string | ||
// 类型名 | ||
TypeName string | ||
// 表名 | ||
DefinedTable string | ||
// 类型子项 | ||
Items []*DefineTableItem | ||
} | ||
|
||
type StructInfo struct { | ||
// 描述(注释) | ||
Desc string | ||
// 字段名 | ||
FieldName string | ||
// 首字母大写字段名 | ||
TitleFieldName string | ||
// 表中定义的原始类型 | ||
RawValueType string | ||
// 转换后的标准类型 | ||
StandardValueType string | ||
// protobuf类型 | ||
PBValueType string | ||
// 转换后的值类型 | ||
ValueType string | ||
// 二进制编码方式 | ||
EncodeType string | ||
// 基础值是否枚举 | ||
IsEnum bool | ||
// 基础值是否结构 | ||
IsStruct bool | ||
// 基础值是否数组 | ||
IsArray bool | ||
// 编号(1开始) | ||
Index int | ||
// 数组分隔符,默认为全局配置符号 | ||
ArraySplitChar string | ||
// 此字段是否可转换对象 | ||
Convertable bool | ||
// 换换后的类型是否需要缓存 | ||
Cachable bool | ||
IsVoid bool | ||
// 是否消息类型 | ||
IsMessage bool | ||
// 别名(可转换对象显示类型) | ||
Alias string | ||
// 字段限制规则 | ||
Rule int | ||
} | ||
|
||
// 定义表数据项(按行) | ||
type DefineTableItem struct { | ||
StructInfo | ||
// 值 | ||
Value string | ||
} | ||
|
||
// 数据表 | ||
type DataTable struct { | ||
Id int | ||
// 类型名 | ||
TypeName string | ||
// 表头 | ||
Headers []*DataTableHeader | ||
// 表文件名 | ||
DefinedTable string | ||
// 数据 | ||
Data [][]string | ||
// 表类型 | ||
TableType ETableType | ||
// 是否数组 | ||
IsArray bool | ||
// 是否需要增加子项 | ||
NeedAddItems bool | ||
} | ||
|
||
type customFileDesc struct { | ||
commonFileDesc | ||
|
||
Namespace string | ||
Info *BuildInfo | ||
// 单个文件导出时使用 | ||
Table *model.DataTable | ||
|
||
Enums []*model.DefineTableInfo | ||
Consts []*model.DefineTableInfo | ||
Tables []*model.DataTable | ||
} | ||
|
||
// 导出到lua的数据结构GXE | ||
type LuaExportInfo struct { | ||
version string | ||
info *BuildInfo | ||
fileDesc *customFileDesc | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
ValueTypes = { | ||
["int"] = "i", | ||
["int32"] = "i", | ||
["uint"] = "i", | ||
["uint32"] = "i", | ||
["float"] = "f", | ||
["float32"] = "f", | ||
["string"] = "s", | ||
["bool"] = "b", | ||
["int[]"] = "ia", | ||
["uint[]"] = "ia", | ||
["float[]"] = "fa", | ||
["float32[]"] = "fa", | ||
["string[]"] = "sa", | ||
["bool[]"] = "ba", | ||
} | ||
|
||
function genTableDesc(t) | ||
line = t.TypeName | ||
for i,v in pairs(t.Headers) do | ||
structInfo = v.StructInfo | ||
if nil == ValueTypes[structInfo.RawValueType] then | ||
print("Error: " .. structInfo.RawValueType) | ||
goto continue | ||
end | ||
|
||
line = line .. ":" .. structInfo.FieldName .. "-" .. ValueTypes[structInfo.RawValueType] | ||
::continue:: | ||
end | ||
return line .. "\n" | ||
end | ||
|
||
function genTableData(t) | ||
ret = "##########\n" | ||
ret = ret .. t.TypeName .. "\n" | ||
|
||
if t.TypeName == "novice" then | ||
-- print(GXE.json_encode(t.Data)) | ||
end | ||
|
||
for i,v in pairs(t.Data) do | ||
line = "" | ||
idx = 0 | ||
for _,v2 in pairs(v) do | ||
if idx == 0 then | ||
line = string.format("%s", v2) | ||
else | ||
line = line .. "," .. string.format("%s", v2) | ||
end | ||
idx = idx + 1 | ||
end | ||
ret = ret .. line .. "\n" | ||
end | ||
return ret | ||
end | ||
|
||
function generate() | ||
ret = "" | ||
for i,v in pairs(GXE.fileDesc.Tables) do | ||
if not v.IsArray then | ||
ret = ret .. genTableDesc(v) | ||
end | ||
end | ||
|
||
for i,v in pairs(GXE.fileDesc.Tables) do | ||
if not v.IsArray then | ||
ret = ret .. genTableData(v) | ||
end | ||
end | ||
return ret | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
ValueTypes = { | ||
["int"] = "number", | ||
["int32"] = "number", | ||
["uint"] = "number", | ||
["uint32"] = "number", | ||
["float"] = "number", | ||
["float32"] = "number", | ||
["string"] = "string", | ||
["bool"] = "boolean", | ||
["int[]"] = "number[]", | ||
["uint[]"] = "number[]", | ||
["float[]"] = "number[]", | ||
["float32[]"] = "number[]", | ||
["string[]"] = "string[]", | ||
["bool[]"] = "boolean[]", | ||
} | ||
|
||
function genItem(t) | ||
line = " interface " .. t.TypeName .. "Item {\n" | ||
for i,v in pairs(t.Headers) do | ||
structInfo = v.StructInfo | ||
if nil == ValueTypes[structInfo.RawValueType] then | ||
print("Error: " .. structInfo.RawValueType) | ||
goto continue | ||
end | ||
|
||
line = line .. " /** " .. structInfo.Desc .. " */\n" | ||
line = line .. " readonly " .. structInfo.FieldName .. ": " .. ValueTypes[structInfo.RawValueType] .. ";\n" | ||
::continue:: | ||
end | ||
return line .. " }\n\n" | ||
end | ||
|
||
function genTable(t) | ||
line = " let " .. t.TypeName .. ": {[key: number]: " .. t.TypeName .. "Item };\n" | ||
return line | ||
end | ||
|
||
function generate() | ||
ret = "//由工具自动生成的代码,请勿手动修改!\n" | ||
ret = ret .. "declare namespace Configs {\n" | ||
|
||
for i,v in pairs(GXE.fileDesc.Tables) do | ||
if not v.IsArray then | ||
ret = ret .. genItem(v) | ||
end | ||
end | ||
|
||
for i,v in pairs(GXE.fileDesc.Tables) do | ||
if not v.IsArray then | ||
ret = ret .. genTable(v) | ||
end | ||
end | ||
|
||
ret = ret .. "}\n" | ||
return ret | ||
end |