Skip to content

Commit

Permalink
支持渠道设置
Browse files Browse the repository at this point in the history
  • Loading branch information
wingcd committed Oct 24, 2023
1 parent 4049fd5 commit 4605605
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 39 deletions.
9 changes: 7 additions & 2 deletions conf.template.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package: "GameData"
pb_bytes_file_ext: ".bytes" #unity must use .bytes extension
channel: "" #导出渠道, 可以根据渠道导出不同的数据
pb_bytes_file_ext: ".bytes" #unity must use .bytes extension, cocoscreator use .bin
comment_symbol: "#"
export_type: 1 #全局导出类型设置,1-ignore,2-client,3-server
export_type: 4 #全局导出类型设置,1-all,2-client,3-server,4-ignore-不支持此行
array_split_char: "," #默认数组分割符号
pause_on_end: false # 运行完毕后是否暂停
strict_mode: false # 是否严格模式,如:int配置为空时,严格模式将会报错,非严格模式默认为0
rules: #数据规则,可在字段类型后加入规则id,在数据导出时进行规则检测,严格模式会中断输出,否则只进行日志提示

sheets:
-
Expand Down
52 changes: 29 additions & 23 deletions conf.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package: "GameData"
channel: "" #导出渠道, 可以根据渠道导出不同的数据
pb_bytes_file_ext: ".bytes" #unity must use .bytes extension, cocoscreator use .bin
comment_symbol: "#"
export_type: 1 #全局导出类型设置,1-all,2-client,3-server,4-ignore-不支持此行
array_split_char: "|" #默认数组分割符号
export_type: 4 #全局导出类型设置,1-all,2-client,3-server,4-ignore-不支持此行
array_split_char: "," #默认数组分割符号
pause_on_end: false # 运行完毕后是否暂停
strict_mode: false # 是否严格模式,如:int配置为空时,严格模式将会报错,非严格模式默认为0
rules: #数据规则,可在字段类型后加入规则id,在数据导出时进行规则检测,严格模式会中断输出,否则只进行日志提示
Expand All @@ -17,11 +18,11 @@ rules: #数据规则,可在字段类型后加入规则id,在数据导出时进
desc: '数字'
disable: false
sheets:
# -
# id: 1
# type: define #type: define/table/language
# file: 'data/define.xlsx'
# sheet: 'define'
-
id: 1
type: define #type: define/table/language
file: 'data/define.xlsx'
sheet: 'define'
# -
# id: 2
# type: define
Expand All @@ -45,19 +46,24 @@ sheets:
# file: 'data/model.xlsx'
# sheet: 'user'
# type_name: 'User'
-
id: 8
type: table
file: 'data/enemy.xlsx'
sheet: 'enemy'
type_name: 'EnemyCfg'
# -
# id: 6
# type: table
# file: 'data/model.xlsx'
# sheet: 'test'
# type_name: 'Test'
# transpose: true
-
id: 6
type: table
file: 'data/i18n.xlsx'
sheet: 'location1'
is_lang: true
# file: 'data/bubble.xlsx'
# sheet: 'bubble'
# type_name: 'Bubble'
# -
# id: 7
# type: table
# file: 'data/i18n.xlsx'
# sheet: 'location1'
# is_lang: true
# -
# id: 7
# type: table
Expand Down Expand Up @@ -92,12 +98,12 @@ exports:
# path: "./gen/code/data_model.pb.go"
# sheets: ""
# package: "game_data"
# -
# id: 3
# type: "csharp"
# path: "./gen/code/DataModel.cs"
# sheets: ""
# package: "Cfg"
-
id: 3
type: "csharp"
path: "./gen/code/DataModel.cs"
sheets: ""
package: "Cfg"
-
id: 4
type: "proto_bytes"
Expand Down
Binary file modified data/define.xlsx
Binary file not shown.
19 changes: 10 additions & 9 deletions doc/arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

