导表工具优化
This commit is contained in:
parent
72fd4f127e
commit
2372d262bd
|
@ -36,6 +36,9 @@ type ConfigExport struct {
|
||||||
func (slf *ConfigExport) ExportClient(prefix, outputDir string) {
|
func (slf *ConfigExport) ExportClient(prefix, outputDir string) {
|
||||||
for _, config := range slf.configs {
|
for _, config := range slf.configs {
|
||||||
config := config
|
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 {
|
if err := file.WriterFile(filepath.Join(outputDir, fmt.Sprintf("%s.%s.json", prefix, config.Name)), config.JsonClient()); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -45,13 +48,21 @@ func (slf *ConfigExport) ExportClient(prefix, outputDir string) {
|
||||||
func (slf *ConfigExport) ExportServer(prefix, outputDir string) {
|
func (slf *ConfigExport) ExportServer(prefix, outputDir string) {
|
||||||
for _, config := range slf.configs {
|
for _, config := range slf.configs {
|
||||||
config := config
|
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 {
|
if err := file.WriterFile(filepath.Join(outputDir, fmt.Sprintf("%s.%s.json", prefix, config.Name)), config.JsonServer()); err != nil {
|
||||||
panic(err)
|
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.exportGoConfig(outputDir)
|
||||||
slf.exportGoDefine(outputDir)
|
slf.exportGoDefine(outputDir)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import "testing"
|
||||||
func TestNew(t *testing.T) {
|
func TestNew(t *testing.T) {
|
||||||
c := New(`D:\sources\minotaur\planner\configexport\template.xlsx`)
|
c := New(`D:\sources\minotaur\planner\configexport\template.xlsx`)
|
||||||
|
|
||||||
c.ExportGo("./example")
|
c.ExportGo("server", "./example")
|
||||||
c.ExportClient("client", "./example")
|
c.ExportClient("client", "./example")
|
||||||
c.ExportServer("server", "./example")
|
c.ExportServer("server", "./example")
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
"name": "张飞"
|
"name": "张飞"
|
||||||
},
|
},
|
||||||
"1": {
|
"1": {
|
||||||
"name": "刘备",
|
"id": 2,
|
||||||
"id": 2
|
"name": "刘备"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,44 +1,27 @@
|
||||||
{
|
{
|
||||||
"1": {
|
"1": {
|
||||||
"a": {
|
"b": {
|
||||||
"Id": 1,
|
|
||||||
"Count": "a",
|
|
||||||
"Award": {
|
|
||||||
"0": "asd",
|
|
||||||
"1": "12"
|
|
||||||
},
|
|
||||||
"Other": {
|
"Other": {
|
||||||
"0": {
|
"0": {
|
||||||
"name": "张飞",
|
"id": 1,
|
||||||
"id": 1
|
"name": "张飞"
|
||||||
},
|
},
|
||||||
"1": {
|
"1": {
|
||||||
"id": 2,
|
"id": 2,
|
||||||
"name": "刘备"
|
"name": "刘备"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
|
||||||
"b": {
|
|
||||||
"Id": 1,
|
"Id": 1,
|
||||||
"Count": "b",
|
"Count": "b",
|
||||||
"Award": {
|
"Award": {
|
||||||
"0": "asd",
|
"0": "asd",
|
||||||
"1": "12"
|
"1": "12"
|
||||||
},
|
|
||||||
"Other": {
|
|
||||||
"0": {
|
|
||||||
"id": 1,
|
|
||||||
"name": "张飞"
|
|
||||||
},
|
|
||||||
"1": {
|
|
||||||
"id": 2,
|
|
||||||
"name": "刘备"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"2": {
|
"2": {
|
||||||
"c": {
|
"c": {
|
||||||
|
"Count": "c",
|
||||||
"Award": {
|
"Award": {
|
||||||
"0": "asd",
|
"0": "asd",
|
||||||
"1": "12"
|
"1": "12"
|
||||||
|
@ -53,8 +36,7 @@
|
||||||
"name": "刘备"
|
"name": "刘备"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Id": 2,
|
"Id": 2
|
||||||
"Count": "c"
|
|
||||||
},
|
},
|
||||||
"d": {
|
"d": {
|
||||||
"Id": 2,
|
"Id": 2,
|
||||||
|
|
|
@ -14,8 +14,8 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoadConfig(handle func(filename string, config any) error) {
|
func LoadConfig(handle func(filename string, config any) error) {
|
||||||
handle("XXConfig.json", &gameXXConfig)
|
handle("server.XXConfig.json", &gameXXConfig)
|
||||||
handle("UNConfig.json", &gameUNConfig)
|
handle("server.UNConfig.json", &gameUNConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Refresh() {
|
func Refresh() {
|
||||||
|
|
|
@ -1,34 +1,10 @@
|
||||||
{
|
{
|
||||||
"1": {
|
"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": {
|
"b": {
|
||||||
"Id": 1,
|
"Id": 1,
|
||||||
"Count": "b",
|
"Count": "b",
|
||||||
"Info": {
|
"Info": {
|
||||||
|
"id": 1,
|
||||||
"name": "小明",
|
"name": "小明",
|
||||||
"info": {
|
"info": {
|
||||||
"lv": 1,
|
"lv": 1,
|
||||||
|
@ -36,13 +12,12 @@
|
||||||
"mux": 10,
|
"mux": 10,
|
||||||
"count": 100
|
"count": 100
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"id": 1
|
|
||||||
},
|
},
|
||||||
"Other": {
|
"Other": {
|
||||||
"0": {
|
"0": {
|
||||||
"id": 1,
|
"name": "张飞",
|
||||||
"name": "张飞"
|
"id": 1
|
||||||
},
|
},
|
||||||
"1": {
|
"1": {
|
||||||
"id": 2,
|
"id": 2,
|
||||||
|
@ -66,41 +41,41 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Other": {
|
"Other": {
|
||||||
|
"0": {
|
||||||
|
"name": "张飞",
|
||||||
|
"id": 1
|
||||||
|
},
|
||||||
"1": {
|
"1": {
|
||||||
"id": 2,
|
"id": 2,
|
||||||
"name": "刘备"
|
"name": "刘备"
|
||||||
},
|
|
||||||
"0": {
|
|
||||||
"id": 1,
|
|
||||||
"name": "张飞"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Id": 2
|
"Id": 2
|
||||||
},
|
},
|
||||||
"d": {
|
"d": {
|
||||||
"Id": 2,
|
|
||||||
"Count": "d",
|
|
||||||
"Info": {
|
"Info": {
|
||||||
"id": 1,
|
|
||||||
"name": "小明",
|
"name": "小明",
|
||||||
"info": {
|
"info": {
|
||||||
"lv": 1,
|
"lv": 1,
|
||||||
"exp": {
|
"exp": {
|
||||||
"count": 100,
|
"mux": 10,
|
||||||
"mux": 10
|
"count": 100
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"id": 1
|
||||||
},
|
},
|
||||||
"Other": {
|
"Other": {
|
||||||
"0": {
|
|
||||||
"id": 1,
|
|
||||||
"name": "张飞"
|
|
||||||
},
|
|
||||||
"1": {
|
"1": {
|
||||||
"id": 2,
|
"id": 2,
|
||||||
"name": "刘备"
|
"name": "刘备"
|
||||||
|
},
|
||||||
|
"0": {
|
||||||
|
"id": 1,
|
||||||
|
"name": "张飞"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"Id": 2,
|
||||||
|
"Count": "d"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -27,6 +27,7 @@ func NewConfig(sheet *xlsx.Sheet) (*Config, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
Prefix string
|
||||||
DisplayName string
|
DisplayName string
|
||||||
Name string
|
Name string
|
||||||
Describe string
|
Describe string
|
||||||
|
@ -118,27 +119,31 @@ func (slf *Config) initField(sheet *xlsx.Sheet) error {
|
||||||
var (
|
var (
|
||||||
describe, fieldName, fieldType, exportParam string
|
describe, fieldName, fieldType, exportParam string
|
||||||
)
|
)
|
||||||
|
var skip bool
|
||||||
if value := slf.matrix.Get(dx, dy); value == nil {
|
if value := slf.matrix.Get(dx, dy); value == nil {
|
||||||
return ErrReadConfigFailedWithFieldPosition
|
skip = true
|
||||||
} else {
|
} else {
|
||||||
describe = value.String()
|
describe = value.String()
|
||||||
}
|
}
|
||||||
if value := slf.matrix.Get(nx, ny); value == nil {
|
if value := slf.matrix.Get(nx, ny); value == nil {
|
||||||
return ErrReadConfigFailedWithFieldPosition
|
skip = true
|
||||||
} else {
|
} else {
|
||||||
fieldName = str.FirstUpper(strings.TrimSpace(value.String()))
|
fieldName = str.FirstUpper(strings.TrimSpace(value.String()))
|
||||||
}
|
}
|
||||||
if value := slf.matrix.Get(tx, ty); value == nil {
|
if value := slf.matrix.Get(tx, ty); value == nil {
|
||||||
return ErrReadConfigFailedWithFieldPosition
|
skip = true
|
||||||
} else {
|
} else {
|
||||||
fieldType = strings.TrimSpace(value.String())
|
fieldType = strings.TrimSpace(value.String())
|
||||||
}
|
}
|
||||||
if value := slf.matrix.Get(ex, ey); value == nil {
|
if value := slf.matrix.Get(ex, ey); value == nil {
|
||||||
return ErrReadConfigFailedWithFieldPosition
|
skip = true
|
||||||
} else {
|
} else {
|
||||||
exportParam = strings.ToLower(strings.TrimSpace(value.String()))
|
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)
|
var field = NewField(slf.Name, fieldName, fieldType)
|
||||||
field.Describe = describe
|
field.Describe = describe
|
||||||
field.ExportParam = exportParam
|
field.ExportParam = exportParam
|
||||||
|
@ -159,38 +164,41 @@ func (slf *Config) initField(sheet *xlsx.Sheet) error {
|
||||||
ey++
|
ey++
|
||||||
}
|
}
|
||||||
|
|
||||||
field.Ignore = slf.excludeFields[len(slf.Fields)]
|
if !skip {
|
||||||
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 fields[field.Name] && !field.Ignore {
|
field.Ignore = slf.excludeFields[len(slf.Fields)]
|
||||||
return ErrReadConfigFailedWithNameDuplicate
|
if !field.Ignore {
|
||||||
}
|
if strings.HasPrefix(field.Describe, slf.ignore) {
|
||||||
if index > 0 && !field.Ignore {
|
field.Ignore = true
|
||||||
if _, exist := basicTypeName[field.Type]; !exist {
|
} else if strings.HasPrefix(field.Name, slf.ignore) {
|
||||||
return ErrReadConfigFailedWithIndexTypeException
|
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
|
if fields[field.Name] && !field.Ignore {
|
||||||
slf.Fields = append(slf.Fields, field)
|
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 horizontal {
|
||||||
if dx >= slf.matrix.GetWidth() {
|
if dx >= slf.matrix.GetWidth() {
|
||||||
|
@ -223,17 +231,39 @@ func (slf *Config) initData() error {
|
||||||
|
|
||||||
var lineServer = map[any]any{}
|
var lineServer = map[any]any{}
|
||||||
var lineClient = map[any]any{}
|
var lineClient = map[any]any{}
|
||||||
|
var skip bool
|
||||||
|
var offset int
|
||||||
for i := 0; i < len(slf.Fields); i++ {
|
for i := 0; i < len(slf.Fields); i++ {
|
||||||
if slf.excludeFields[i] {
|
if slf.excludeFields[i] {
|
||||||
|
if c := slf.matrix.Get(x+i, y); c != nil && strings.HasPrefix(c.String(), "#") {
|
||||||
|
skip = true
|
||||||
|
break
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
field := slf.Fields[i]
|
field := slf.Fields[i]
|
||||||
|
if field.Ignore {
|
||||||
|
continue
|
||||||
|
}
|
||||||
var value any
|
var value any
|
||||||
if slf.horizontal {
|
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 {
|
} 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 {
|
switch field.ExportParam {
|
||||||
case "s":
|
case "s":
|
||||||
|
@ -280,12 +310,11 @@ func (slf *Config) initData() error {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
x++
|
if !skip {
|
||||||
if x >= slf.matrix.GetWidth() {
|
|
||||||
slf.dataServer = lineServer
|
slf.dataServer = lineServer
|
||||||
slf.dataClient = lineClient
|
slf.dataClient = lineClient
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if slf.horizontal {
|
if slf.horizontal {
|
||||||
|
|
|
@ -42,7 +42,7 @@ var (
|
||||||
|
|
||||||
func LoadConfig(handle func(filename string, config any) error) {
|
func LoadConfig(handle func(filename string, config any) error) {
|
||||||
{{range $index, $config := .Configs}}
|
{{range $index, $config := .Configs}}
|
||||||
handle("{{$config.Name}}.json", &game{{$config.Name}})
|
handle("{{$config.Prefix}}{{$config.Name}}.json", &game{{$config.Name}})
|
||||||
{{end}}
|
{{end}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue