From 9e6463f18dd72c503c867dabd75de142b3b6ba11 Mon Sep 17 00:00:00 2001 From: walon Date: Fri, 17 Dec 2021 10:24:58 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20--go:bright=5Fmodule=5Fname=20=E5=8F=82=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96go=E7=9A=84=E7=94=9F=E6=88=90?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=EF=BC=8C=E4=BD=BF=E7=94=A8=E6=AF=94=E8=BE=83?= =?UTF-8?q?=E5=9C=B0=E9=81=93=E7=9A=84module=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Luban.Job.Cfg/Source/JobController.cs | 4 ++++ .../GoDeserializeJsonUndering2Visitor.cs | 6 +++--- .../GoDeserializeJsonUnderingVisitor.cs | 6 +++--- .../Source/TypeVisitors/GoJsonImport.cs | 7 ++++--- src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs | 4 ++++ src/Luban.Job.Common/Source/GenArgsBase.cs | 13 +++++++++++++ .../Source/TypeVisitors/GoBinImport.cs | 6 +++--- .../TypeVisitors/GoTypeUnderingNameVisitor.cs | 6 +++--- src/Luban.Job.Proto/Source/JobController.cs | 4 ++++ src/Luban.Server/Templates/config/go_bin/bean.tpl | 2 +- src/Luban.Server/Templates/config/go_bin/table.tpl | 2 +- src/Luban.Server/Templates/config/go_bin/tables.tpl | 2 +- 12 files changed, 44 insertions(+), 18 deletions(-) diff --git a/src/Luban.Job.Cfg/Source/JobController.cs b/src/Luban.Job.Cfg/Source/JobController.cs index 4a1f4cc..d95aafc 100644 --- a/src/Luban.Job.Cfg/Source/JobController.cs +++ b/src/Luban.Job.Cfg/Source/JobController.cs @@ -103,6 +103,10 @@ namespace Luban.Job.Cfg { return false; } + if (options.GenType.Contains("go_") && !options.ValidateGoRequire(options.GenType, ref errMsg)) + { + return false; + } if (!options.ValidateConvention(ref errMsg)) { return false; diff --git a/src/Luban.Job.Cfg/Source/TypeVisitors/GoDeserializeJsonUndering2Visitor.cs b/src/Luban.Job.Cfg/Source/TypeVisitors/GoDeserializeJsonUndering2Visitor.cs index c680a3b..782a269 100644 --- a/src/Luban.Job.Cfg/Source/TypeVisitors/GoDeserializeJsonUndering2Visitor.cs +++ b/src/Luban.Job.Cfg/Source/TypeVisitors/GoDeserializeJsonUndering2Visitor.cs @@ -96,7 +96,7 @@ namespace Luban.Job.Cfg.TypeVisitors var _x_, _y_ float32; {TFloat.Ins.Apply(GoDeserializeJsonUnderingVisitor.Ins, "_x_", "x", "_v_")} {TFloat.Ins.Apply(GoDeserializeJsonUnderingVisitor.Ins, "_y_", "y", "_v_")} - {varName} = math.NewVector2(_x_, _y_) + {varName} = serialization.NewVector2(_x_, _y_) }} "; } @@ -108,7 +108,7 @@ namespace Luban.Job.Cfg.TypeVisitors {TFloat.Ins.Apply(GoDeserializeJsonUnderingVisitor.Ins, "_x_", "x", "_v_")} {TFloat.Ins.Apply(GoDeserializeJsonUnderingVisitor.Ins, "_y_", "y", "_v_")} {TFloat.Ins.Apply(GoDeserializeJsonUnderingVisitor.Ins, "_z_", "z", "_v_")} - {varName} = math.NewVector3(_x_, _y_, _z_) + {varName} = serialization.NewVector3(_x_, _y_, _z_) }} "; } @@ -121,7 +121,7 @@ namespace Luban.Job.Cfg.TypeVisitors {TFloat.Ins.Apply(GoDeserializeJsonUnderingVisitor.Ins, "_y_", "y", "_v_")} {TFloat.Ins.Apply(GoDeserializeJsonUnderingVisitor.Ins, "_z_", "z", "_v_")} {TFloat.Ins.Apply(GoDeserializeJsonUnderingVisitor.Ins, "_w_", "w", "_v_")} - {varName} = math.NewVector4(_x_, _y_, _z_, _w_) + {varName} = serialization.NewVector4(_x_, _y_, _z_, _w_) }} "; } diff --git a/src/Luban.Job.Cfg/Source/TypeVisitors/GoDeserializeJsonUnderingVisitor.cs b/src/Luban.Job.Cfg/Source/TypeVisitors/GoDeserializeJsonUnderingVisitor.cs index 5aba279..b0e28fd 100644 --- a/src/Luban.Job.Cfg/Source/TypeVisitors/GoDeserializeJsonUnderingVisitor.cs +++ b/src/Luban.Job.Cfg/Source/TypeVisitors/GoDeserializeJsonUnderingVisitor.cs @@ -96,7 +96,7 @@ namespace Luban.Job.Cfg.TypeVisitors var _x_, _y_ float32; {TFloat.Ins.Apply(this, "_x_", "x", "_v_")} {TFloat.Ins.Apply(this, "_y_", "y", "_v_")} - {varName} = math.NewVector2(_x_, _y_) + {varName} = serialization.NewVector2(_x_, _y_) }} "; } @@ -108,7 +108,7 @@ namespace Luban.Job.Cfg.TypeVisitors {TFloat.Ins.Apply(this, "_x_", "x", "_v_")} {TFloat.Ins.Apply(this, "_y_", "y", "_v_")} {TFloat.Ins.Apply(this, "_z_", "z", "_v_")} - {varName} = math.NewVector3(_x_, _y_, _z_) + {varName} = serialization.NewVector3(_x_, _y_, _z_) }} "; } @@ -121,7 +121,7 @@ namespace Luban.Job.Cfg.TypeVisitors {TFloat.Ins.Apply(this, "_y_", "y", "_v_")} {TFloat.Ins.Apply(this, "_z_", "z", "_v_")} {TFloat.Ins.Apply(this, "_w_", "w", "_v_")} - {varName} = math.NewVector4(_x_, _y_, _z_, _w_) + {varName} = serialization.NewVector4(_x_, _y_, _z_, _w_) }} "; } diff --git a/src/Luban.Job.Cfg/Source/TypeVisitors/GoJsonImport.cs b/src/Luban.Job.Cfg/Source/TypeVisitors/GoJsonImport.cs index 03eec3f..390f1c2 100644 --- a/src/Luban.Job.Cfg/Source/TypeVisitors/GoJsonImport.cs +++ b/src/Luban.Job.Cfg/Source/TypeVisitors/GoJsonImport.cs @@ -1,3 +1,4 @@ +using Luban.Job.Cfg.Defs; using Luban.Job.Common.Types; using Luban.Job.Common.TypeVisitors; using System.Collections.Generic; @@ -37,19 +38,19 @@ namespace Luban.Job.Cfg.TypeVisitors public override void Accept(TVector2 type, HashSet x) { x.Add("errors"); - x.Add("bright/math"); + x.Add($"{DefAssembly.LocalAssebmly.Args.GoBrightModuleName}/serialization"); } public override void Accept(TVector3 type, HashSet x) { x.Add("errors"); - x.Add("bright/math"); + x.Add($"{DefAssembly.LocalAssebmly.Args.GoBrightModuleName}/serialization"); } public override void Accept(TVector4 type, HashSet x) { x.Add("errors"); - x.Add("bright/math"); + x.Add($"{DefAssembly.LocalAssebmly.Args.GoBrightModuleName}/serialization"); } } } diff --git a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs index 25cb11f..f41846c 100644 --- a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs +++ b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs @@ -43,6 +43,8 @@ namespace Luban.Job.Common.Defs public bool CsUseUnityVectors { get; set; } + public GenArgsBase Args { get; private set; } + public NamingConvention NamingConventionModule { get; set; } = NamingConvention.LanguangeRecommend; public NamingConvention NamingConventionType { get; set; } = NamingConvention.LanguangeRecommend; @@ -90,6 +92,8 @@ namespace Luban.Job.Common.Defs this.ExternalSelectors = defines.ExternalSelectors; this.ExternalTypes = defines.ExternalTypes; + this.Args = args; + SetCurrentExternalSelectors(args.ExternalSelectors); CsUseUnityVectors = args.CsUseUnityVectors; diff --git a/src/Luban.Job.Common/Source/GenArgsBase.cs b/src/Luban.Job.Common/Source/GenArgsBase.cs index 5d779fb..9c29d43 100644 --- a/src/Luban.Job.Common/Source/GenArgsBase.cs +++ b/src/Luban.Job.Common/Source/GenArgsBase.cs @@ -53,6 +53,9 @@ namespace Luban.Job.Common [Option("cs:use_unity_vector", Required = false, HelpText = "use UnityEngine.Vector{2,3,4}")] public bool CsUseUnityVectors { get; set; } + [Option("go:bright_module_name", Required = false, HelpText = "go bright module name")] + public string GoBrightModuleName { get; set; } + [Option("external:selectors", Required = false, HelpText = "external selectors")] public string ExternalSelectors { get; set; } @@ -119,6 +122,16 @@ namespace Luban.Job.Common return true; } + public bool ValidateGoRequire(string genType, ref string errMsg) + { + if (string.IsNullOrWhiteSpace(this.GoBrightModuleName)) + { + errMsg = "option '--go:bright_module_name ' missing"; + return false; + } + return true; + } + public bool ValidateConvention(ref string errMsg) { if (!TryParseNamingConvention(NamingConventionModuleStr, out var m)) diff --git a/src/Luban.Job.Common/Source/TypeVisitors/GoBinImport.cs b/src/Luban.Job.Common/Source/TypeVisitors/GoBinImport.cs index a2a419e..f35005c 100644 --- a/src/Luban.Job.Common/Source/TypeVisitors/GoBinImport.cs +++ b/src/Luban.Job.Common/Source/TypeVisitors/GoBinImport.cs @@ -35,17 +35,17 @@ namespace Luban.Job.Common.TypeVisitors public override void Accept(TVector2 type, HashSet x) { - x.Add("bright/math"); + //x.Add("bright/serialization"); } public override void Accept(TVector3 type, HashSet x) { - x.Add("bright/math"); + //x.Add("bright/serialization"); } public override void Accept(TVector4 type, HashSet x) { - x.Add("bright/math"); + //x.Add("bright/serialization"); } } } diff --git a/src/Luban.Job.Common/Source/TypeVisitors/GoTypeUnderingNameVisitor.cs b/src/Luban.Job.Common/Source/TypeVisitors/GoTypeUnderingNameVisitor.cs index 26411e5..be16e1f 100644 --- a/src/Luban.Job.Common/Source/TypeVisitors/GoTypeUnderingNameVisitor.cs +++ b/src/Luban.Job.Common/Source/TypeVisitors/GoTypeUnderingNameVisitor.cs @@ -104,17 +104,17 @@ namespace Luban.Job.Common.TypeVisitors public string Accept(TVector2 type) { - return $"math.Vector2"; + return $"serialization.Vector2"; } public string Accept(TVector3 type) { - return $"math.Vector3"; + return $"serialization.Vector3"; } public string Accept(TVector4 type) { - return $"math.Vector4"; + return $"serialization.Vector4"; } public string Accept(TDateTime type) diff --git a/src/Luban.Job.Proto/Source/JobController.cs b/src/Luban.Job.Proto/Source/JobController.cs index cc2fed1..e397278 100644 --- a/src/Luban.Job.Proto/Source/JobController.cs +++ b/src/Luban.Job.Proto/Source/JobController.cs @@ -49,6 +49,10 @@ namespace Luban.Job.Proto { return false; } + if (options.GenType.Contains("go_") && !options.ValidateGoRequire(options.GenType, ref errMsg)) + { + return false; + } if (!options.ValidateConvention(ref errMsg)) { return false; diff --git a/src/Luban.Server/Templates/config/go_bin/bean.tpl b/src/Luban.Server/Templates/config/go_bin/bean.tpl index a3628fc..5132f00 100644 --- a/src/Luban.Server/Templates/config/go_bin/bean.tpl +++ b/src/Luban.Server/Templates/config/go_bin/bean.tpl @@ -9,7 +9,7 @@ package {{x.top_module}} import ( - "bright/serialization" + "{{assembly.args.go_bright_module_name}}/serialization" ) {{x.go_bin_import}} diff --git a/src/Luban.Server/Templates/config/go_bin/table.tpl b/src/Luban.Server/Templates/config/go_bin/table.tpl index 1714a27..10779a2 100644 --- a/src/Luban.Server/Templates/config/go_bin/table.tpl +++ b/src/Luban.Server/Templates/config/go_bin/table.tpl @@ -11,7 +11,7 @@ package {{x.top_module}} -import "bright/serialization" +import "{{assembly.args.go_bright_module_name}}/serialization" {{~if x.is_map_table~}} type {{go_full_name}} struct { diff --git a/src/Luban.Server/Templates/config/go_bin/tables.tpl b/src/Luban.Server/Templates/config/go_bin/tables.tpl index 396dbb4..1012f91 100644 --- a/src/Luban.Server/Templates/config/go_bin/tables.tpl +++ b/src/Luban.Server/Templates/config/go_bin/tables.tpl @@ -6,7 +6,7 @@ package {{namespace}} -import "bright/serialization" +import "{{assembly.args.go_bright_module_name}}/serialization" type ByteBufLoader func(string) (*serialization.ByteBuf, error)