```text
-cfg string
设置配置文件 (default "./conf.yaml")
设置配置文件 (default "./conf.yaml")
-cmt string
设置表格注释符号 (default "#")
设置表格注释符号 (default "#")
-exports string
设置需要导出的配置项,默认为空,全部导出, 参考:1,2,5-7
设置需要导出的配置项,默认为空,全部导出, 参考:1,2,5-7
-ext string
设置二进制数据文件后缀(unity必须为.bytes)
-h 获取帮助
设置二进制数据文件后缀(unity必须为.bytes)
-h 获取帮助
-lang
是否生成语言类型到代码(仅测试用,默认为false)
是否生成语言类型到代码(仅测试用,默认为false)
-pkg string
设置导出包名
设置导出包名
-silence
是否静默执行(默认为false)
-v 获取工具当前版本号
是否静默执行(默认为false)
-v 获取工具当前版本号
-channel 设置导出数据的渠道,默认为空
```
6 changes: 5 additions & 1 deletion doc/field_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@

- [自定义类型](#自定义) 如果问号后面带上自定义类型,可在生成Get函数时定义返回类型,减少类型转换,如果有自定义类型,一般会在生成配置中`添加引用`,或者直接修改相关代码生成模板,在`模板中添加引用`

- [规则](#规则) 如果使用规则,需要在最后添加<规则id>,如<1>标明使用id=1的规则对列数据进行检测,且检测一般发生在数据生成时
- [规则](#规则) 如果使用规则,需要在最后添加<规则id>,如<1>标明使用id=1的规则对列数据进行检测,且检测一般发生在数据生成时

### 字段名
- 字段名请遵从代码命名规则,因为此名称将会作为导出代码的结构属性,规则为:`[渠道(可选)]字段名`
- [渠道](#渠道) 字段名中如果包含渠道,如:[IAP]Price,则Price字段将会在打包IAP渠道时,覆盖Price字段的值,导出时只会有一个Price字段
12 changes: 10 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var (
p_comment_symbol string
p_config string
p_silence bool
p_channel string
)

func init() {
Expand All @@ -43,6 +44,7 @@ func init() {

flag.BoolVar(&p_gen_language_code, "lang", false, "是否生成语言类型到代码(仅测试用,默认为false)")
flag.BoolVar(&p_silence, "silence", false, "是否静默执行(默认为false)")
flag.StringVar(&p_channel, "channel", "", "设置渠道名(默认为空)")
}

func main() {
Expand Down Expand Up @@ -247,8 +249,14 @@ func doExport(exportInfo *settings.ExportInfo) {
settings.PackageName = "Deploy"
}

fmt.Printf("执行导出任务,id:%v, 类型:%v, 包含:%v, 排除:%v, 导出路径:%v, 导出类型:%v \n",
exportInfo.ID, exportInfo.Type, exportInfo.Includes, exportInfo.Excludes, exportInfo.Path, []string{"所有", "仅客户端", "仅服务器", "忽略"}[settings.ExportType-1])
settings.Channel = config.Channel
if p_channel != "" {
settings.Channel = p_channel
}
settings.Channel = strings.Trim(settings.Channel, " ")

fmt.Printf("执行导出任务,id:%v, 类型:%v, 包含:%v, 排除:%v, 导出路径:%v, 导出类型:%v, 渠道:%v\n",
exportInfo.ID, exportInfo.Type, exportInfo.Includes, exportInfo.Excludes, exportInfo.Path, []string{"所有", "仅客户端", "仅服务器", "忽略"}[settings.ExportType-1], settings.Channel)

sheetsIds := getIds(exportInfo.Includes)
exceptIds := getIds(exportInfo.Excludes)
Expand Down
1 change: 1 addition & 0 deletions settings/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type RuleInfo struct {

type YamlConf struct {
Package string `yaml:"package"`
Channel string `yaml:"channel"`
PBBytesFileExt string `yaml:"pb_bytes_file_ext"`
CommentSymbol string `yaml:"comment_symbol"`
ExportType int `yaml:"export_type"`
Expand Down
5 changes: 3 additions & 2 deletions settings/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ const (

var (
GO_PROTO_VERTION = "v1.27.1"
TOOL_VERSION = "1.2"
TOOL_VERSION = "1.3"

ExportType = EXPORT_TYPE_ALL
PackageName = "PBGen"
Channel = ""
PbBytesFileExt = ".bytes"
CommentSymbol = "#"
ArraySplitChar = ","
Expand Down Expand Up @@ -160,7 +161,7 @@ func SetTables(tables ...*model.DataTable) {
}

TABLES = CombineTables(TABLES)

sort.Sort(model.DataTables(TABLES))
}

Expand Down
91 changes: 91 additions & 0 deletions xlsx/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"math"
"regexp"
"sort"
"strconv"
"strings"
Expand All @@ -18,6 +19,15 @@ const (
totalSize = 6
)

var (
channelRegex *regexp.Regexp = nil
)

func init() {
// [channel]xxx
channelRegex = regexp.MustCompile(`\[(.+)\](.+)`)
}

func transpose(arr [][]string) [][]string {
cnt1 := len(arr)
if cnt1 == 0 {
Expand Down Expand Up @@ -226,6 +236,36 @@ func DefinesPreProcess(infos map[string]*model.DefineTableInfo) {
item.Index = idx
}
} else if info.Category == model.DEFINE_TYPE_CONST {
var newItems = make([]*model.DefineTableItem, 0)
var channelItems = make([]*model.DefineTableItem, 0)
// 将channel变量值覆盖到同名的变量上
for _, item := range info.Items {
if channelRegex.MatchString(item.FieldName) {
channelItems = append(channelItems, item)
} else {
newItems = append(newItems, item)
}
}

if settings.Channel != "" && len(channelItems) > 0 {
for _, item := range channelItems {
matches := channelRegex.FindStringSubmatch(item.FieldName)
if len(matches) == 3 {
channelValue := matches[1]
filedName := matches[2]
if settings.Channel == channelValue {
for _, item2 := range newItems {
if item2.FieldName == filedName {
item2.Value = item.Value
break
}
}
}
}
}
}
info.Items = newItems

var idx = 0
names := make(map[string]int)
for _, item := range info.Items {
Expand Down Expand Up @@ -524,9 +564,60 @@ func ParseDataSheet(files ...*settings.SheetInfo) (table *model.DataTable) {

table.Data = rows

DataSheetPreProcess(table)
return
}

func DataSheetPreProcess(table *model.DataTable) {
var newHeaders = make([]*model.DataTableHeader, 0)
var channelHeaders = make([]*model.DataTableHeader, 0)
var data = table.Data
// 将channel变量值覆盖到同名的变量上
for _, header := range table.Headers {
if channelRegex.MatchString(header.FieldName) {
channelHeaders = append(channelHeaders, header)
} else {
newHeaders = append(newHeaders, header)
}
}

if len(channelHeaders) > 0 {
var newData = make([][]string, 0)
var deleteIndices = make(map[int]bool, 0)
for _, item := range channelHeaders {
matches := channelRegex.FindStringSubmatch(item.FieldName)
if len(matches) == 3 {
deleteIndices[item.Index-1] = true
channelValue := matches[1]
filedName := matches[2]
if settings.Channel == channelValue {
for _, item2 := range newHeaders {
if item2.FieldName == filedName {
for i, row := range data {
row[item2.Index-1] = row[item.Index-1]
data[i] = row
}
break
}
}
}
}
}

for _, data := range table.Data {
var newRow = make([]string, 0)
for ci, cellValue := range data {
if _, ignore := deleteIndices[ci]; !ignore {
newRow = append(newRow, cellValue)
}
}
newData = append(newData, newRow)
}
table.Data = newData
}
table.Headers = newHeaders
}

func CheckTable(table *model.DataTable) {
for i, row := range table.Data {
for j, col := range row {
Expand Down

0 comments on commit 4605605

Please sign in to comment.