From c9b53b9aedc4fbd0de0182174d9f6d37eb99a440 Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Fri, 19 May 2023 13:19:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E8=A1=A8=E6=A8=A1=E6=9D=BF=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/client.EasyConfig.json | 4 +-- .../example/client.IndexConfig.json | 34 +++++++++---------- planner/configexport/example/config.go | 13 +++++-- .../example/server.IndexConfig.json | 20 +++++------ planner/configexport/internal/template.go | 11 ++++-- 5 files changed, 49 insertions(+), 33 deletions(-) diff --git a/planner/configexport/example/client.EasyConfig.json b/planner/configexport/example/client.EasyConfig.json index 410ffc1..67c853c 100644 --- a/planner/configexport/example/client.EasyConfig.json +++ b/planner/configexport/example/client.EasyConfig.json @@ -7,8 +7,8 @@ }, "Other": { "0": { - "name": "张飞", - "id": 1 + "id": 1, + "name": "张飞" }, "1": { "id": 2, diff --git a/planner/configexport/example/client.IndexConfig.json b/planner/configexport/example/client.IndexConfig.json index 89c64d8..6dbe107 100644 --- a/planner/configexport/example/client.IndexConfig.json +++ b/planner/configexport/example/client.IndexConfig.json @@ -1,42 +1,42 @@ { "1": { "b": { + "Other": { + "1": { + "id": 2, + "name": "刘备" + }, + "0": { + "name": "张飞", + "id": 1 + } + }, "Id": 1, "Count": "b", "Award": { "0": "asd", "1": "12" - }, - "Other": { - "1": { - "id": 2, - "name": "刘备" - }, - "0": { - "id": 1, - "name": "张飞" - } } } }, "2": { "c": { - "Id": 2, - "Count": "c", "Award": { - "0": "asd", - "1": "12" + "1": "12", + "0": "asd" }, "Other": { "0": { - "id": 1, - "name": "张飞" + "name": "张飞", + "id": 1 }, "1": { "id": 2, "name": "刘备" } - } + }, + "Id": 2, + "Count": "c" }, "d": { "Id": 2, diff --git a/planner/configexport/example/config.go b/planner/configexport/example/config.go index f4713bc..d37ca0e 100644 --- a/planner/configexport/example/config.go +++ b/planner/configexport/example/config.go @@ -2,6 +2,8 @@ package example import ( jsonIter "github.com/json-iterator/go" + "github.com/kercylan98/minotaur/utils/log" + "go.uber.org/zap" "os" ) @@ -14,10 +16,17 @@ var ( ) func LoadConfig(handle func(filename string, config any) error) { + var err error gameIndexConfig = make(map[int]map[string]*IndexConfig) - handle("server.IndexConfig.json", &gameIndexConfig) + if err = handle("server.IndexConfig.json", &gameIndexConfig); err != nil { + log.Error("Config", zap.String("Name", "IndexConfig"), zap.Bool("Invalid", true), zap.Error(err)) + } + gameEasyConfig = new(EasyConfig) - handle("server.EasyConfig.json", gameEasyConfig) + if err = handle("server.EasyConfig.json", gameEasyConfig); err != nil { + log.Error("Config", zap.String("Name", "EasyConfig"), zap.Bool("Invalid", true), zap.Error(err)) + } + } func Refresh() { diff --git a/planner/configexport/example/server.IndexConfig.json b/planner/configexport/example/server.IndexConfig.json index f6597b1..16d3cf1 100644 --- a/planner/configexport/example/server.IndexConfig.json +++ b/planner/configexport/example/server.IndexConfig.json @@ -1,10 +1,8 @@ { "1": { "b": { - "Id": 1, "Count": "b", "Info": { - "name": "小明", "info": { "lv": 1, "exp": { @@ -12,7 +10,8 @@ "count": 100 } }, - "id": 1 + "id": 1, + "name": "小明" }, "Other": { "0": { @@ -23,7 +22,8 @@ "id": 2, "name": "刘备" } - } + }, + "Id": 1 } }, "2": { @@ -31,6 +31,7 @@ "Id": 2, "Count": "c", "Info": { + "id": 1, "name": "小明", "info": { "lv": 1, @@ -38,8 +39,7 @@ "mux": 10, "count": 100 } - }, - "id": 1 + } }, "Other": { "0": { @@ -56,15 +56,15 @@ "Id": 2, "Count": "d", "Info": { + "name": "小明", "info": { + "lv": 1, "exp": { "mux": 10, "count": 100 - }, - "lv": 1 + } }, - "id": 1, - "name": "小明" + "id": 1 }, "Other": { "0": { diff --git a/planner/configexport/internal/template.go b/planner/configexport/internal/template.go index aeaa474..d5485af 100644 --- a/planner/configexport/internal/template.go +++ b/planner/configexport/internal/template.go @@ -28,6 +28,8 @@ package {{.Package}} import ( jsonIter "github.com/json-iterator/go" + "github.com/kercylan98/minotaur/utils/log" + "go.uber.org/zap" "os" ) @@ -41,12 +43,17 @@ var ( ) func LoadConfig(handle func(filename string, config any) error) { + var err error {{range $index, $config := .Configs}} game{{$config.Name}} = {{$config.GetVariableGen}} {{if eq $config.IndexCount 0}} - handle("{{$config.Prefix}}{{$config.Name}}.json", game{{$config.Name}}) + if err = handle("{{$config.Prefix}}{{$config.Name}}.json", game{{$config.Name}}); err != nil { + log.Error("Config", zap.String("Name", "{{$config.Name}}"), zap.Bool("Invalid", true), zap.Error(err)) + } {{else}} - handle("{{$config.Prefix}}{{$config.Name}}.json", &game{{$config.Name}}) + if err = handle("{{$config.Prefix}}{{$config.Name}}.json", &game{{$config.Name}}); err != nil { + log.Error("Config", zap.String("Name", "{{$config.Name}}"), zap.Bool("Invalid", true), zap.Error(err)) + } {{end}} {{end}} }