From 8069c6d7fe8cb54060d57fad359d36a322b185ff Mon Sep 17 00:00:00 2001 From: walon Date: Mon, 30 Aug 2021 10:43:55 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E4=B8=8A=E6=AC=A1=E8=B0=83=E6=95=B4DataExport?= =?UTF-8?q?=E5=BC=95=E5=8F=91=E7=9A=84=E6=96=B0=E7=9A=84=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=9A=84bug=20=E3=80=90=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E3=80=91=E8=B0=83=E6=95=B4=E8=BE=93=E5=87=BA=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=90=8D=E4=B8=BA=20.replace('.?= =?UTF-8?q?','=5F').lower()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Source/DataExporters/BinaryExportor.cs | 8 ++++++-- .../Source/DataExporters/JsonExportor.cs | 6 +++--- .../Source/DataVisitors/ToJsonLiteralVisitor.cs | 16 +++++++++------- .../Source/DataVisitors/ToLuaLiteralVisitor.cs | 4 ++-- .../DataVisitors/ToPythonLiteralVisitor.cs | 16 +++++----------- .../Source/DataVisitors/ToStringVisitor.cs | 2 +- src/Luban.Job.Cfg/Source/Defs/DefTable.cs | 4 +--- .../Source/Utils/DTypeTemplateExtends.cs | 4 ++-- .../Source/Utils/RenderFileUtil.cs | 2 +- .../Templates/config/lua_lua/all.tpl | 4 ++-- 10 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/Luban.Job.Cfg/Source/DataExporters/BinaryExportor.cs b/src/Luban.Job.Cfg/Source/DataExporters/BinaryExportor.cs index 34d869f..751c2b9 100644 --- a/src/Luban.Job.Cfg/Source/DataExporters/BinaryExportor.cs +++ b/src/Luban.Job.Cfg/Source/DataExporters/BinaryExportor.cs @@ -100,11 +100,15 @@ namespace Luban.Job.Cfg.DataExporters x.WriteInt(type.ImplType.Id); } - var defFields = type.ImplType.HierarchyExportFields; + var defFields = type.ImplType.HierarchyFields; int index = 0; foreach (var field in type.Fields) { - var defField = defFields[index++]; + var defField = (DefField)defFields[index++]; + if (!defField.NeedExport) + { + continue; + } if (defField.CType.IsNullable) { if (field != null) diff --git a/src/Luban.Job.Cfg/Source/DataExporters/JsonExportor.cs b/src/Luban.Job.Cfg/Source/DataExporters/JsonExportor.cs index aa42004..e7c7171 100644 --- a/src/Luban.Job.Cfg/Source/DataExporters/JsonExportor.cs +++ b/src/Luban.Job.Cfg/Source/DataExporters/JsonExportor.cs @@ -107,15 +107,15 @@ namespace Luban.Job.Cfg.DataExporters x.WriteStringValue(type.ImplType.Name); } - var defFields = type.ImplType.HierarchyExportFields; + var defFields = type.ImplType.HierarchyFields; int index = 0; foreach (var d in type.Fields) { - var defField = defFields[index++]; + var defField = (DefField)defFields[index++]; // 特殊处理 bean 多态类型 // 另外,不生成 xxx:null 这样 - if (d == null /*|| (d is DBean db && db.ImplType == null)*/) + if (d == null || !defField.NeedExport) { //x.WriteNullValue(); } diff --git a/src/Luban.Job.Cfg/Source/DataVisitors/ToJsonLiteralVisitor.cs b/src/Luban.Job.Cfg/Source/DataVisitors/ToJsonLiteralVisitor.cs index b741d4a..a5c61ee 100644 --- a/src/Luban.Job.Cfg/Source/DataVisitors/ToJsonLiteralVisitor.cs +++ b/src/Luban.Job.Cfg/Source/DataVisitors/ToJsonLiteralVisitor.cs @@ -19,13 +19,11 @@ namespace Luban.Job.Cfg.DataVisitors public override string Accept(DBean type) { var x = new StringBuilder(); + bool prevProperty = false; if (type.Type.IsAbstractType) { x.Append($"{{ \"_name\":\"{type.ImplType.Name}\""); - if (type.Fields.Count > 0) - { - x.Append(','); - } + prevProperty = true; } else { @@ -35,15 +33,19 @@ namespace Luban.Job.Cfg.DataVisitors int index = 0; foreach (var f in type.Fields) { - var defField = type.ImplType.HierarchyExportFields[index++]; - if (f == null) + var defField = (DefField)type.ImplType.HierarchyFields[index++]; + if (f == null || !defField.NeedExport) { continue; } - if (index > 1) + if (prevProperty) { x.Append(','); } + else + { + prevProperty = true; + } x.Append('\"').Append(defField.Name).Append('\"').Append(':'); x.Append(f.Apply(this)); } diff --git a/src/Luban.Job.Cfg/Source/DataVisitors/ToLuaLiteralVisitor.cs b/src/Luban.Job.Cfg/Source/DataVisitors/ToLuaLiteralVisitor.cs index 86488c0..6557d26 100644 --- a/src/Luban.Job.Cfg/Source/DataVisitors/ToLuaLiteralVisitor.cs +++ b/src/Luban.Job.Cfg/Source/DataVisitors/ToLuaLiteralVisitor.cs @@ -31,8 +31,8 @@ namespace Luban.Job.Cfg.DataVisitors int index = 0; foreach (var f in type.Fields) { - var defField = type.ImplType.HierarchyExportFields[index++]; - if (f == null) + var defField = (DefField)type.ImplType.HierarchyFields[index++]; + if (f == null || !defField.NeedExport) { continue; } diff --git a/src/Luban.Job.Cfg/Source/DataVisitors/ToPythonLiteralVisitor.cs b/src/Luban.Job.Cfg/Source/DataVisitors/ToPythonLiteralVisitor.cs index 939e6eb..10be55c 100644 --- a/src/Luban.Job.Cfg/Source/DataVisitors/ToPythonLiteralVisitor.cs +++ b/src/Luban.Job.Cfg/Source/DataVisitors/ToPythonLiteralVisitor.cs @@ -32,20 +32,14 @@ namespace Luban.Job.Cfg.DataVisitors int index = 0; foreach (var f in type.Fields) { - if (index >= 1) + var defField = (DefField)type.ImplType.HierarchyFields[index++]; + if (f == null || !defField.NeedExport) { - x.Append(','); + continue; } - var defField = type.ImplType.HierarchyExportFields[index++]; x.Append('\"').Append(defField.Name).Append('\"').Append(':'); - if (f != null) - { - x.Append(f.Apply(this)); - } - else - { - x.Append("None"); - } + x.Append(f.Apply(this)); + x.Append(','); } x.Append('}'); return x.ToString(); diff --git a/src/Luban.Job.Cfg/Source/DataVisitors/ToStringVisitor.cs b/src/Luban.Job.Cfg/Source/DataVisitors/ToStringVisitor.cs index 241fb52..f9aea19 100644 --- a/src/Luban.Job.Cfg/Source/DataVisitors/ToStringVisitor.cs +++ b/src/Luban.Job.Cfg/Source/DataVisitors/ToStringVisitor.cs @@ -31,7 +31,7 @@ namespace Luban.Job.Cfg.DataVisitors int index = 0; foreach (var f in type.Fields) { - var defField = type.ImplType.HierarchyExportFields[index++]; + var defField = type.ImplType.HierarchyFields[index++]; x.Append(defField.Name).Append(':'); if (f != null) { diff --git a/src/Luban.Job.Cfg/Source/Defs/DefTable.cs b/src/Luban.Job.Cfg/Source/Defs/DefTable.cs index 4d1924c..b455784 100644 --- a/src/Luban.Job.Cfg/Source/Defs/DefTable.cs +++ b/src/Luban.Job.Cfg/Source/Defs/DefTable.cs @@ -52,12 +52,10 @@ namespace Luban.Job.Cfg.Defs public bool NeedExport => Assembly.NeedExport(this.Groups); - public string OutputDataFile => FullName; + public string OutputDataFile => FullName.Replace('.', '_').ToLower(); public string InnerName => "_" + this.Name; - public string OutputDataFileEscapeDot => FullName.Replace('.', '_'); - public List GetBranchInputFiles(string branchName) { return _branchInputFiles.GetValueOrDefault(branchName); diff --git a/src/Luban.Job.Cfg/Source/Utils/DTypeTemplateExtends.cs b/src/Luban.Job.Cfg/Source/Utils/DTypeTemplateExtends.cs index 598c4f4..c260288 100644 --- a/src/Luban.Job.Cfg/Source/Utils/DTypeTemplateExtends.cs +++ b/src/Luban.Job.Cfg/Source/Utils/DTypeTemplateExtends.cs @@ -18,14 +18,14 @@ namespace Luban.Job.Cfg.Utils public static string ToLocalizedText(DText type) { - var ass = DefAssembly.LocalAssebmly as DefAssembly; + var ass = DefAssembly.LocalAssebmly; return type.GetText(ass.ExportTextTable, ass.NotConvertTextSet); } public static DType GetField(DBean bean, string fieldName) { int index = 0; - foreach (var f in bean.ImplType.HierarchyExportFields) + foreach (var f in bean.ImplType.HierarchyFields) { if (f.Name == fieldName) { diff --git a/src/Luban.Job.Common/Source/Utils/RenderFileUtil.cs b/src/Luban.Job.Common/Source/Utils/RenderFileUtil.cs index ac338f9..9d0b180 100644 --- a/src/Luban.Job.Common/Source/Utils/RenderFileUtil.cs +++ b/src/Luban.Job.Common/Source/Utils/RenderFileUtil.cs @@ -137,7 +137,7 @@ namespace Luban.Job.Common.Utils public static string GetOutputFileName(string genType, string fileName) { - return $"{fileName.Replace('.', '_')}.{GetOutputFileSuffix(genType)}"; + return $"{fileName}.{GetOutputFileSuffix(genType)}"; } } } diff --git a/src/Luban.Server/Templates/config/lua_lua/all.tpl b/src/Luban.Server/Templates/config/lua_lua/all.tpl index f191edd..61f5740 100644 --- a/src/Luban.Server/Templates/config/lua_lua/all.tpl +++ b/src/Luban.Server/Templates/config/lua_lua/all.tpl @@ -39,9 +39,9 @@ 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}}' }, + { 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_escape_dot}}', mode='one', value_type='{{table.value_ttype.bean.full_name}}'}, + { name='{{table.name}}', file='{{table.output_data_file}}', mode='one', value_type='{{table.value_ttype.bean.full_name}}'}, {{end}} {{~end~}} }