【优化】新增 --go:bright_module_name 参数,优化go的生成代码,使用比较地道的module机制

main
walon 2021-12-17 10:24:58 +08:00
parent 4f8fd20780
commit 9e6463f18d
12 changed files with 44 additions and 18 deletions

View File

@ -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;

View File

@ -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_)
}}
";
}

View File

@ -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_)
}}
";
}

View File

@ -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<string> x)
{
x.Add("errors");
x.Add("bright/math");
x.Add($"{DefAssembly.LocalAssebmly.Args.GoBrightModuleName}/serialization");
}
public override void Accept(TVector3 type, HashSet<string> x)
{
x.Add("errors");
x.Add("bright/math");
x.Add($"{DefAssembly.LocalAssebmly.Args.GoBrightModuleName}/serialization");
}
public override void Accept(TVector4 type, HashSet<string> x)
{
x.Add("errors");
x.Add("bright/math");
x.Add($"{DefAssembly.LocalAssebmly.Args.GoBrightModuleName}/serialization");
}
}
}

View File

@ -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;

View File

@ -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 <module name> ' missing";
return false;
}
return true;
}
public bool ValidateConvention(ref string errMsg)
{
if (!TryParseNamingConvention(NamingConventionModuleStr, out var m))

View File

@ -35,17 +35,17 @@ namespace Luban.Job.Common.TypeVisitors
public override void Accept(TVector2 type, HashSet<string> x)
{
x.Add("bright/math");
//x.Add("bright/serialization");
}
public override void Accept(TVector3 type, HashSet<string> x)
{
x.Add("bright/math");
//x.Add("bright/serialization");
}
public override void Accept(TVector4 type, HashSet<string> x)
{
x.Add("bright/math");
//x.Add("bright/serialization");
}
}
}

View File

@ -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)

View File

@ -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;

View File

@ -9,7 +9,7 @@
package {{x.top_module}}
import (
"bright/serialization"
"{{assembly.args.go_bright_module_name}}/serialization"
)
{{x.go_bin_import}}

View File

@ -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 {

View File

@ -6,7 +6,7 @@
package {{namespace}}
import "bright/serialization"
import "{{assembly.args.go_bright_module_name}}/serialization"
type ByteBufLoader func(string) (*serialization.ByteBuf, error)