【cfg】 ref 支持多个表

【cfg】 修复Validator未加载完所有数据便进行校验,导致出现大量ref检查错误的bug
main
walon 2021-06-02 15:39:53 +08:00
parent b123a61081
commit a36b118a98
5 changed files with 52 additions and 23 deletions

View File

@ -69,7 +69,7 @@ namespace Luban.Job.Cfg.Defs
public Dictionary<DType, DBean> GetTableDataMap(DefTable table)
{
return _recordsMapByTables.GetValueOrDefault(table.FullName);
return _recordsMapByTables[table.FullName];
}
public List<DefTable> GetExportTables()

View File

@ -46,7 +46,7 @@ namespace Luban.Job.Cfg.Defs
public RefValidator Ref { get; private set; }
// 对于 two key map, 需要检查 ref,但不为它生成 ref 代码.故只有map类型表才要生成代码
public bool GenRef => Ref != null && Assembly.GetCfgTable(Ref.FirstTable).IsMapTable;
public bool GenRef => Ref != null && Ref.Tables.Count == 1 && Assembly.GetCfgTable(Ref.FirstTable).IsMapTable;
public bool HasRecursiveRef => (CType is TBean)
|| (CType is TArray ta && ta.ElementType is TBean)

View File

@ -61,27 +61,41 @@ namespace Luban.Job.Cfg
public async Task ValidateTables(IEnumerable<DefTable> tables)
{
var tasks = new List<Task>();
foreach (var t in tables)
{
tasks.Add(Task.Run(() =>
var tasks = new List<Task>();
foreach (var t in tables)
{
var records = t.Assembly.GetTableDataList(t);
ValidateTableModeIndex(t, records);
var visitor = new ValidatorVisitor(this);
try
tasks.Add(Task.Run(() =>
{
CurrentVisitor = visitor;
visitor.ValidateTable(t, records);
}
finally
{
CurrentVisitor = null;
}
}));
var records = t.Assembly.GetTableDataList(t);
ValidateTableModeIndex(t, records);
}));
}
await Task.WhenAll(tasks);
}
await Task.WhenAll(tasks);
{
var tasks = new List<Task>();
foreach (var t in tables)
{
tasks.Add(Task.Run(() =>
{
var records = t.Assembly.GetTableDataList(t);
var visitor = new ValidatorVisitor(this);
try
{
CurrentVisitor = visitor;
visitor.ValidateTable(t, records);
}
finally
{
CurrentVisitor = null;
}
}));
}
await Task.WhenAll(tasks);
}
if (!string.IsNullOrWhiteSpace(RootDir))
{
await ValidatePaths();

View File

@ -54,13 +54,27 @@ namespace Luban.Job.Cfg.Validators
}
DefTable ct = assembly.GetCfgTable(actualTable);
var recordMap = assembly.GetTableDataMap(ct);
if (recordMap != null && !recordMap.ContainsKey(key))
if (/*recordMap != null &&*/ recordMap.ContainsKey(key))
{
string source = DataUtil.GetSourceFile(ValidatorContext.CurrentVisitor.CurrentValidateRecord);
assembly.Agent.Error("记录 {0} = {1} (来自文件:{2}) 在引用表:{3} 中不存在", ValidatorContext.CurrentRecordPath, key, source, table);
return;
}
}
foreach (var table in Tables)
{
string actualTable;
if (table.EndsWith("?"))
{
actualTable = table[0..^1];
}
else
{
actualTable = table;
}
DefTable ct = assembly.GetCfgTable(actualTable);
string source = DataUtil.GetSourceFile(ValidatorContext.CurrentVisitor.CurrentValidateRecord);
assembly.Agent.Error("记录 {0} = {1} (来自文件:{2}) 在引用表:{3} 中不存在", ValidatorContext.CurrentRecordPath, key, source, table);
}
}
public void Compile(DefField def)

View File

@ -1,6 +1,7 @@
using Luban.Config.Common.RawDefs;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Luban.Job.Cfg.Validators
{
@ -14,7 +15,7 @@ namespace Luban.Job.Cfg.Validators
{
case RefValidator.NAME:
{
return new RefValidator(new List<string> { validator.Rule });
return new RefValidator(validator.Rule.Split(',').ToList());
}
case PathValidator.NAME:
{