From 1377eb828dc06343929883a4e09fb1cec2ef7ede Mon Sep 17 00:00:00 2001 From: walon Date: Sun, 5 Dec 2021 17:52:42 +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=8Dref=E4=BA=86=E4=B8=8D=E5=B1=9E=E4=BA=8E=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E5=AF=BC=E5=87=BA=E5=88=86=E7=BB=84=E7=9A=84table?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E7=94=9F=E6=88=90=E6=8A=A5=E9=94=99=E7=9A=84?= =?UTF-8?q?bug=E3=80=82=20=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=9C=AA=E8=BF=9B=E8=A1=8C=E5=AE=8C=E6=95=B4=E7=94=9F?= =?UTF-8?q?=E6=88=90=EF=BC=8C=E5=8F=AA=E7=94=9F=E6=88=90=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E5=88=86=E7=BB=84=E8=A1=A8=EF=BC=8C=E5=AF=BC=E8=87=B4=E4=B8=80?= =?UTF-8?q?=E4=BA=9Bref=E6=A3=80=E6=9F=A5=E5=87=BA=E9=94=99=E7=9A=84bug?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Luban.Job.Cfg/Source/Defs/DefAssembly.cs | 5 +++++ src/Luban.Job.Cfg/Source/JobController.cs | 2 +- src/Luban.Job.Cfg/Source/Utils/DataLoaderUtil.cs | 2 +- .../Source/Validators/RefValidator.cs | 14 ++++++++------ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Luban.Job.Cfg/Source/Defs/DefAssembly.cs b/src/Luban.Job.Cfg/Source/Defs/DefAssembly.cs index a29815d..8b24fd2 100644 --- a/src/Luban.Job.Cfg/Source/Defs/DefAssembly.cs +++ b/src/Luban.Job.Cfg/Source/Defs/DefAssembly.cs @@ -157,6 +157,11 @@ namespace Luban.Job.Cfg.Defs return _recordsByTables[table.FullName]; } + public List GetAllTables() + { + return Types.Values.Where(t => t is DefTable).Cast().ToList(); + } + public List GetExportTables() { return Types.Values.Where(t => t is DefTable ct && ct.NeedExport).Select(t => (DefTable)t).ToList(); diff --git a/src/Luban.Job.Cfg/Source/JobController.cs b/src/Luban.Job.Cfg/Source/JobController.cs index 493a129..4a1f4cc 100644 --- a/src/Luban.Job.Cfg/Source/JobController.cs +++ b/src/Luban.Job.Cfg/Source/JobController.cs @@ -178,7 +178,7 @@ namespace Luban.Job.Cfg timer.StartPhase("validate"); var validateCtx = new ValidatorContext(ass, args.ValidateRootDir); - await validateCtx.ValidateTables(exportTables); + await validateCtx.ValidateTables(ass.GetAllTables()); timer.EndPhaseAndLog(); } } diff --git a/src/Luban.Job.Cfg/Source/Utils/DataLoaderUtil.cs b/src/Luban.Job.Cfg/Source/Utils/DataLoaderUtil.cs index f3cd294..49eaa73 100644 --- a/src/Luban.Job.Cfg/Source/Utils/DataLoaderUtil.cs +++ b/src/Luban.Job.Cfg/Source/Utils/DataLoaderUtil.cs @@ -167,7 +167,7 @@ namespace Luban.Job.Cfg.Utils public static async Task LoadCfgDataAsync(IAgent agent, DefAssembly ass, string dataDir, string patchName, string patchDataDir, string inputConvertDataDir) { var ctx = agent; - List exportTables = ass.Types.Values.Where(t => t is DefTable ct && ct.NeedExport).Select(t => (DefTable)t).ToList(); + List exportTables = ass.Types.Values.Where(t => t is DefTable).Cast().ToList(); //&& ct.NeedExport.Select(t => (DefTable)t) var genDataTasks = new List(); var outputDataFiles = new ConcurrentBag(); long genDataStartTime = Bright.Time.TimeUtil.NowMillis; diff --git a/src/Luban.Job.Cfg/Source/Validators/RefValidator.cs b/src/Luban.Job.Cfg/Source/Validators/RefValidator.cs index 952c799..d2e41de 100644 --- a/src/Luban.Job.Cfg/Source/Validators/RefValidator.cs +++ b/src/Luban.Job.Cfg/Source/Validators/RefValidator.cs @@ -58,7 +58,7 @@ namespace Luban.Job.Cfg.Validators case ETableMode.MAP: { var recordMap = assembly.GetTableDataInfo(ct).FinalRecordMap; - if (/*recordMap != null &&*/ recordMap.ContainsKey(key)) + if (recordMap.ContainsKey(key)) { return; } @@ -139,10 +139,10 @@ namespace Luban.Job.Cfg.Validators { throw new Exception($"结构:{hostTypeName} 字段:{fieldName} ref:{actualTable} 不存在"); } - if (!ct.NeedExport) - { - throw new Exception($"type:'{hostTypeName}' field:'{fieldName}' ref 引用的表:'{actualTable}' 没有导出"); - } + //if (!ct.NeedExport) + //{ + // throw new Exception($"type:'{hostTypeName}' field:'{fieldName}' ref 引用的表:'{actualTable}' 没有导出"); + //} if (ct.IsOneValueTable) { if (string.IsNullOrEmpty(fieldName)) @@ -167,8 +167,10 @@ namespace Luban.Job.Cfg.Validators } else if (ct.IsMapTable) { - if (first && Tables.Count == 1) + if (first && Tables.Count == 1 && ct.NeedExport) { + // 只引用一个表时才生成ref代码。 + // 如果被引用的表没有导出,生成ref没有意义,还会产生编译错误 GenRef = true; } if (!string.IsNullOrEmpty(indexName))