From 02979f65a45ce94f03312855a26a624dae6056a1 Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Thu, 18 May 2023 19:28:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- planner/configexport/example/config.define.go | 40 +++++++++---------- planner/configexport/example/config.go | 18 +++++---- planner/configexport/internal/config.go | 7 ++++ planner/configexport/internal/template.go | 5 +++ 4 files changed, 42 insertions(+), 28 deletions(-) diff --git a/planner/configexport/example/config.define.go b/planner/configexport/example/config.define.go index bad882b..2b5974f 100644 --- a/planner/configexport/example/config.define.go +++ b/planner/configexport/example/config.define.go @@ -1,59 +1,59 @@ // Code generated by minotaur-config-export. DO NOT EDIT. package example - // XXConfig 有索引 -type XXConfig struct { + // IndexConfig 有索引 +type IndexConfig struct { Id int // 任务ID Count string // 次数 - Info *XXConfigInfo // 信息 - Other map[int]*XXConfigOther // 信息2 + Info *IndexConfigInfo // 信息 + Other map[int]*IndexConfigOther // 信息2 } -type XXConfigInfo struct { +type IndexConfigInfo struct { Id int Name string - Info *XXConfigInfoInfo + Info *IndexConfigInfoInfo } -type XXConfigInfoInfo struct { +type IndexConfigInfoInfo struct { Lv int - Exp *XXConfigInfoInfoExp + Exp *IndexConfigInfoInfoExp } -type XXConfigInfoInfoExp struct { +type IndexConfigInfoInfoExp struct { Mux int Count int } -type XXConfigOther struct { +type IndexConfigOther struct { Id int Name string } - // UNConfig 无索引 -type UNConfig struct { + // EasyConfig 无索引 +type EasyConfig struct { Id int // 任务ID Count string // 次数 - Info *UNConfigInfo // 信息 - Other map[int]*UNConfigOther // 信息2 + Info *EasyConfigInfo // 信息 + Other map[int]*EasyConfigOther // 信息2 } -type UNConfigInfo struct { +type EasyConfigInfo struct { Id int Name string - Info *UNConfigInfoInfo + Info *EasyConfigInfoInfo } -type UNConfigInfoInfo struct { +type EasyConfigInfoInfo struct { Lv int - Exp *UNConfigInfoInfoExp + Exp *EasyConfigInfoInfoExp } -type UNConfigInfoInfoExp struct { +type EasyConfigInfoInfoExp struct { Mux int Count int } -type UNConfigOther struct { +type EasyConfigOther struct { Id int Name string } diff --git a/planner/configexport/example/config.go b/planner/configexport/example/config.go index 9d80983..f4713bc 100644 --- a/planner/configexport/example/config.go +++ b/planner/configexport/example/config.go @@ -7,20 +7,22 @@ import ( var json = jsonIter.ConfigCompatibleWithStandardLibrary var ( - GameXXConfig map[int]map[string]*XXConfig - gameXXConfig map[int]map[string]*XXConfig - GameUNConfig *UNConfig - gameUNConfig *UNConfig + GameIndexConfig map[int]map[string]*IndexConfig + gameIndexConfig map[int]map[string]*IndexConfig + GameEasyConfig *EasyConfig + gameEasyConfig *EasyConfig ) func LoadConfig(handle func(filename string, config any) error) { - handle("server.XXConfig.json", &gameXXConfig) - handle("server.UNConfig.json", &gameUNConfig) + gameIndexConfig = make(map[int]map[string]*IndexConfig) + handle("server.IndexConfig.json", &gameIndexConfig) + gameEasyConfig = new(EasyConfig) + handle("server.EasyConfig.json", gameEasyConfig) } func Refresh() { - GameXXConfig = gameXXConfig - GameUNConfig = gameUNConfig + GameIndexConfig = gameIndexConfig + GameEasyConfig = gameEasyConfig } func DefaultLoad(filepath string) { diff --git a/planner/configexport/internal/config.go b/planner/configexport/internal/config.go index 399a01b..ab3e02d 100644 --- a/planner/configexport/internal/config.go +++ b/planner/configexport/internal/config.go @@ -375,3 +375,10 @@ func (slf *Config) GetVariable() string { } return fmt.Sprintf("%s*%s", result, slf.Name) } + +func (slf *Config) GetVariableGen() string { + if slf.IndexCount == 0 { + return fmt.Sprintf("new(%s)", strings.TrimPrefix(slf.GetVariable(), "*")) + } + return fmt.Sprintf("make(%s)", slf.GetVariable()) +} diff --git a/planner/configexport/internal/template.go b/planner/configexport/internal/template.go index cb0c64d..aeaa474 100644 --- a/planner/configexport/internal/template.go +++ b/planner/configexport/internal/template.go @@ -42,8 +42,13 @@ var ( func LoadConfig(handle func(filename string, config any) error) { {{range $index, $config := .Configs}} + game{{$config.Name}} = {{$config.GetVariableGen}} +{{if eq $config.IndexCount 0}} + handle("{{$config.Prefix}}{{$config.Name}}.json", game{{$config.Name}}) +{{else}} handle("{{$config.Prefix}}{{$config.Name}}.json", &game{{$config.Name}}) {{end}} +{{end}} } func Refresh() {