最近朋友介绍了一款打包工具,初步看了下,挺好的,备忘之
github 地址: https://github.com/davyxu/tabtoy
官网介绍已经很详细了,这里截下图,不用看文字,更好了解
例子 execl 参见 : https://github.com/davyxu/tabtoy/blob/master/v2/example/Sample.xlsx
截图如下:
前 4 行,用于描述字段属性,自己看下也是秒懂的
类似这样:
tabtoy --mode=v2 --json_out=config.json --combinename=Sample.xlsx
详细参见 https://github.com/davyxu/tabtoy/blob/master/v2/example/golang/Config.json
类似下列 json
{
"Tool": "github.com/davyxu/tabtoy",
"Version": "2.9.0",
"Sample":[
{ "ID": 100, "Name": "黑猫警长", "NumericalRate": 0.6, "ItemID": 100, "BuffID":[ 10 ], "Pos": { "X": 100, "Y": 89 }, "Type": 0, "SkillID":[ 4, 6, 7 ], "AttackParam": { "Value": 1 }, "SingleStruct": { "HP": 100, "AttackRate": 1.2 }, "StrStruct":[ { "HP": 3, "ExType": 0 }, { "HP": 10, "ExType": 1 } ] },
{ "ID": 101, "Name": "葫芦\n娃", "NumericalRate": 0.8, "ItemID": 100, "BuffID":[ 3, 1 ], "Type": 2, "SkillID":[ 1 ], "SingleStruct": { "HP": 10 }, "StrStruct":[ { } ] },
{ "ID": 102, "Name": "舒\"克\"", "NumericalRate": 0.7, "ItemID": 100, "BuffID":[ ], "Type": 3, "SkillID":[ ], "SingleStruct": { "HP": 10 }, "StrStruct":[ { } ] },
{ "ID": 103, "Name": "贝\n塔", "ItemID": 100, "BuffID":[ ], "Type": 1, "SkillID":[ ], "SingleStruct": { "HP": 10 }, "StrStruct":[ { } ] },
{ "ID": 104, "Name": "邋遢大王", "NumericalRate": 1, "ItemID": 100, "BuffID":[ ], "Type": 2, "SkillID":[ ], "SingleStruct": { "HP": 10 }, "StrStruct":[ { } ] }
]}
详细参见 https://github.com/davyxu/tabtoy/blob/master/v2/example/golang/table/table_gen.go
类似如下:
// Defined in table: Config
type Config struct {
//Sample
Sample []*SampleDefine
}
// Defined in table: Sample
type SampleDefine struct {
//唯一ID
ID int64
//名称
Name string `自定义tag:"支持go的struct tag"`
EmptyName string
//图标ID
IconID int32
//攻击率
NumericalRate float32
//物品id
ItemID int32
//BuffID
BuffID []int32
//位置
Pos *Vec2
//类型
Type ActorType
//技能ID列表
SkillID []int32
//攻击参数
AttackParam *AttackParam
//单结构解析
SingleStruct *Prop
//字符串结构
StrStruct []*Prop
}
// 解析代码略
详细参见: https://github.com/davyxu/tabtoy/blob/master/v2/example/golang/main.go
类似如下:
package main
import (
"fmt"
"github.com/davyxu/tabtoy/v2/example/golang/table"
)
func main() {
config := table.NewConfigTable()
if err := config.Load("Config.json"); err != nil {
panic(err)
}
for index, v := range config.SampleByID {
fmt.Println(index, v)
}
}
以上