tabtoy :一款打包工具介绍(备忘)

tabtoy

最近朋友介绍了一款打包工具,初步看了下,挺好的,备忘之

github 地址: https://github.com/davyxu/tabtoy

例子

官网介绍已经很详细了,这里截下图,不用看文字,更好了解

1. execl

例子 execl 参见 : https://github.com/davyxu/tabtoy/blob/master/v2/example/Sample.xlsx

截图如下:

在这里插入图片描述

前 4 行,用于描述字段属性,自己看下也是秒懂的

2. 使用 tabtoy 生成资源和代

类似这样:

tabtoy --mode=v2 --json_out=config.json --combinename=Sample.xlsx
3. Sample.xlsx 会被转化为对应的 config.json

详细参见 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":[ {  } ] }
	]}
4. 同时会生成 golang 结构与解析代码

详细参见 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
}

// 解析代码略
5. 如何使用

详细参见: 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)
	}

}

总结

  1. execl 列属性定义可自动 slice ,很好,比我之前项目中的打表工具,还好一丢丢
  2. 输出是 json 文件,可视化,差错等都很方便
  3. 自动生成的代码,没有傻逼的去炫技(比如,使用反射这种看似高大上的编码)。效率放心;接口也方便直接 map ,无缝 golang 用法
  4. 还没深入使用,初看用下,已经 100 分+

以上

猜你喜欢

转载自blog.csdn.net/u013272009/article/details/104692772