From 2372d262bded520ee4267c9a49cf63883fbb7619 Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Thu, 18 May 2023 19:17:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E8=A1=A8=E5=B7=A5=E5=85=B7=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- planner/configexport/configexport.go | 13 ++- planner/configexport/configexport_test.go | 2 +- .../configexport/example/client.UNConfig.json | 4 +- .../configexport/example/client.XXConfig.json | 30 +---- planner/configexport/example/config.go | 4 +- .../configexport/example/server.XXConfig.json | 63 ++++------- planner/configexport/internal/config.go | 107 +++++++++++------- planner/configexport/internal/template.go | 2 +- planner/configexport/template.xlsx | Bin 10614 -> 10773 bytes 9 files changed, 111 insertions(+), 114 deletions(-) diff --git a/planner/configexport/configexport.go b/planner/configexport/configexport.go index aa28c4d..685ad9e 100644 --- a/planner/configexport/configexport.go +++ b/planner/configexport/configexport.go @@ -36,6 +36,9 @@ type ConfigExport struct { func (slf *ConfigExport) ExportClient(prefix, outputDir string) { for _, config := range slf.configs { config := config + if len(prefix) > 0 { + config.Prefix = fmt.Sprintf("%s.", prefix) + } if err := file.WriterFile(filepath.Join(outputDir, fmt.Sprintf("%s.%s.json", prefix, config.Name)), config.JsonClient()); err != nil { panic(err) } @@ -45,13 +48,21 @@ func (slf *ConfigExport) ExportClient(prefix, outputDir string) { func (slf *ConfigExport) ExportServer(prefix, outputDir string) { for _, config := range slf.configs { config := config + if len(prefix) > 0 { + config.Prefix = fmt.Sprintf("%s.", prefix) + } if err := file.WriterFile(filepath.Join(outputDir, fmt.Sprintf("%s.%s.json", prefix, config.Name)), config.JsonServer()); err != nil { panic(err) } } } -func (slf *ConfigExport) ExportGo(outputDir string) { +func (slf *ConfigExport) ExportGo(prefix, outputDir string) { + if len(prefix) > 0 { + for _, config := range slf.configs { + config.Prefix = fmt.Sprintf("%s.", prefix) + } + } slf.exportGoConfig(outputDir) slf.exportGoDefine(outputDir) } diff --git a/planner/configexport/configexport_test.go b/planner/configexport/configexport_test.go index 90a5b9b..b8a379d 100644 --- a/planner/configexport/configexport_test.go +++ b/planner/configexport/configexport_test.go @@ -5,7 +5,7 @@ import "testing" func TestNew(t *testing.T) { c := New(`D:\sources\minotaur\planner\configexport\template.xlsx`) - c.ExportGo("./example") + c.ExportGo("server", "./example") c.ExportClient("client", "./example") c.ExportServer("server", "./example") } diff --git a/planner/configexport/example/client.UNConfig.json b/planner/configexport/example/client.UNConfig.json index 2174b4c..67c853c 100644 --- a/planner/configexport/example/client.UNConfig.json +++ b/planner/configexport/example/client.UNConfig.json @@ -11,8 +11,8 @@ "name": "张飞" }, "1": { - "name": "刘备", - "id": 2 + "id": 2, + "name": "刘备" } } } \ No newline at end of file diff --git a/planner/configexport/example/client.XXConfig.json b/planner/configexport/example/client.XXConfig.json index 8c7c6c3..720cdf1 100644 --- a/planner/configexport/example/client.XXConfig.json +++ b/planner/configexport/example/client.XXConfig.json @@ -1,44 +1,27 @@ { "1": { - "a": { - "Id": 1, - "Count": "a", - "Award": { - "0": "asd", - "1": "12" - }, + "b": { "Other": { "0": { - "name": "张飞", - "id": 1 + "id": 1, + "name": "张飞" }, "1": { "id": 2, "name": "刘备" } - } - }, - "b": { + }, "Id": 1, "Count": "b", "Award": { "0": "asd", "1": "12" - }, - "Other": { - "0": { - "id": 1, - "name": "张飞" - }, - "1": { - "id": 2, - "name": "刘备" - } } } }, "2": { "c": { + "Count": "c", "Award": { "0": "asd", "1": "12" @@ -53,8 +36,7 @@ "name": "刘备" } }, - "Id": 2, - "Count": "c" + "Id": 2 }, "d": { "Id": 2, diff --git a/planner/configexport/example/config.go b/planner/configexport/example/config.go index 2e581e2..9d80983 100644 --- a/planner/configexport/example/config.go +++ b/planner/configexport/example/config.go @@ -14,8 +14,8 @@ var ( ) func LoadConfig(handle func(filename string, config any) error) { - handle("XXConfig.json", &gameXXConfig) - handle("UNConfig.json", &gameUNConfig) + handle("server.XXConfig.json", &gameXXConfig) + handle("server.UNConfig.json", &gameUNConfig) } func Refresh() { diff --git a/planner/configexport/example/server.XXConfig.json b/planner/configexport/example/server.XXConfig.json index 2416d88..2019748 100644 --- a/planner/configexport/example/server.XXConfig.json +++ b/planner/configexport/example/server.XXConfig.json @@ -1,34 +1,10 @@ { "1": { - "a": { - "Id": 1, - "Count": "a", - "Info": { - "id": 1, - "name": "小明", - "info": { - "exp": { - "mux": 10, - "count": 100 - }, - "lv": 1 - } - }, - "Other": { - "0": { - "id": 1, - "name": "张飞" - }, - "1": { - "id": 2, - "name": "刘备" - } - } - }, "b": { "Id": 1, "Count": "b", "Info": { + "id": 1, "name": "小明", "info": { "lv": 1, @@ -36,13 +12,12 @@ "mux": 10, "count": 100 } - }, - "id": 1 + } }, "Other": { "0": { - "id": 1, - "name": "张飞" + "name": "张飞", + "id": 1 }, "1": { "id": 2, @@ -66,41 +41,41 @@ } }, "Other": { + "0": { + "name": "张飞", + "id": 1 + }, "1": { "id": 2, "name": "刘备" - }, - "0": { - "id": 1, - "name": "张飞" } }, "Id": 2 }, "d": { - "Id": 2, - "Count": "d", "Info": { - "id": 1, "name": "小明", "info": { "lv": 1, "exp": { - "count": 100, - "mux": 10 + "mux": 10, + "count": 100 } - } + }, + "id": 1 }, "Other": { - "0": { - "id": 1, - "name": "张飞" - }, "1": { "id": 2, "name": "刘备" + }, + "0": { + "id": 1, + "name": "张飞" } - } + }, + "Id": 2, + "Count": "d" } } } \ No newline at end of file diff --git a/planner/configexport/internal/config.go b/planner/configexport/internal/config.go index 65cda64..399a01b 100644 --- a/planner/configexport/internal/config.go +++ b/planner/configexport/internal/config.go @@ -27,6 +27,7 @@ func NewConfig(sheet *xlsx.Sheet) (*Config, error) { } type Config struct { + Prefix string DisplayName string Name string Describe string @@ -118,27 +119,31 @@ func (slf *Config) initField(sheet *xlsx.Sheet) error { var ( describe, fieldName, fieldType, exportParam string ) - + var skip bool if value := slf.matrix.Get(dx, dy); value == nil { - return ErrReadConfigFailedWithFieldPosition + skip = true } else { describe = value.String() } if value := slf.matrix.Get(nx, ny); value == nil { - return ErrReadConfigFailedWithFieldPosition + skip = true } else { fieldName = str.FirstUpper(strings.TrimSpace(value.String())) } if value := slf.matrix.Get(tx, ty); value == nil { - return ErrReadConfigFailedWithFieldPosition + skip = true } else { fieldType = strings.TrimSpace(value.String()) } if value := slf.matrix.Get(ex, ey); value == nil { - return ErrReadConfigFailedWithFieldPosition + skip = true } else { exportParam = strings.ToLower(strings.TrimSpace(value.String())) } + if len(strings.TrimSpace(fieldName))+len(strings.TrimSpace(fieldType))+len(strings.TrimSpace(exportParam)) < 3 { + skip = true + } + var field = NewField(slf.Name, fieldName, fieldType) field.Describe = describe field.ExportParam = exportParam @@ -159,38 +164,41 @@ func (slf *Config) initField(sheet *xlsx.Sheet) error { ey++ } - field.Ignore = slf.excludeFields[len(slf.Fields)] - if !field.Ignore { - if strings.HasPrefix(field.Describe, slf.ignore) { - field.Ignore = true - } else if strings.HasPrefix(field.Name, slf.ignore) { - field.Ignore = true - } else if strings.HasPrefix(field.Type, slf.ignore) { - field.Ignore = true - } else if strings.HasPrefix(field.ExportParam, slf.ignore) { - field.Ignore = true - } - } - if !field.Ignore { - switch exportParam { - case "s", "c", "sc", "cs": - default: - return ErrReadConfigFailedWithExportParamException - } - } + if !skip { - if fields[field.Name] && !field.Ignore { - return ErrReadConfigFailedWithNameDuplicate - } - if index > 0 && !field.Ignore { - if _, exist := basicTypeName[field.Type]; !exist { - return ErrReadConfigFailedWithIndexTypeException + field.Ignore = slf.excludeFields[len(slf.Fields)] + if !field.Ignore { + if strings.HasPrefix(field.Describe, slf.ignore) { + field.Ignore = true + } else if strings.HasPrefix(field.Name, slf.ignore) { + field.Ignore = true + } else if strings.HasPrefix(field.Type, slf.ignore) { + field.Ignore = true + } else if strings.HasPrefix(field.ExportParam, slf.ignore) { + field.Ignore = true + } + } + if !field.Ignore { + switch exportParam { + case "s", "c", "sc", "cs": + default: + continue + } } - index-- - } - fields[field.Name] = true - slf.Fields = append(slf.Fields, field) + if fields[field.Name] && !field.Ignore { + return ErrReadConfigFailedWithNameDuplicate + } + if index > 0 && !field.Ignore { + if _, exist := basicTypeName[field.Type]; !exist { + return ErrReadConfigFailedWithIndexTypeException + } + index-- + } + + fields[field.Name] = true + slf.Fields = append(slf.Fields, field) + } if horizontal { if dx >= slf.matrix.GetWidth() { @@ -223,17 +231,39 @@ func (slf *Config) initData() error { var lineServer = map[any]any{} var lineClient = map[any]any{} + var skip bool + var offset int for i := 0; i < len(slf.Fields); i++ { if slf.excludeFields[i] { + if c := slf.matrix.Get(x+i, y); c != nil && strings.HasPrefix(c.String(), "#") { + skip = true + break + } continue } field := slf.Fields[i] + if field.Ignore { + continue + } var value any if slf.horizontal { - value = getValueWithType(field.SourceType, slf.matrix.Get(x+i, y).String()) + c := slf.matrix.Get(x+i, y) + if c == nil || (currentIndex < slf.IndexCount && len(c.String()) == 0) { + skip = true + break + } + value = getValueWithType(field.SourceType, c.String()) } else { - value = getValueWithType(field.SourceType, slf.matrix.Get(x, y+i).String()) + c := slf.matrix.Get(x, y+i+offset) + for c == nil { + offset++ + c = slf.matrix.Get(x, y+i+offset) + if y+i+offset >= slf.matrix.GetHeight() { + break + } + } + value = getValueWithType(field.SourceType, c.String()) } switch field.ExportParam { case "s": @@ -280,12 +310,11 @@ func (slf *Config) initData() error { break } } else { - x++ - if x >= slf.matrix.GetWidth() { + if !skip { slf.dataServer = lineServer slf.dataClient = lineClient - break } + break } } if slf.horizontal { diff --git a/planner/configexport/internal/template.go b/planner/configexport/internal/template.go index 82bf982..cb0c64d 100644 --- a/planner/configexport/internal/template.go +++ b/planner/configexport/internal/template.go @@ -42,7 +42,7 @@ var ( func LoadConfig(handle func(filename string, config any) error) { {{range $index, $config := .Configs}} - handle("{{$config.Name}}.json", &game{{$config.Name}}) + handle("{{$config.Prefix}}{{$config.Name}}.json", &game{{$config.Name}}) {{end}} } diff --git a/planner/configexport/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