【重构】重构 cfg JobController代码,减少重复代码
【调整】原来data_lua中类型部分代码被移到 code_lua_lua目标中 【修复】修复go_bin的生成代码有编译错误的问题main
parent
d7dbdf4b94
commit
f164dc82fb
|
|
@ -1,10 +1,11 @@
|
||||||
using Bright.Serialization;
|
using Bright.Serialization;
|
||||||
using Luban.Job.Cfg.Datas;
|
using Luban.Job.Cfg.Datas;
|
||||||
|
using Luban.Job.Cfg.DataVisitors;
|
||||||
using Luban.Job.Cfg.Defs;
|
using Luban.Job.Cfg.Defs;
|
||||||
using Luban.Job.Common.TypeVisitors;
|
using Luban.Job.Common.TypeVisitors;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.DataVisitors
|
namespace Luban.Job.Cfg.DataExporters
|
||||||
{
|
{
|
||||||
class BinaryExportor : IDataActionVisitor<DefAssembly, ByteBuf>
|
class BinaryExportor : IDataActionVisitor<DefAssembly, ByteBuf>
|
||||||
{
|
{
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
using Luban.Job.Cfg.Datas;
|
using Luban.Job.Cfg.Datas;
|
||||||
|
using Luban.Job.Cfg.DataVisitors;
|
||||||
using Luban.Job.Cfg.Defs;
|
using Luban.Job.Cfg.Defs;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.DataVisitors
|
namespace Luban.Job.Cfg.DataExporters
|
||||||
{
|
{
|
||||||
class JsonExportor : IDataActionVisitor<DefAssembly, Utf8JsonWriter>
|
class JsonExportor : IDataActionVisitor<DefAssembly, Utf8JsonWriter>
|
||||||
{
|
{
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
using Luban.Job.Cfg.Datas;
|
using Luban.Job.Cfg.Datas;
|
||||||
|
using Luban.Job.Cfg.DataVisitors;
|
||||||
using Luban.Job.Cfg.Defs;
|
using Luban.Job.Cfg.Defs;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.DataVisitors
|
namespace Luban.Job.Cfg.DataExporters
|
||||||
{
|
{
|
||||||
class LuaExportor : IDataActionVisitor<DefAssembly, StringBuilder>
|
class LuaExportor : IDataActionVisitor<DefAssembly, StringBuilder>
|
||||||
{
|
{
|
||||||
|
|
@ -31,7 +31,7 @@ namespace Luban.Job.Cfg.Defs
|
||||||
return DeepCompareTypeDefine.Ins.Compare(this, b, new Dictionary<DefTypeBase, bool>(), new HashSet<DefTypeBase>());
|
return DeepCompareTypeDefine.Ins.Compare(this, b, new Dictionary<DefTypeBase, bool>(), new HashSet<DefTypeBase>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GoImport
|
public string GoBinImport
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
|
@ -42,7 +42,24 @@ namespace Luban.Job.Cfg.Defs
|
||||||
}
|
}
|
||||||
foreach (var f in Fields)
|
foreach (var f in Fields)
|
||||||
{
|
{
|
||||||
f.CType.Apply(CollectGoImport.Ins, imports);
|
f.CType.Apply(TypeVisitors.GoBinImport.Ins, imports);
|
||||||
|
}
|
||||||
|
return string.Join('\n', imports.Select(im => $"import \"{im}\""));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GoJsonImport
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var imports = new HashSet<string>();
|
||||||
|
if (IsAbstractType)
|
||||||
|
{
|
||||||
|
imports.Add("errors");
|
||||||
|
}
|
||||||
|
foreach (var f in Fields)
|
||||||
|
{
|
||||||
|
f.CType.Apply(TypeVisitors.GoJsonImport.Ins, imports);
|
||||||
}
|
}
|
||||||
return string.Join('\n', imports.Select(im => $"import \"{im}\""));
|
return string.Join('\n', imports.Select(im => $"import \"{im}\""));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,9 +49,9 @@ namespace Luban.Job.Cfg.Defs
|
||||||
|
|
||||||
public bool NeedExport => Assembly.NeedExport(this.Groups);
|
public bool NeedExport => Assembly.NeedExport(this.Groups);
|
||||||
|
|
||||||
public string OutputDataFile => $"{FullName}.bin";
|
public string OutputDataFile => FullName;
|
||||||
|
|
||||||
public string JsonOutputDataFile => $"{FullName}.json";
|
public string OutputDataFileEscapeDot => FullName.Replace('.', '_');
|
||||||
|
|
||||||
public List<string> GetBranchInputFiles(string branchName)
|
public List<string> GetBranchInputFiles(string branchName)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -80,12 +80,12 @@ namespace Luban.Job.Cfg.Defs
|
||||||
|
|
||||||
public static string GoDeserializeType(TBean type, string bufName)
|
public static string GoDeserializeType(TBean type, string bufName)
|
||||||
{
|
{
|
||||||
return type.Bean.IsAbstractType ? $"NewChild{type.Bean.GoFullName}({bufName})" : $"New{ type.Bean.GoFullName} ({ bufName})";
|
return $"New{type.Bean.GoFullName}({bufName})";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GoDeserializeField(TType type, string name, string bufName)
|
public static string GoDeserializeField(TType type, string name, string bufName)
|
||||||
{
|
{
|
||||||
return type.Apply(GoDeserializeVisitor.Ins, name, bufName);
|
return type.Apply(GoDeserializeBinVisitor.Ins, name, bufName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GoDeserializeJsonField(TType type, string name, string fieldName, string bufName)
|
public static string GoDeserializeJsonField(TType type, string name, string fieldName, string bufName)
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.Generate
|
namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
public abstract class CodeRenderBase : ICodeRender
|
public abstract class CodeRenderBase : ICfgCodeRender
|
||||||
{
|
{
|
||||||
public abstract string Render(DefConst c);
|
public abstract string Render(DefConst c);
|
||||||
public abstract string Render(DefEnum c);
|
public abstract string Render(DefEnum c);
|
||||||
|
|
@ -13,7 +13,7 @@ namespace Luban.Job.Cfg.Generate
|
||||||
public abstract string Render(DefTable c);
|
public abstract string Render(DefTable c);
|
||||||
public abstract string RenderService(string name, string module, List<DefTable> tables);
|
public abstract string RenderService(string name, string module, List<DefTable> tables);
|
||||||
|
|
||||||
public string RenderAny(object o)
|
public string RenderAny(DefTypeBase o)
|
||||||
{
|
{
|
||||||
switch (o)
|
switch (o)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.Generate
|
namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class CppBinCodeRender : CodeRenderBase
|
class CppCodeBinRender : CodeRenderBase
|
||||||
{
|
{
|
||||||
public override string Render(DefConst c)
|
public override string Render(DefConst c)
|
||||||
{
|
{
|
||||||
|
|
@ -5,7 +5,7 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.Generate
|
namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class CsBinCodeRender : CsCodeRenderBase
|
class CsCodeBinRender : CsCodeRenderBase
|
||||||
{
|
{
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
private static Template t_beanRender;
|
private static Template t_beanRender;
|
||||||
|
|
@ -5,7 +5,7 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.Generate
|
namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class CsJsonCodeRender : CsCodeRenderBase
|
class CsCodeJsonRender : CsCodeRenderBase
|
||||||
{
|
{
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
private static Template t_beanRender;
|
private static Template t_beanRender;
|
||||||
|
|
@ -233,7 +233,7 @@ public sealed partial class {{name}}
|
||||||
{
|
{
|
||||||
var tables = new System.Collections.Generic.Dictionary<string, object>();
|
var tables = new System.Collections.Generic.Dictionary<string, object>();
|
||||||
{{~for table in tables ~}}
|
{{~for table in tables ~}}
|
||||||
{{table.name}} = new {{table.full_name}}(loader(""{{table.json_output_data_file}}""));
|
{{table.name}} = new {{table.full_name}}(loader(""{{table.output_data_file}}""));
|
||||||
tables.Add(""{{table.full_name}}"", {{table.name}});
|
tables.Add(""{{table.full_name}}"", {{table.name}});
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
|
|
||||||
|
|
@ -5,43 +5,31 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.Generate
|
namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class EditorCppRender
|
class EditorCppRender : CodeRenderBase
|
||||||
{
|
{
|
||||||
public string RenderAny(object o)
|
public override string Render(DefConst c)
|
||||||
{
|
|
||||||
switch (o)
|
|
||||||
{
|
|
||||||
case DefConst c: return Render(c);
|
|
||||||
case DefEnum e: return Render(e);
|
|
||||||
case DefBean b: return Render(b);
|
|
||||||
case DefTable r: return Render(r);
|
|
||||||
default: throw new Exception($"unknown render type:{o}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Render(DefConst c)
|
|
||||||
{
|
{
|
||||||
return "// const";
|
return "// const";
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Render(DefEnum e)
|
public override string Render(DefEnum e)
|
||||||
{
|
{
|
||||||
return "// enum";
|
return "// enum";
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Render(DefBean b)
|
public override string Render(DefBean b)
|
||||||
{
|
{
|
||||||
return "// bean";
|
return "// bean";
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Render(DefTable p)
|
public override string Render(DefTable p)
|
||||||
{
|
{
|
||||||
return "// table";
|
return "// table";
|
||||||
}
|
}
|
||||||
|
|
||||||
public string RenderStubs(string name, string module, List<CfgDefTypeBase> protos)
|
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||||
{
|
{
|
||||||
return "// stubs";
|
return "// service";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,33 +8,21 @@ using System.Linq;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.Generate
|
namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class EditorCsRender
|
class EditorCsRender : CodeRenderBase
|
||||||
{
|
{
|
||||||
public string RenderAny(object o)
|
public override string Render(DefConst c)
|
||||||
{
|
|
||||||
switch (o)
|
|
||||||
{
|
|
||||||
case DefConst c: return Render(c);
|
|
||||||
case DefEnum e: return Render(e);
|
|
||||||
// case DefBean b: return Render(b); editor 不需要生成 table 的定义
|
|
||||||
// case CTable r: return Render(r);
|
|
||||||
default: throw new Exception($"unknown render type:{o}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Render(DefConst c)
|
|
||||||
{
|
{
|
||||||
return RenderUtil.RenderCsConstClass(c);
|
return RenderUtil.RenderCsConstClass(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Render(DefEnum e)
|
public override string Render(DefEnum e)
|
||||||
{
|
{
|
||||||
return RenderUtil.RenderCsEnumClass(e);
|
return RenderUtil.RenderCsEnumClass(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
private static Template t_beanRender;
|
private static Template t_beanRender;
|
||||||
public string Render(DefBean b)
|
public override string Render(DefBean b)
|
||||||
{
|
{
|
||||||
var template = t_beanRender ??= Template.Parse(@"
|
var template = t_beanRender ??= Template.Parse(@"
|
||||||
using Bright.Serialization;
|
using Bright.Serialization;
|
||||||
|
|
@ -136,7 +124,7 @@ public {{cs_class_modifier}} class {{name}} : {{if parent_def_type}} {{parent}}
|
||||||
|
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
private static Template t_tableRender;
|
private static Template t_tableRender;
|
||||||
public string Render(DefTable p)
|
public override string Render(DefTable p)
|
||||||
{
|
{
|
||||||
var template = t_tableRender ??= Template.Parse(@"
|
var template = t_tableRender ??= Template.Parse(@"
|
||||||
using Bright.Serialization;
|
using Bright.Serialization;
|
||||||
|
|
@ -211,7 +199,7 @@ public sealed class {{name}} : Bright.Net.Protocol
|
||||||
|
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
private static Template t_stubRender;
|
private static Template t_stubRender;
|
||||||
public string RenderStubs(string name, string module, List<CfgDefTypeBase> protos)
|
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||||
{
|
{
|
||||||
var template = t_stubRender ??= Template.Parse(@"
|
var template = t_stubRender ??= Template.Parse(@"
|
||||||
using Bright.Serialization;
|
using Bright.Serialization;
|
||||||
|
|
@ -236,7 +224,7 @@ public static class {{name}}
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
Namespace = module,
|
Namespace = module,
|
||||||
Tables = protos.Where(p => p is DefTable).ToList(),
|
Tables = tables,
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.Generate
|
namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class GoBinCodeRender : GoCodeRenderBase
|
class GoCodeBinRender : GoCodeRenderBase
|
||||||
{
|
{
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
private static Template t_beanRender;
|
private static Template t_beanRender;
|
||||||
protected override string Render(DefBean b)
|
public override string Render(DefBean b)
|
||||||
{
|
{
|
||||||
string package = "cfg";
|
string package = "cfg";
|
||||||
|
|
||||||
|
|
@ -27,12 +27,9 @@ package {{package}}
|
||||||
|
|
||||||
import (
|
import (
|
||||||
""bright/serialization""
|
""bright/serialization""
|
||||||
{{~if is_abstract_type~}}
|
|
||||||
""errors""
|
|
||||||
{{~end~}}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
{{x.go_import}}
|
{{x.go_bin_import}}
|
||||||
|
|
||||||
type {{go_full_name}} struct {
|
type {{go_full_name}} struct {
|
||||||
{{~if parent_def_type~}}
|
{{~if parent_def_type~}}
|
||||||
|
|
@ -49,20 +46,8 @@ func ({{go_full_name}}) GetTypeId() int {
|
||||||
}
|
}
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
|
|
||||||
func New{{go_full_name}}(_buf *serialization.ByteBuf) (_v *{{go_full_name}}, err error) {
|
|
||||||
_v = &{{go_full_name}}{}
|
|
||||||
{{~if parent_def_type~}}
|
|
||||||
var _p *{{parent_def_type.go_full_name}}
|
|
||||||
if _p, err = New{{parent_def_type.go_full_name}}(_buf) ; err != nil { return }
|
|
||||||
_v.{{parent_def_type.go_full_name}} = *_p
|
|
||||||
{{~end~}}
|
|
||||||
{{~for field in export_fields ~}}
|
|
||||||
{{go_deserialize_field field.ctype (""_v."" + field.go_style_name) '_buf'}}
|
|
||||||
{{~end~}}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
{{~if is_abstract_type~}}
|
{{~if is_abstract_type~}}
|
||||||
func NewChild{{go_full_name}}(_buf *serialization.ByteBuf) (_v interface{}, err error) {
|
func New{{go_full_name}}(_buf *serialization.ByteBuf) (_v interface{}, err error) {
|
||||||
var id int32
|
var id int32
|
||||||
if id, err = _buf.ReadInt() ; err != nil {
|
if id, err = _buf.ReadInt() ; err != nil {
|
||||||
return
|
return
|
||||||
|
|
@ -75,6 +60,33 @@ func NewChild{{go_full_name}}(_buf *serialization.ByteBuf) (_v interface{}, err
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func New{{go_full_name}}_Body(_buf *serialization.ByteBuf) (_v *{{go_full_name}}, err error) {
|
||||||
|
_v = &{{go_full_name}}{}
|
||||||
|
{{~if parent_def_type~}}
|
||||||
|
var _p *{{parent_def_type.go_full_name}}
|
||||||
|
if _p, err = New{{parent_def_type.go_full_name}}_Body(_buf) ; err != nil { return }
|
||||||
|
_v.{{parent_def_type.go_full_name}} = *_p
|
||||||
|
{{~end~}}
|
||||||
|
{{~for field in export_fields ~}}
|
||||||
|
{{go_deserialize_field field.ctype (""_v."" + field.go_style_name) '_buf'}}
|
||||||
|
{{~end~}}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
{{~else~}}
|
||||||
|
func New{{go_full_name}}(_buf *serialization.ByteBuf) (_v *{{go_full_name}}, err error) {
|
||||||
|
_v = &{{go_full_name}}{}
|
||||||
|
{{~if parent_def_type~}}
|
||||||
|
var _p *{{parent_def_type.go_full_name}}
|
||||||
|
if _p, err = New{{parent_def_type.go_full_name}}_Body(_buf) ; err != nil { return }
|
||||||
|
_v.{{parent_def_type.go_full_name}} = *_p
|
||||||
|
{{~end~}}
|
||||||
|
{{~for field in export_fields ~}}
|
||||||
|
{{go_deserialize_field field.ctype (""_v."" + field.go_style_name) '_buf'}}
|
||||||
|
{{~end~}}
|
||||||
|
return
|
||||||
|
}
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
|
|
||||||
");
|
");
|
||||||
|
|
@ -85,7 +97,7 @@ func NewChild{{go_full_name}}(_buf *serialization.ByteBuf) (_v interface{}, err
|
||||||
|
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
private static Template t_tableRender;
|
private static Template t_tableRender;
|
||||||
protected override string Render(DefTable p)
|
public override string Render(DefTable p)
|
||||||
{
|
{
|
||||||
// TODO 目前只有普通表支持多态. 单例表和双key表都不支持
|
// TODO 目前只有普通表支持多态. 单例表和双key表都不支持
|
||||||
string package = "cfg";
|
string package = "cfg";
|
||||||
|
|
@ -6,11 +6,11 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.Generate
|
namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class GoJsonCodeRender : GoCodeRenderBase
|
class GoCodeJsonRender : GoCodeRenderBase
|
||||||
{
|
{
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
private static Template t_beanRender;
|
private static Template t_beanRender;
|
||||||
protected override string Render(DefBean b)
|
public override string Render(DefBean b)
|
||||||
{
|
{
|
||||||
string package = "cfg";
|
string package = "cfg";
|
||||||
|
|
||||||
|
|
@ -25,7 +25,7 @@ namespace Luban.Job.Cfg.Generate
|
||||||
|
|
||||||
package {{package}}
|
package {{package}}
|
||||||
|
|
||||||
{{x.go_import}}
|
{{x.go_json_import}}
|
||||||
|
|
||||||
type {{go_full_name}} struct {
|
type {{go_full_name}} struct {
|
||||||
{{~if parent_def_type~}}
|
{{~if parent_def_type~}}
|
||||||
|
|
@ -42,20 +42,8 @@ func ({{go_full_name}}) GetTypeId() int {
|
||||||
}
|
}
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
|
|
||||||
func New{{go_full_name}}(_buf map[string]interface{}) (_v *{{go_full_name}}, err error) {
|
|
||||||
_v = &{{go_full_name}}{}
|
|
||||||
{{~if parent_def_type~}}
|
|
||||||
var _p *{{parent_def_type.go_full_name}}
|
|
||||||
if _p, err = New{{parent_def_type.go_full_name}}(_buf) ; err != nil { return }
|
|
||||||
_v.{{parent_def_type.go_full_name}} = *_p
|
|
||||||
{{~end~}}
|
|
||||||
{{~for field in export_fields ~}}
|
|
||||||
{{go_deserialize_json_field field.ctype (""_v."" + field.go_style_name) field.name '_buf'}}
|
|
||||||
{{~end~}}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
{{~if is_abstract_type~}}
|
{{~if is_abstract_type~}}
|
||||||
func NewChild{{go_full_name}}(_buf map[string]interface{}) (_v interface{}, err error) {
|
func New{{go_full_name}}(_buf map[string]interface{}) (_v interface{}, err error) {
|
||||||
var id string
|
var id string
|
||||||
var _ok_ bool
|
var _ok_ bool
|
||||||
if id, _ok_ = _buf[""__type__""].(string) ; !_ok_ {
|
if id, _ok_ = _buf[""__type__""].(string) ; !_ok_ {
|
||||||
|
|
@ -69,6 +57,32 @@ func NewChild{{go_full_name}}(_buf map[string]interface{}) (_v interface{}, err
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func New{{go_full_name}}_Body(_buf map[string]interface{}) (_v *{{go_full_name}}, err error) {
|
||||||
|
_v = &{{go_full_name}}{}
|
||||||
|
{{~if parent_def_type~}}
|
||||||
|
var _p *{{parent_def_type.go_full_name}}
|
||||||
|
if _p, err = New{{parent_def_type.go_full_name}}_Body(_buf) ; err != nil { return }
|
||||||
|
_v.{{parent_def_type.go_full_name}} = *_p
|
||||||
|
{{~end~}}
|
||||||
|
{{~for field in export_fields ~}}
|
||||||
|
{{go_deserialize_json_field field.ctype (""_v."" + field.go_style_name) field.name '_buf'}}
|
||||||
|
{{~end~}}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
{{~else~}}
|
||||||
|
func New{{go_full_name}}(_buf map[string]interface{}) (_v *{{go_full_name}}, err error) {
|
||||||
|
_v = &{{go_full_name}}{}
|
||||||
|
{{~if parent_def_type~}}
|
||||||
|
var _p *{{parent_def_type.go_full_name}}
|
||||||
|
if _p, err = New{{parent_def_type.go_full_name}}_Body(_buf) ; err != nil { return }
|
||||||
|
_v.{{parent_def_type.go_full_name}} = *_p
|
||||||
|
{{~end~}}
|
||||||
|
{{~for field in export_fields ~}}
|
||||||
|
{{go_deserialize_json_field field.ctype (""_v."" + field.go_style_name) field.name '_buf'}}
|
||||||
|
{{~end~}}
|
||||||
|
return
|
||||||
|
}
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
|
|
||||||
");
|
");
|
||||||
|
|
@ -79,7 +93,7 @@ func NewChild{{go_full_name}}(_buf map[string]interface{}) (_v interface{}, err
|
||||||
|
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
private static Template t_tableRender;
|
private static Template t_tableRender;
|
||||||
protected override string Render(DefTable p)
|
public override string Render(DefTable p)
|
||||||
{
|
{
|
||||||
// TODO 目前只有普通表支持多态. 单例表和双key表都不支持
|
// TODO 目前只有普通表支持多态. 单例表和双key表都不支持
|
||||||
string package = "cfg";
|
string package = "cfg";
|
||||||
|
|
@ -194,7 +208,7 @@ func NewTables(loader JsonLoader) (*{{name}}, error) {
|
||||||
|
|
||||||
tables := &{{name}}{}
|
tables := &{{name}}{}
|
||||||
{{~for table in tables ~}}
|
{{~for table in tables ~}}
|
||||||
if buf, err = loader(""{{table.json_output_data_file}}"") ; err != nil {
|
if buf, err = loader(""{{table.output_data_file}}"") ; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if tables.{{table.name}}, err = New{{table.go_full_name}}(buf) ; err != nil {
|
if tables.{{table.name}}, err = New{{table.go_full_name}}(buf) ; err != nil {
|
||||||
|
|
@ -9,24 +9,12 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.Generate
|
namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
abstract class GoCodeRenderBase
|
abstract class GoCodeRenderBase : CodeRenderBase
|
||||||
{
|
{
|
||||||
public string RenderAny(object o)
|
|
||||||
{
|
|
||||||
switch (o)
|
|
||||||
{
|
|
||||||
case DefConst c: return Render(c);
|
|
||||||
case DefEnum e: return Render(e);
|
|
||||||
case DefBean b: return Render(b);
|
|
||||||
case DefTable r: return Render(r);
|
|
||||||
default: throw new Exception($"unknown render type:{o}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
private static Template t_constRender;
|
private static Template t_constRender;
|
||||||
|
|
||||||
private string Render(DefConst c)
|
public override string Render(DefConst c)
|
||||||
{
|
{
|
||||||
string package = "cfg";
|
string package = "cfg";
|
||||||
|
|
||||||
|
|
@ -48,7 +36,7 @@ const (
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
private static Template t_enumRender;
|
private static Template t_enumRender;
|
||||||
|
|
||||||
private string Render(DefEnum e)
|
public override string Render(DefEnum e)
|
||||||
{
|
{
|
||||||
string package = "cfg";
|
string package = "cfg";
|
||||||
|
|
||||||
|
|
@ -68,11 +56,5 @@ const (
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected abstract string Render(DefBean b);
|
|
||||||
|
|
||||||
protected abstract string Render(DefTable p);
|
|
||||||
|
|
||||||
public abstract string RenderService(string name, string module, List<DefTable> tables);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
using Luban.Job.Cfg.Defs;
|
||||||
|
using Luban.Job.Common.Defs;
|
||||||
|
using Luban.Job.Common.Generate;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Luban.Job.Cfg.Generate
|
||||||
|
{
|
||||||
|
interface ICfgCodeRender : ICodeRender<DefTable>
|
||||||
|
{
|
||||||
|
string Render(DefBean b);
|
||||||
|
|
||||||
|
string Render(DefTable c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
using Luban.Job.Cfg.Defs;
|
|
||||||
using Luban.Job.Common.Defs;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.Generate
|
|
||||||
{
|
|
||||||
interface ICodeRender
|
|
||||||
{
|
|
||||||
string RenderAny(object o);
|
|
||||||
|
|
||||||
string Render(DefConst c);
|
|
||||||
|
|
||||||
string Render(DefEnum c);
|
|
||||||
|
|
||||||
string Render(DefBean b);
|
|
||||||
|
|
||||||
string Render(DefTable c);
|
|
||||||
|
|
||||||
string RenderService(string name, string module, List<DefTable> tables);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -7,18 +7,8 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.Generate
|
namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class JavaBinCodeRender : CodeRenderBase
|
class JavaCodeBinRender : JavaCodeRenderBase
|
||||||
{
|
{
|
||||||
public override string Render(DefConst c)
|
|
||||||
{
|
|
||||||
return RenderUtil.RenderJavaConstClass(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string Render(DefEnum c)
|
|
||||||
{
|
|
||||||
return RenderUtil.RenderJavaEnumClass(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
private static Template t_beanRender;
|
private static Template t_beanRender;
|
||||||
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
using Luban.Job.Cfg.Defs;
|
||||||
|
using Luban.Job.Common.Defs;
|
||||||
|
using Luban.Job.Common.Utils;
|
||||||
|
using Scriban;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Luban.Job.Cfg.Generate
|
||||||
|
{
|
||||||
|
abstract class JavaCodeRenderBase : CodeRenderBase
|
||||||
|
{
|
||||||
|
public override string Render(DefConst c)
|
||||||
|
{
|
||||||
|
return RenderUtil.RenderJavaConstClass(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Render(DefEnum c)
|
||||||
|
{
|
||||||
|
return RenderUtil.RenderJavaEnumClass(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,53 +1,24 @@
|
||||||
using Luban.Job.Cfg.Defs;
|
using Luban.Job.Cfg.Defs;
|
||||||
using Luban.Job.Common.Defs;
|
using Luban.Job.Common.Defs;
|
||||||
|
using Luban.Job.Common.Utils;
|
||||||
using Scriban;
|
using Scriban;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.Generate
|
namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class LuaRender
|
class LuaCodeBinRender : LuaCodeRenderBase
|
||||||
{
|
{
|
||||||
|
[ThreadStatic]
|
||||||
public string RenderAll(List<DefTypeBase> types)
|
private static Template t_allRender;
|
||||||
|
public override string RenderAll(List<DefTypeBase> types)
|
||||||
{
|
{
|
||||||
var consts = types.Where(t => t is DefConst).ToList();
|
var consts = types.Where(t => t is DefConst).ToList();
|
||||||
var enums = types.Where(t => t is DefEnum).ToList();
|
var enums = types.Where(t => t is DefEnum).ToList();
|
||||||
var beans = types.Where(t => t is DefBean).ToList();
|
var beans = types.Where(t => t is DefBean).ToList();
|
||||||
var tables = types.Where(t => t is DefTable).ToList();
|
var tables = types.Where(t => t is DefTable).ToList();
|
||||||
var template = Template.Parse(@"
|
var template = t_allRender ??= Template.Parse(LuaStringTemplate.BaseDefines + @"
|
||||||
{{
|
|
||||||
consts = x.consts
|
|
||||||
enums = x.enums
|
|
||||||
beans = x.beans
|
|
||||||
tables = x.tables
|
|
||||||
}}
|
|
||||||
local setmetatable = setmetatable
|
|
||||||
local pairs = pairs
|
|
||||||
local ipairs = ipairs
|
|
||||||
local tinsert = table.insert
|
|
||||||
|
|
||||||
local function SimpleClass()
|
|
||||||
local class = {}
|
|
||||||
class.__index = class
|
|
||||||
class.New = function(...)
|
|
||||||
local ctor = class.ctor
|
|
||||||
local o = ctor and ctor(...) or {}
|
|
||||||
setmetatable(o, class)
|
|
||||||
return o
|
|
||||||
end
|
|
||||||
return class
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function get_map_size(m)
|
|
||||||
local n = 0
|
|
||||||
for _ in pairs(m) do
|
|
||||||
n = n + 1
|
|
||||||
end
|
|
||||||
return n
|
|
||||||
end
|
|
||||||
|
|
||||||
local consts =
|
local consts =
|
||||||
{
|
{
|
||||||
{{~ for c in consts ~}}
|
{{~ for c in consts ~}}
|
||||||
|
|
@ -185,74 +156,6 @@ local function InitTypes(methods)
|
||||||
return { InitTypes = InitTypes }
|
return { InitTypes = InitTypes }
|
||||||
|
|
||||||
|
|
||||||
");
|
|
||||||
return template.RenderCode(new { Consts = consts, Enums = enums, Beans = beans, Tables = tables });
|
|
||||||
}
|
|
||||||
|
|
||||||
public string RenderDefines(List<DefTypeBase> types)
|
|
||||||
{
|
|
||||||
var consts = types.Where(t => t is DefConst).ToList();
|
|
||||||
var enums = types.Where(t => t is DefEnum).ToList();
|
|
||||||
var beans = types.Where(t => t is DefBean).ToList();
|
|
||||||
var tables = types.Where(t => t is DefTable).ToList();
|
|
||||||
var template = Template.Parse(@"
|
|
||||||
{{
|
|
||||||
consts = x.consts
|
|
||||||
enums = x.enums
|
|
||||||
beans = x.beans
|
|
||||||
tables = x.tables
|
|
||||||
}}
|
|
||||||
|
|
||||||
local consts =
|
|
||||||
{
|
|
||||||
{{~ for c in consts ~}}
|
|
||||||
---@class {{c.full_name}}
|
|
||||||
{{~ for item in c.items ~}}
|
|
||||||
---@field public {{item.name}} {{item.type}}
|
|
||||||
{{~end~}}
|
|
||||||
['{{c.full_name}}'] = { {{ for item in c.items }} {{item.name}}={{lua_const_value item.ctype item.value}}, {{end}} };
|
|
||||||
{{~end~}}
|
|
||||||
}
|
|
||||||
|
|
||||||
local enums =
|
|
||||||
{
|
|
||||||
{{~ for c in enums ~}}
|
|
||||||
---@class {{c.full_name}}
|
|
||||||
{{~ for item in c.items ~}}
|
|
||||||
---@field public {{item.name}} int
|
|
||||||
{{~end~}}
|
|
||||||
['{{c.full_name}}'] = { {{ for item in c.items }} {{item.name}}={{item.int_value}}, {{end}} };
|
|
||||||
{{~end~}}
|
|
||||||
}
|
|
||||||
|
|
||||||
local beans = {}
|
|
||||||
{{~ for bean in beans ~}}
|
|
||||||
---@class {{bean.full_name}} {{if bean.parent_def_type}}:{{bean.parent}} {{end}}
|
|
||||||
{{~ for field in bean.export_fields~}}
|
|
||||||
---@field public {{field.name}} {{lua_comment_type field.ctype}}
|
|
||||||
{{~end~}}
|
|
||||||
beans['{{bean.full_name}}'] =
|
|
||||||
{
|
|
||||||
{{~ for field in bean.hierarchy_export_fields ~}}
|
|
||||||
{ name='{{field.name}}', type='{{lua_comment_type field.ctype}}'},
|
|
||||||
{{~end~}}
|
|
||||||
}
|
|
||||||
|
|
||||||
{{~end~}}
|
|
||||||
|
|
||||||
local tables =
|
|
||||||
{
|
|
||||||
{{~for table in tables ~}}
|
|
||||||
{{~if table.is_map_table ~}}
|
|
||||||
{ name='{{table.name}}', file='{{table.output_data_file}}', mode='map', index='{{table.index}}', value_type='{{table.value_ttype.bean.full_name}}' },
|
|
||||||
{{~else~}}
|
|
||||||
{ name='{{table.name}}', file='{{table.output_data_file}}', mode='one', value_type='{{table.value_ttype.bean.full_name}}'},
|
|
||||||
{{end}}
|
|
||||||
{{~end~}}
|
|
||||||
}
|
|
||||||
|
|
||||||
return { consts = consts, enums = enums, beans = beans, tables = tables }
|
|
||||||
|
|
||||||
");
|
");
|
||||||
return template.RenderCode(new { Consts = consts, Enums = enums, Beans = beans, Tables = tables });
|
return template.RenderCode(new { Consts = consts, Enums = enums, Beans = beans, Tables = tables });
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,77 @@
|
||||||
|
using Luban.Job.Cfg.Defs;
|
||||||
|
using Luban.Job.Common.Defs;
|
||||||
|
using Luban.Job.Common.Utils;
|
||||||
|
using Scriban;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Luban.Job.Cfg.Generate
|
||||||
|
{
|
||||||
|
class LuaCodeLuaRender : LuaCodeRenderBase
|
||||||
|
{
|
||||||
|
[ThreadStatic]
|
||||||
|
private static Template t_allRender;
|
||||||
|
|
||||||
|
public override string RenderAll(List<DefTypeBase> types)
|
||||||
|
{
|
||||||
|
var consts = types.Where(t => t is DefConst).ToList();
|
||||||
|
var enums = types.Where(t => t is DefEnum).ToList();
|
||||||
|
var beans = types.Where(t => t is DefBean).ToList();
|
||||||
|
var tables = types.Where(t => t is DefTable).ToList();
|
||||||
|
var template = t_allRender ??= Template.Parse(LuaStringTemplate.BaseDefines + @"
|
||||||
|
local consts =
|
||||||
|
{
|
||||||
|
{{~ for c in consts ~}}
|
||||||
|
---@class {{c.full_name}}
|
||||||
|
{{~ for item in c.items ~}}
|
||||||
|
---@field public {{item.name}} {{item.type}}
|
||||||
|
{{~end~}}
|
||||||
|
['{{c.full_name}}'] = { {{ for item in c.items }} {{item.name}}={{lua_const_value item.ctype item.value}}, {{end}} };
|
||||||
|
{{~end~}}
|
||||||
|
}
|
||||||
|
|
||||||
|
local enums =
|
||||||
|
{
|
||||||
|
{{~ for c in enums ~}}
|
||||||
|
---@class {{c.full_name}}
|
||||||
|
{{~ for item in c.items ~}}
|
||||||
|
---@field public {{item.name}} int
|
||||||
|
{{~end~}}
|
||||||
|
['{{c.full_name}}'] = { {{ for item in c.items }} {{item.name}}={{item.int_value}}, {{end}} };
|
||||||
|
{{~end~}}
|
||||||
|
}
|
||||||
|
|
||||||
|
local beans = {}
|
||||||
|
{{~ for bean in beans ~}}
|
||||||
|
---@class {{bean.full_name}} {{if bean.parent_def_type}}:{{bean.parent}} {{end}}
|
||||||
|
{{~ for field in bean.export_fields~}}
|
||||||
|
---@field public {{field.name}} {{lua_comment_type field.ctype}}
|
||||||
|
{{~end~}}
|
||||||
|
beans['{{bean.full_name}}'] =
|
||||||
|
{
|
||||||
|
{{~ for field in bean.hierarchy_export_fields ~}}
|
||||||
|
{ name='{{field.name}}', type='{{lua_comment_type field.ctype}}'},
|
||||||
|
{{~end~}}
|
||||||
|
}
|
||||||
|
|
||||||
|
{{~end~}}
|
||||||
|
|
||||||
|
local tables =
|
||||||
|
{
|
||||||
|
{{~for table in tables ~}}
|
||||||
|
{{~if table.is_map_table ~}}
|
||||||
|
{ name='{{table.name}}', file='{{table.output_data_file_escape_dot}}', mode='map', index='{{table.index}}', value_type='{{table.value_ttype.bean.full_name}}' },
|
||||||
|
{{~else~}}
|
||||||
|
{ name='{{table.name}}', file='{{table.output_data_file_escape_dot}}', mode='one', value_type='{{table.value_ttype.bean.full_name}}'},
|
||||||
|
{{end}}
|
||||||
|
{{~end~}}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { consts = consts, enums = enums, beans = beans, tables = tables }
|
||||||
|
|
||||||
|
");
|
||||||
|
return template.RenderCode(new { Consts = consts, Enums = enums, Beans = beans, Tables = tables });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
using Luban.Job.Cfg.Defs;
|
||||||
|
using Luban.Job.Common.Defs;
|
||||||
|
using Scriban;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Luban.Job.Cfg.Generate
|
||||||
|
{
|
||||||
|
abstract class LuaCodeRenderBase : CodeRenderBase
|
||||||
|
{
|
||||||
|
|
||||||
|
public override string Render(DefConst c)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Render(DefEnum e)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Render(DefTable c)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Render(DefBean b)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract string RenderAll(List<DefTypeBase> types);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -6,53 +6,8 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.Generate
|
namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class Python27JsonCodeRender : CodeRenderBase
|
class Python27CodeJsonRender : PythonCodeRenderBase
|
||||||
{
|
{
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_tsConstRender;
|
|
||||||
public override string Render(DefConst c)
|
|
||||||
{
|
|
||||||
var ctx = new TemplateContext();
|
|
||||||
var env = new TTypeTemplateCommonExtends
|
|
||||||
{
|
|
||||||
["x"] = c
|
|
||||||
};
|
|
||||||
ctx.PushGlobal(env);
|
|
||||||
|
|
||||||
|
|
||||||
var template = t_tsConstRender ??= Template.Parse(@"
|
|
||||||
|
|
||||||
class {{x.py_full_name}}:
|
|
||||||
{{~ for item in x.items ~}}
|
|
||||||
{{item.name}} = {{py_const_value item.ctype item.value}}
|
|
||||||
{{~end~}}
|
|
||||||
{{~if (x.items == empty)~}}
|
|
||||||
pass
|
|
||||||
{{~end~}}
|
|
||||||
|
|
||||||
");
|
|
||||||
var result = template.Render(ctx);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_tsEnumRender;
|
|
||||||
public override string Render(DefEnum e)
|
|
||||||
{
|
|
||||||
var template = t_tsEnumRender ??= Template.Parse(@"
|
|
||||||
class {{py_full_name}}:
|
|
||||||
{{~ for item in items ~}}
|
|
||||||
{{item.name}} = {{item.value}}
|
|
||||||
{{~end~}}
|
|
||||||
{{~if (items == empty)~}}
|
|
||||||
pass
|
|
||||||
{{~end~}}
|
|
||||||
");
|
|
||||||
var result = template.Render(e);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
private static Template t_beanRender;
|
private static Template t_beanRender;
|
||||||
|
|
@ -155,37 +110,5 @@ class {{name}}:
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_serviceRender;
|
|
||||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
|
||||||
{
|
|
||||||
var template = t_serviceRender ??= Template.Parse(@"
|
|
||||||
{{
|
|
||||||
name = x.name
|
|
||||||
namespace = x.namespace
|
|
||||||
tables = x.tables
|
|
||||||
}}
|
|
||||||
|
|
||||||
class {{name}}:
|
|
||||||
{{~ for table in tables ~}}
|
|
||||||
#def {{table.name}} : return self._{{table.name}}
|
|
||||||
{{~end~}}
|
|
||||||
|
|
||||||
def __init__(self, loader):
|
|
||||||
{{~for table in tables ~}}
|
|
||||||
self.{{table.name}} = {{table.py_full_name}}(loader('{{table.json_output_data_file}}'));
|
|
||||||
{{~end~}}
|
|
||||||
|
|
||||||
");
|
|
||||||
var result = template.RenderCode(new
|
|
||||||
{
|
|
||||||
Name = name,
|
|
||||||
Namespace = module,
|
|
||||||
Tables = tables,
|
|
||||||
});
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,54 +6,8 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.Generate
|
namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class Python3JsonCodeRender : CodeRenderBase
|
class Python3CodeJsonRender : PythonCodeRenderBase
|
||||||
{
|
{
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_tsConstRender;
|
|
||||||
public override string Render(DefConst c)
|
|
||||||
{
|
|
||||||
var ctx = new TemplateContext();
|
|
||||||
var env = new TTypeTemplateCommonExtends
|
|
||||||
{
|
|
||||||
["x"] = c
|
|
||||||
};
|
|
||||||
ctx.PushGlobal(env);
|
|
||||||
|
|
||||||
|
|
||||||
var template = t_tsConstRender ??= Template.Parse(@"
|
|
||||||
|
|
||||||
class {{x.py_full_name}}:
|
|
||||||
{{~ for item in x.items ~}}
|
|
||||||
{{item.name}} = {{py_const_value item.ctype item.value}}
|
|
||||||
{{~end~}}
|
|
||||||
{{~if (x.items == empty)~}}
|
|
||||||
pass
|
|
||||||
{{~end~}}
|
|
||||||
|
|
||||||
");
|
|
||||||
var result = template.Render(ctx);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_tsEnumRender;
|
|
||||||
public override string Render(DefEnum e)
|
|
||||||
{
|
|
||||||
var template = t_tsEnumRender ??= Template.Parse(@"
|
|
||||||
class {{py_full_name}}(Enum):
|
|
||||||
{{~ for item in items ~}}
|
|
||||||
{{item.name}} = {{item.value}}
|
|
||||||
{{~end~}}
|
|
||||||
{{~if (items == empty)~}}
|
|
||||||
pass
|
|
||||||
{{~end~}}
|
|
||||||
");
|
|
||||||
var result = template.Render(e);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
private static Template t_beanRender;
|
private static Template t_beanRender;
|
||||||
public override string Render(DefBean b)
|
public override string Render(DefBean b)
|
||||||
|
|
@ -155,37 +109,5 @@ class {{name}}:
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_serviceRender;
|
|
||||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
|
||||||
{
|
|
||||||
var template = t_serviceRender ??= Template.Parse(@"
|
|
||||||
{{
|
|
||||||
name = x.name
|
|
||||||
namespace = x.namespace
|
|
||||||
tables = x.tables
|
|
||||||
}}
|
|
||||||
|
|
||||||
class {{name}}:
|
|
||||||
{{~ for table in tables ~}}
|
|
||||||
#def {{table.name}} : return self._{{table.name}}
|
|
||||||
{{~end~}}
|
|
||||||
|
|
||||||
def __init__(self, loader):
|
|
||||||
{{~for table in tables ~}}
|
|
||||||
self.{{table.name}} = {{table.py_full_name}}(loader('{{table.json_output_data_file}}'));
|
|
||||||
{{~end~}}
|
|
||||||
|
|
||||||
");
|
|
||||||
var result = template.RenderCode(new
|
|
||||||
{
|
|
||||||
Name = name,
|
|
||||||
Namespace = module,
|
|
||||||
Tables = tables,
|
|
||||||
});
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,89 @@
|
||||||
|
using Luban.Job.Cfg.Defs;
|
||||||
|
using Luban.Job.Common.Defs;
|
||||||
|
using Scriban;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Luban.Job.Cfg.Generate
|
||||||
|
{
|
||||||
|
abstract class PythonCodeRenderBase : CodeRenderBase
|
||||||
|
{
|
||||||
|
[ThreadStatic]
|
||||||
|
private static Template t_tsConstRender;
|
||||||
|
public override string Render(DefConst c)
|
||||||
|
{
|
||||||
|
var ctx = new TemplateContext();
|
||||||
|
var env = new TTypeTemplateCommonExtends
|
||||||
|
{
|
||||||
|
["x"] = c
|
||||||
|
};
|
||||||
|
ctx.PushGlobal(env);
|
||||||
|
|
||||||
|
|
||||||
|
var template = t_tsConstRender ??= Template.Parse(@"
|
||||||
|
|
||||||
|
class {{x.py_full_name}}:
|
||||||
|
{{~ for item in x.items ~}}
|
||||||
|
{{item.name}} = {{py_const_value item.ctype item.value}}
|
||||||
|
{{~end~}}
|
||||||
|
{{~if (x.items == empty)~}}
|
||||||
|
pass
|
||||||
|
{{~end~}}
|
||||||
|
|
||||||
|
");
|
||||||
|
var result = template.Render(ctx);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
[ThreadStatic]
|
||||||
|
private static Template t_tsEnumRender;
|
||||||
|
public override string Render(DefEnum e)
|
||||||
|
{
|
||||||
|
var template = t_tsEnumRender ??= Template.Parse(@"
|
||||||
|
class {{py_full_name}}:
|
||||||
|
{{~ for item in items ~}}
|
||||||
|
{{item.name}} = {{item.value}}
|
||||||
|
{{~end~}}
|
||||||
|
{{~if (items == empty)~}}
|
||||||
|
pass
|
||||||
|
{{~end~}}
|
||||||
|
");
|
||||||
|
var result = template.Render(e);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
[ThreadStatic]
|
||||||
|
private static Template t_serviceRender;
|
||||||
|
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||||
|
{
|
||||||
|
var template = t_serviceRender ??= Template.Parse(@"
|
||||||
|
{{
|
||||||
|
name = x.name
|
||||||
|
namespace = x.namespace
|
||||||
|
tables = x.tables
|
||||||
|
}}
|
||||||
|
|
||||||
|
class {{name}}:
|
||||||
|
{{~ for table in tables ~}}
|
||||||
|
#def {{table.name}} : return self._{{table.name}}
|
||||||
|
{{~end~}}
|
||||||
|
|
||||||
|
def __init__(self, loader):
|
||||||
|
{{~for table in tables ~}}
|
||||||
|
self.{{table.name}} = {{table.py_full_name}}(loader('{{table.output_data_file}}'));
|
||||||
|
{{~end~}}
|
||||||
|
|
||||||
|
");
|
||||||
|
var result = template.RenderCode(new
|
||||||
|
{
|
||||||
|
Name = name,
|
||||||
|
Namespace = module,
|
||||||
|
Tables = tables,
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,18 +7,8 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.Generate
|
namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class TypeScriptBinCodeRender : CodeRenderBase
|
class TypescriptCodeBinRender : TypescriptCodeRenderBase
|
||||||
{
|
{
|
||||||
public override string Render(DefConst c)
|
|
||||||
{
|
|
||||||
return RenderUtil.RenderTypescriptConstClass(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string Render(DefEnum e)
|
|
||||||
{
|
|
||||||
return RenderUtil.RenderTypescriptEnumClass(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
private static Template t_beanRender;
|
private static Template t_beanRender;
|
||||||
public override string Render(DefBean b)
|
public override string Render(DefBean b)
|
||||||
|
|
@ -7,18 +7,8 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.Generate
|
namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class TypeScriptJsonCodeRender : CodeRenderBase
|
class TypescriptCodeJsonRender : TypescriptCodeRenderBase
|
||||||
{
|
{
|
||||||
public override string Render(DefConst c)
|
|
||||||
{
|
|
||||||
return RenderUtil.RenderTypescriptConstClass(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string Render(DefEnum e)
|
|
||||||
{
|
|
||||||
return RenderUtil.RenderTypescriptEnumClass(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
private static Template t_beanRender;
|
private static Template t_beanRender;
|
||||||
public override string Render(DefBean b)
|
public override string Render(DefBean b)
|
||||||
|
|
@ -175,7 +165,7 @@ export class {{name}} {
|
||||||
constructor(loader: JsonLoader) {
|
constructor(loader: JsonLoader) {
|
||||||
let tables = new Map<string, any>()
|
let tables = new Map<string, any>()
|
||||||
{{~for table in tables ~}}
|
{{~for table in tables ~}}
|
||||||
this._{{table.name}} = new {{table.full_name}}(loader('{{table.json_output_data_file}}'))
|
this._{{table.name}} = new {{table.full_name}}(loader('{{table.output_data_file}}'))
|
||||||
tables.set('{{table.full_name}}', this._{{table.name}})
|
tables.set('{{table.full_name}}', this._{{table.name}})
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
using Luban.Job.Cfg.Defs;
|
||||||
|
using Luban.Job.Common.Defs;
|
||||||
|
using Luban.Job.Common.Utils;
|
||||||
|
using Scriban;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Luban.Job.Cfg.Generate
|
||||||
|
{
|
||||||
|
abstract class TypescriptCodeRenderBase : CodeRenderBase
|
||||||
|
{
|
||||||
|
public override string Render(DefConst c)
|
||||||
|
{
|
||||||
|
return RenderUtil.RenderTypescriptConstClass(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Render(DefEnum e)
|
||||||
|
{
|
||||||
|
return RenderUtil.RenderTypescriptEnumClass(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,25 +2,15 @@ using Luban.Job.Cfg.Defs;
|
||||||
using Luban.Job.Common.Defs;
|
using Luban.Job.Common.Defs;
|
||||||
using Scriban;
|
using Scriban;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.Generate
|
namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class UE4BpCppRender
|
class UE4BpCppRender : CodeRenderBase
|
||||||
{
|
{
|
||||||
public string RenderAny(object o)
|
|
||||||
{
|
|
||||||
switch (o)
|
|
||||||
{
|
|
||||||
case DefEnum e: return Render(e);
|
|
||||||
case DefBean b: return Render(b);
|
|
||||||
//case CTable r: return Render(r);
|
|
||||||
default: throw new Exception($"unknown render type:{o}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
private static Template t_enumRender;
|
private static Template t_enumRender;
|
||||||
public string Render(DefEnum e)
|
public override string Render(DefEnum e)
|
||||||
{
|
{
|
||||||
// ue 不允许 UEnum 为这
|
// ue 不允许 UEnum 为这
|
||||||
// ue 强制枚举underling type 为 uint8, 意味着不能超过255
|
// ue 强制枚举underling type 为 uint8, 意味着不能超过255
|
||||||
|
|
@ -53,7 +43,7 @@ enum class {{ue_bp_full_name}} : uint8
|
||||||
|
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
private static Template t_beanRender;
|
private static Template t_beanRender;
|
||||||
public string Render(DefBean b)
|
public override string Render(DefBean b)
|
||||||
{
|
{
|
||||||
var template = t_beanRender ??= Template.Parse(@"
|
var template = t_beanRender ??= Template.Parse(@"
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
@ -86,6 +76,19 @@ public:
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string Render(DefConst c)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Render(DefTable c)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,22 +6,11 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.Generate
|
namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class UE4EditorCppRender
|
class UE4EditorCppRender : CodeRenderBase
|
||||||
{
|
{
|
||||||
public string RenderAny(object o)
|
|
||||||
{
|
|
||||||
switch (o)
|
|
||||||
{
|
|
||||||
case DefEnum e: return Render(e);
|
|
||||||
case DefBean b: return Render(b);
|
|
||||||
//case CTable r: return Render(r);
|
|
||||||
default: throw new Exception($"unknown render type:{o}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
private static Template t_enumRender;
|
private static Template t_enumRender;
|
||||||
public string Render(DefEnum e)
|
public override string Render(DefEnum e)
|
||||||
{
|
{
|
||||||
var template = t_enumRender ??= Template.Parse(@"
|
var template = t_enumRender ??= Template.Parse(@"
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
@ -53,7 +42,7 @@ namespace editor
|
||||||
|
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
private static Template t_beanRender;
|
private static Template t_beanRender;
|
||||||
public string Render(DefBean b)
|
public override string Render(DefBean b)
|
||||||
{
|
{
|
||||||
var template = t_beanRender ??= Template.Parse(@"
|
var template = t_beanRender ??= Template.Parse(@"
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
@ -229,5 +218,20 @@ bool {{type.ue_fname}}FromString(const FString& s, {{type.ue_fname}}& value)
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string Render(DefConst c)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Render(DefTable c)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,52 @@
|
||||||
|
using Luban.Job.Common.Types;
|
||||||
|
using Luban.Job.Common.TypeVisitors;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Luban.Job.Cfg.TypeVisitors
|
||||||
|
{
|
||||||
|
class GoBinImport : DecoratorActionVisitor<HashSet<string>>
|
||||||
|
{
|
||||||
|
public static GoBinImport Ins { get; } = new();
|
||||||
|
|
||||||
|
public override void DoAccept(TType type, HashSet<string> x)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Accept(TArray type, HashSet<string> x)
|
||||||
|
{
|
||||||
|
type.ElementType.Apply(this, x);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Accept(TList type, HashSet<string> x)
|
||||||
|
{
|
||||||
|
type.ElementType.Apply(this, x);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Accept(TSet type, HashSet<string> x)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Accept(TMap type, HashSet<string> x)
|
||||||
|
{
|
||||||
|
type.KeyType.Apply(this, x);
|
||||||
|
type.ValueType.Apply(this, x);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Accept(TVector2 type, HashSet<string> x)
|
||||||
|
{
|
||||||
|
x.Add("bright/math");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Accept(TVector3 type, HashSet<string> x)
|
||||||
|
{
|
||||||
|
x.Add("bright/math");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Accept(TVector4 type, HashSet<string> x)
|
||||||
|
{
|
||||||
|
x.Add("bright/math");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,9 +3,9 @@ using Luban.Job.Common.TypeVisitors;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.TypeVisitors
|
namespace Luban.Job.Cfg.TypeVisitors
|
||||||
{
|
{
|
||||||
class GoDeserializeVisitor : DecoratorFuncVisitor<string, string, string>
|
class GoDeserializeBinVisitor : DecoratorFuncVisitor<string, string, string>
|
||||||
{
|
{
|
||||||
public static GoDeserializeVisitor Ins { get; } = new GoDeserializeVisitor();
|
public static GoDeserializeBinVisitor Ins { get; } = new GoDeserializeBinVisitor();
|
||||||
|
|
||||||
public override string DoAccept(TType type, string fieldName, string bufName)
|
public override string DoAccept(TType type, string fieldName, string bufName)
|
||||||
{
|
{
|
||||||
|
|
@ -91,7 +91,7 @@ namespace Luban.Job.Cfg.TypeVisitors
|
||||||
|
|
||||||
public string Accept(TBean type, string varName, string bufName)
|
public string Accept(TBean type, string varName, string bufName)
|
||||||
{
|
{
|
||||||
return $"{{ var _ok_ bool; var _x_ map[string]interface{{}}; if _x_, _ok_ = {bufName}.(map[string]interface{{}}); !_ok_ {{ err = errors.New(\"{varName} error\"); return }}; if {varName}, err = {(type.Bean.IsAbstractType ? $"NewChild{type.Bean.GoFullName}(_x_)" : $"New{ type.Bean.GoFullName} (_x_)")}; err != nil {{ return }} }}";
|
return $"{{ var _ok_ bool; var _x_ map[string]interface{{}}; if _x_, _ok_ = {bufName}.(map[string]interface{{}}); !_ok_ {{ err = errors.New(\"{varName} error\"); return }}; if {varName}, err = {($"New{ type.Bean.GoFullName}(_x_)")}; err != nil {{ return }} }}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Accept(TArray type, string varName, string bufName)
|
public string Accept(TArray type, string varName, string bufName)
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ namespace Luban.Job.Cfg.TypeVisitors
|
||||||
|
|
||||||
public string Accept(TBean type, string varName, string fieldName, string bufName)
|
public string Accept(TBean type, string varName, string fieldName, string bufName)
|
||||||
{
|
{
|
||||||
return $"{{ var _ok_ bool; var _x_ map[string]interface{{}}; if _x_, _ok_ = {bufName}[\"{fieldName}\"].(map[string]interface{{}}); !_ok_ {{ err = errors.New(\"{fieldName} error\"); return }}; if {varName}, err = {(type.Bean.IsAbstractType ? $"NewChild{type.Bean.GoFullName}(_x_)" : $"New{ type.Bean.GoFullName} (_x_)")}; err != nil {{ return }} }}";
|
return $"{{ var _ok_ bool; var _x_ map[string]interface{{}}; if _x_, _ok_ = {bufName}[\"{fieldName}\"].(map[string]interface{{}}); !_ok_ {{ err = errors.New(\"{fieldName} error\"); return }}; if {varName}, err = {($"New{ type.Bean.GoFullName}(_x_)")}; err != nil {{ return }} }}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,8 +79,7 @@ namespace Luban.Job.Cfg.TypeVisitors
|
||||||
|
|
||||||
public string Accept(TBean type, string fieldName, string bufName)
|
public string Accept(TBean type, string fieldName, string bufName)
|
||||||
{
|
{
|
||||||
return $"{{ if {fieldName}, err = {(type.Bean.IsAbstractType ? $"NewChild{type.Bean.GoFullName}({bufName})" : $"New{ type.Bean.GoFullName} ({ bufName})")}; err != nil {{ return }} }}";
|
return $"{{ if {fieldName}, err = {($"New{type.Bean.GoFullName}({bufName})")}; err != nil {{ return }} }}";
|
||||||
//return type.Bean.IsAbstractType ? $"NewChild{type.Bean.GoFullName}({bufName})" : $"New{ type.Bean.GoFullName} ({ bufName})";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -92,7 +91,7 @@ namespace Luban.Job.Cfg.TypeVisitors
|
||||||
if _n_, err = {bufName}.ReadSize(); err != nil {{return}}
|
if _n_, err = {bufName}.ReadSize(); err != nil {{return}}
|
||||||
for i := 0 ; i < _n_ ; i++ {{
|
for i := 0 ; i < _n_ ; i++ {{
|
||||||
var _e_ {elementType.Apply(GoTypeNameVisitor.Ins)}
|
var _e_ {elementType.Apply(GoTypeNameVisitor.Ins)}
|
||||||
{elementType.Apply(GoDeserializeVisitor.Ins, "_e_", bufName)}
|
{elementType.Apply(GoDeserializeBinVisitor.Ins, "_e_", bufName)}
|
||||||
{fieldName} = append({fieldName}, _e_)
|
{fieldName} = append({fieldName}, _e_)
|
||||||
}}
|
}}
|
||||||
}}
|
}}
|
||||||
|
|
@ -122,9 +121,9 @@ namespace Luban.Job.Cfg.TypeVisitors
|
||||||
if _n_, err = {bufName}.ReadSize(); err != nil {{return}}
|
if _n_, err = {bufName}.ReadSize(); err != nil {{return}}
|
||||||
for i := 0 ; i < _n_ ; i++ {{
|
for i := 0 ; i < _n_ ; i++ {{
|
||||||
var _key_ {type.KeyType.Apply(GoTypeNameVisitor.Ins)}
|
var _key_ {type.KeyType.Apply(GoTypeNameVisitor.Ins)}
|
||||||
{type.KeyType.Apply(GoDeserializeVisitor.Ins, "_key_", bufName)}
|
{type.KeyType.Apply(GoDeserializeBinVisitor.Ins, "_key_", bufName)}
|
||||||
var _value_ {type.ValueType.Apply(GoTypeNameVisitor.Ins)}
|
var _value_ {type.ValueType.Apply(GoTypeNameVisitor.Ins)}
|
||||||
{type.ValueType.Apply(GoDeserializeVisitor.Ins, "_value_", bufName)}
|
{type.ValueType.Apply(GoDeserializeBinVisitor.Ins, "_value_", bufName)}
|
||||||
{fieldName}[_key_] = _value_
|
{fieldName}[_key_] = _value_
|
||||||
}}
|
}}
|
||||||
}}";
|
}}";
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,9 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.TypeVisitors
|
namespace Luban.Job.Cfg.TypeVisitors
|
||||||
{
|
{
|
||||||
class CollectGoImport : DecoratorActionVisitor<HashSet<string>>
|
class GoJsonImport : DecoratorActionVisitor<HashSet<string>>
|
||||||
{
|
{
|
||||||
public static CollectGoImport Ins { get; } = new CollectGoImport();
|
public static GoJsonImport Ins { get; } = new();
|
||||||
|
|
||||||
public override void DoAccept(TType type, HashSet<string> x)
|
public override void DoAccept(TType type, HashSet<string> x)
|
||||||
{
|
{
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using Bright.Serialization;
|
using Bright.Serialization;
|
||||||
|
using Luban.Job.Cfg.DataExporters;
|
||||||
using Luban.Job.Cfg.Datas;
|
using Luban.Job.Cfg.Datas;
|
||||||
using Luban.Job.Cfg.DataVisitors;
|
using Luban.Job.Cfg.DataVisitors;
|
||||||
using Luban.Job.Cfg.Defs;
|
using Luban.Job.Cfg.Defs;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
using Luban.Job.Common.Defs;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Luban.Job.Common.Generate
|
||||||
|
{
|
||||||
|
public interface ICodeRender<T> where T : DefTypeBase
|
||||||
|
{
|
||||||
|
string RenderAny(DefTypeBase o);
|
||||||
|
|
||||||
|
string Render(DefConst c);
|
||||||
|
|
||||||
|
string Render(DefEnum c);
|
||||||
|
|
||||||
|
string RenderService(string name, string module, List<T> tables);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -16,6 +16,11 @@ namespace Luban.Job.Common.TypeVisitors
|
||||||
return type.Apply(CsUnderingDefineTypeName.Ins);
|
return type.Apply(CsUnderingDefineTypeName.Ins);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string Accept(TText type)
|
||||||
|
{
|
||||||
|
return type.Apply(CsUnderingDefineTypeName.Ins);
|
||||||
|
}
|
||||||
|
|
||||||
public override string Accept(TBean type)
|
public override string Accept(TBean type)
|
||||||
{
|
{
|
||||||
return type.Apply(CsUnderingDefineTypeName.Ins);
|
return type.Apply(CsUnderingDefineTypeName.Ins);
|
||||||
|
|
|
||||||
|
|
@ -42,5 +42,15 @@ namespace Luban.Job.Common.Utils
|
||||||
default: return AUTO_GENERATE_C_LIKE + txt;
|
default: return AUTO_GENERATE_C_LIKE + txt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetAutoGenerationHeader(ELanguage lan)
|
||||||
|
{
|
||||||
|
switch (lan)
|
||||||
|
{
|
||||||
|
case ELanguage.LUA: return AUTO_GENERATE_LUA;
|
||||||
|
case ELanguage.PYTHON: return AUTO_GENERATE_PYTHON;
|
||||||
|
default: return AUTO_GENERATE_C_LIKE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,107 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Luban.Job.Common.Utils
|
||||||
|
{
|
||||||
|
public static class LuaStringTemplate
|
||||||
|
{
|
||||||
|
public const string BaseDefines = @"
|
||||||
|
{{
|
||||||
|
consts = x.consts
|
||||||
|
enums = x.enums
|
||||||
|
beans = x.beans
|
||||||
|
tables = x.tables
|
||||||
|
}}
|
||||||
|
local setmetatable = setmetatable
|
||||||
|
local pairs = pairs
|
||||||
|
local ipairs = ipairs
|
||||||
|
local tinsert = table.insert
|
||||||
|
|
||||||
|
local function SimpleClass()
|
||||||
|
local class = {}
|
||||||
|
class.__index = class
|
||||||
|
class.New = function(...)
|
||||||
|
local ctor = class.ctor
|
||||||
|
local o = ctor and ctor(...) or {}
|
||||||
|
setmetatable(o, class)
|
||||||
|
return o
|
||||||
|
end
|
||||||
|
return class
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function get_map_size(m)
|
||||||
|
local n = 0
|
||||||
|
for _ in pairs(m) do
|
||||||
|
n = n + 1
|
||||||
|
end
|
||||||
|
return n
|
||||||
|
end";
|
||||||
|
|
||||||
|
public const string MethodHeader = @"local function InitTypes(methods)
|
||||||
|
local readBool = methods.readBool
|
||||||
|
local readByte = methods.readByte
|
||||||
|
local readShort = methods.readShort
|
||||||
|
local readFshort = methods.readFshort
|
||||||
|
local readInt = methods.readInt
|
||||||
|
local readFint = methods.readFint
|
||||||
|
local readLong = methods.readLong
|
||||||
|
local readFlong = methods.readFlong
|
||||||
|
local readFloat = methods.readFloat
|
||||||
|
local readDouble = methods.readDouble
|
||||||
|
local readSize = methods.readSize
|
||||||
|
|
||||||
|
local readString = methods.readString
|
||||||
|
|
||||||
|
local function readVector2(bs)
|
||||||
|
return { x = readFloat(bs), y = readFloat(bs) }
|
||||||
|
end
|
||||||
|
|
||||||
|
local function readVector3(bs)
|
||||||
|
return { x = readFloat(bs), y = readFloat(bs), z = readFloat(bs) }
|
||||||
|
end
|
||||||
|
|
||||||
|
local function readVector4(bs)
|
||||||
|
return { x = readFloat(bs), y = readFloat(bs), z = readFloat(bs), w = readFloat(bs) }
|
||||||
|
end
|
||||||
|
|
||||||
|
local function readList(bs, keyFun)
|
||||||
|
local list = {}
|
||||||
|
local v
|
||||||
|
for i = 1, readSize(bs) do
|
||||||
|
tinsert(list, keyFun(bs))
|
||||||
|
end
|
||||||
|
return list
|
||||||
|
end
|
||||||
|
|
||||||
|
local readArray = readList
|
||||||
|
|
||||||
|
local function readSet(bs, keyFun)
|
||||||
|
local set = {}
|
||||||
|
local v
|
||||||
|
for i = 1, readSize(bs) do
|
||||||
|
tinsert(set, keyFun(bs))
|
||||||
|
end
|
||||||
|
return set
|
||||||
|
end
|
||||||
|
|
||||||
|
local function readMap(bs, keyFun, valueFun)
|
||||||
|
local map = {}
|
||||||
|
for i = 1, readSize(bs) do
|
||||||
|
local k = keyFun(bs)
|
||||||
|
local v = valueFun(bs)
|
||||||
|
map[k] = v
|
||||||
|
end
|
||||||
|
return map
|
||||||
|
end
|
||||||
|
|
||||||
|
local function readNullableBool(bs)
|
||||||
|
if readBool(bs) then
|
||||||
|
return readBool(bs)
|
||||||
|
end
|
||||||
|
end";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Luban.Job.Common.Utils
|
||||||
|
{
|
||||||
|
public class PythonStringTemplates
|
||||||
|
{
|
||||||
|
public const string PythonVectorTypes = @"
|
||||||
|
class Vector2:
|
||||||
|
def __init__(self, x, y):
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
def __str__(self):
|
||||||
|
return '{%g,%g}' % (self.x, self.y)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def fromJson(_json_):
|
||||||
|
x = _json_['x']
|
||||||
|
y = _json_['y']
|
||||||
|
if (x == None or y == None):
|
||||||
|
raise Exception()
|
||||||
|
return Vector2(x, y)
|
||||||
|
|
||||||
|
|
||||||
|
class Vector3:
|
||||||
|
def __init__(self, x, y, z):
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
self.z = z
|
||||||
|
def __str__(self):
|
||||||
|
return '{%f,%f,%f}' % (self.x, self.y, self.z)
|
||||||
|
@staticmethod
|
||||||
|
def fromJson(_json_):
|
||||||
|
x = _json_['x']
|
||||||
|
y = _json_['y']
|
||||||
|
z = _json_['z']
|
||||||
|
if (x == None or y == None or z == None):
|
||||||
|
raise Exception()
|
||||||
|
return Vector3(x, y, z)
|
||||||
|
|
||||||
|
class Vector4:
|
||||||
|
def __init__(self, x, y, z, w):
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
self.z = z
|
||||||
|
self.w = w
|
||||||
|
def __str__(self):
|
||||||
|
return '{%g,%g,%g,%g}' % (self.x, self.y, self.z, self.w)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def fromJson(_json_):
|
||||||
|
x = _json_['x']
|
||||||
|
y = _json_['y']
|
||||||
|
z = _json_['z']
|
||||||
|
w = _json_['w']
|
||||||
|
if (x == None or y == None or z == None or w == None):
|
||||||
|
raise Exception()
|
||||||
|
return Vector4(x, y, z, w)
|
||||||
|
|
||||||
|
";
|
||||||
|
|
||||||
|
public const string ImportTython3Enum = @"
|
||||||
|
from enum import Enum
|
||||||
|
import abc
|
||||||
|
";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Luban.Job.Common.Utils
|
namespace Luban.Job.Common.Utils
|
||||||
{
|
{
|
||||||
public static class TypescriptBrightTypeTemplates
|
public static class TypescriptStringTemplate
|
||||||
{
|
{
|
||||||
public const string PuertsByteBufImports = @"
|
public const string PuertsByteBufImports = @"
|
||||||
import {Bright} from 'csharp'
|
import {Bright} from 'csharp'
|
||||||
|
|
@ -135,11 +135,11 @@ namespace Luban.Job.Db
|
||||||
{
|
{
|
||||||
var fileContent = new List<string>();
|
var fileContent = new List<string>();
|
||||||
|
|
||||||
fileContent.Add(string.Format(TypescriptBrightTypeTemplates.BrightByteBufImportsFormat, brightRequirePath));
|
fileContent.Add(string.Format(TypescriptStringTemplate.BrightByteBufImportsFormat, brightRequirePath));
|
||||||
|
|
||||||
fileContent.Add(string.Format(TypescriptBrightTypeTemplates.SerializeImportsFormat, brightRequirePath));
|
fileContent.Add(string.Format(TypescriptStringTemplate.SerializeImportsFormat, brightRequirePath));
|
||||||
fileContent.Add(string.Format(TypescriptBrightTypeTemplates.ProtocolImportsFormat, brightRequirePath));
|
fileContent.Add(string.Format(TypescriptStringTemplate.ProtocolImportsFormat, brightRequirePath));
|
||||||
fileContent.Add(string.Format(TypescriptBrightTypeTemplates.VectorImportsFormat, brightRequirePath));
|
fileContent.Add(string.Format(TypescriptStringTemplate.VectorImportsFormat, brightRequirePath));
|
||||||
fileContent.Add($"import {{FieldLogger, FieldLoggerGeneric1, FieldLoggerGeneric2}} from '{brightRequirePath}/transaction/FieldLogger'");
|
fileContent.Add($"import {{FieldLogger, FieldLoggerGeneric1, FieldLoggerGeneric2}} from '{brightRequirePath}/transaction/FieldLogger'");
|
||||||
fileContent.Add($"import TxnBeanBase from '{brightRequirePath}/transaction/TxnBeanBase'");
|
fileContent.Add($"import TxnBeanBase from '{brightRequirePath}/transaction/TxnBeanBase'");
|
||||||
fileContent.Add($"import {{TxnTable, TxnTableGeneric}} from '{brightRequirePath}/transaction/TxnTable'");
|
fileContent.Add($"import {{TxnTable, TxnTableGeneric}} from '{brightRequirePath}/transaction/TxnTable'");
|
||||||
|
|
|
||||||
|
|
@ -159,23 +159,23 @@ namespace Luban.Job.Proto
|
||||||
var fileContent = new List<string>();
|
var fileContent = new List<string>();
|
||||||
if (args.UsePuertsByteBuf)
|
if (args.UsePuertsByteBuf)
|
||||||
{
|
{
|
||||||
fileContent.Add(TypescriptBrightTypeTemplates.PuertsByteBufImports);
|
fileContent.Add(TypescriptStringTemplate.PuertsByteBufImports);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fileContent.Add(string.Format(TypescriptBrightTypeTemplates.BrightByteBufImportsFormat, brightRequirePath));
|
fileContent.Add(string.Format(TypescriptStringTemplate.BrightByteBufImportsFormat, brightRequirePath));
|
||||||
}
|
}
|
||||||
if (args.EmbedBrightTypes)
|
if (args.EmbedBrightTypes)
|
||||||
{
|
{
|
||||||
fileContent.Add(TypescriptBrightTypeTemplates.VectorTypesByteBuf);
|
fileContent.Add(TypescriptStringTemplate.VectorTypesByteBuf);
|
||||||
fileContent.Add(TypescriptBrightTypeTemplates.SerializeTypes);
|
fileContent.Add(TypescriptStringTemplate.SerializeTypes);
|
||||||
fileContent.Add(TypescriptBrightTypeTemplates.ProtoTypes);
|
fileContent.Add(TypescriptStringTemplate.ProtoTypes);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fileContent.Add(string.Format(TypescriptBrightTypeTemplates.SerializeImportsFormat, brightRequirePath));
|
fileContent.Add(string.Format(TypescriptStringTemplate.SerializeImportsFormat, brightRequirePath));
|
||||||
fileContent.Add(string.Format(TypescriptBrightTypeTemplates.ProtocolImportsFormat, brightRequirePath));
|
fileContent.Add(string.Format(TypescriptStringTemplate.ProtocolImportsFormat, brightRequirePath));
|
||||||
fileContent.Add(string.Format(TypescriptBrightTypeTemplates.VectorImportsFormat, brightRequirePath));
|
fileContent.Add(string.Format(TypescriptStringTemplate.VectorImportsFormat, brightRequirePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
fileContent.Add(@$"export namespace {ass.TopModule} {{");
|
fileContent.Add(@$"export namespace {ass.TopModule} {{");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue