【特性】新增 SizeValidator
parent
4f0addec89
commit
9eacac3171
|
|
@ -736,7 +736,7 @@ binary格式占空间最小,lua其次,json最大。
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## [LubanAssistant](https://github.com/focus-creative-games/Tools/LubanAssistant) Excel插件。神器!
|
## [LubanAssistant](https://github.com/focus-creative-games/luban_examples/tree/main/Tools/LubanAssistant) Excel插件。神器!
|
||||||
对于多人协作编辑的配置表,如何以xlsx格式保存配置,很容易出现数据冲突覆盖的问题,在大型项目中尤为严重。另外合并多分支数据时,xlsx无法像文本文件那样自动解决冲突,给项目的版本维护带来很大麻烦。
|
对于多人协作编辑的配置表,如何以xlsx格式保存配置,很容易出现数据冲突覆盖的问题,在大型项目中尤为严重。另外合并多分支数据时,xlsx无法像文本文件那样自动解决冲突,给项目的版本维护带来很大麻烦。
|
||||||
|
|
||||||
一个合理的解决思路是,以json、xml之类格式保存配置数据,在excel中编辑。LubanAssistant较好地解决了这个问题,使用者既享受luban强大的数据处理能力、同时拥有json良好的可阅读性及多版本可维护性,还能兼顾excel的便捷的编辑能力。
|
一个合理的解决思路是,以json、xml之类格式保存配置数据,在excel中编辑。LubanAssistant较好地解决了这个问题,使用者既享受luban强大的数据处理能力、同时拥有json良好的可阅读性及多版本可维护性,还能兼顾excel的便捷的编辑能力。
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,90 @@
|
||||||
|
using Luban.Job.Cfg.Datas;
|
||||||
|
using Luban.Job.Common.Defs;
|
||||||
|
using Luban.Job.Common.Types;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Luban.Job.Cfg.Validators
|
||||||
|
{
|
||||||
|
internal class SizeValidator : IValidator
|
||||||
|
{
|
||||||
|
public const string NAME = "size";
|
||||||
|
private readonly TType _field;
|
||||||
|
private readonly int _size;
|
||||||
|
|
||||||
|
public SizeValidator(TType field, string rule)
|
||||||
|
{
|
||||||
|
this._field = field;
|
||||||
|
this._size = int.Parse(rule);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Compile(DefFieldBase def)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private string Source => ValidatorContext.CurrentVisitor.CurrentValidateRecord.Source;
|
||||||
|
|
||||||
|
public void Validate(ValidatorContext ctx, TType type, DType data)
|
||||||
|
{
|
||||||
|
var assembly = ctx.Assembly;
|
||||||
|
void LogError(int size)
|
||||||
|
{
|
||||||
|
assembly.Agent.Error("记录 {0}:{1} (来自文件:{2}) size:{3},但要求为 {4} ", ValidatorContext.CurrentRecordPath, data, Source, size, _size);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type.IsNullable && data == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (data)
|
||||||
|
{
|
||||||
|
case DArray b:
|
||||||
|
{
|
||||||
|
if (b.Datas.Count != _size)
|
||||||
|
{
|
||||||
|
LogError(b.Datas.Count);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DList b:
|
||||||
|
{
|
||||||
|
if (b.Datas.Count != _size)
|
||||||
|
{
|
||||||
|
LogError(b.Datas.Count);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DSet b:
|
||||||
|
{
|
||||||
|
if (b.Datas.Count != _size)
|
||||||
|
{
|
||||||
|
LogError(b.Datas.Count);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DMap b:
|
||||||
|
{
|
||||||
|
if (b.Datas.Count != _size)
|
||||||
|
{
|
||||||
|
LogError(b.Datas.Count);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
assembly.Agent.Error("记录 {0}:{1} (来自文件:{2}) 不支持 size", ValidatorContext.CurrentRecordPath, data, Source);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -11,7 +11,13 @@ namespace Luban.Job.Cfg.Validators
|
||||||
{
|
{
|
||||||
private static readonly NLog.Logger s_logger = NLog.LogManager.GetCurrentClassLogger();
|
private static readonly NLog.Logger s_logger = NLog.LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
private readonly static List<string> s_validatorNames = new List<string>() { RefValidator.NAME, PathValidator.NAME, RangeValidator.NAME };
|
private readonly static List<string> s_validatorNames = new List<string>()
|
||||||
|
{
|
||||||
|
RefValidator.NAME,
|
||||||
|
PathValidator.NAME,
|
||||||
|
RangeValidator.NAME,
|
||||||
|
SizeValidator.NAME
|
||||||
|
};
|
||||||
|
|
||||||
public static List<string> ValidatorNames => s_validatorNames;
|
public static List<string> ValidatorNames => s_validatorNames;
|
||||||
|
|
||||||
|
|
@ -32,6 +38,10 @@ namespace Luban.Job.Cfg.Validators
|
||||||
{
|
{
|
||||||
return new RangeValidator(field, rule);
|
return new RangeValidator(field, rule);
|
||||||
}
|
}
|
||||||
|
case SizeValidator.NAME:
|
||||||
|
{
|
||||||
|
return new SizeValidator(field, rule);
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
throw new NotSupportedException("unknown validator type:" + type);
|
throw new NotSupportedException("unknown validator type:" + type);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue