【优化】cfg cs代码的datetime类型额外生成 xxx_Millis字段,返回毫秒值。

【更新】更新文档,补充protobuf,msgpack,flatbuffers相关描述
main
walon 2021-11-30 12:16:38 +08:00
parent 56c222976e
commit d571638970
29 changed files with 65 additions and 11 deletions

View File

@ -41,13 +41,14 @@ luban相较于常规的excel导表工具有以下核心优势
## 特性
- 支持excel族、json、xml、lua、yaml 多种数据格式,基本统一了游戏常见的配置数据
- **强大完备的类型系统**。**可以优雅表达任意复杂的数据结构**。支持所有常见原生类型、datetime类型、容器类型list,set,map、枚举和结构、**多态结构**以及**可空类型**。
- **强大完备的类型系统**。**可以优雅表达任意复杂的数据结构**。支持所有常见原生类型、text本地化类型、datetime类型、vector{2,3,4}、容器类型list,set,map、枚举和结构、**多态结构**以及**可空类型**。
- 支持增强的excel格式。可以在excel里比较简洁填写出任意复杂的嵌套数据。
- 生成代码清晰易读、良好模块化。支持指定变量命名风格约定。特地支持运行时原子性热更新配置。
- 灵活的数据源定义。一个表可以来自多个文件或者一个文件内定义多个表或者一个目录下所有文件甚至来自云表格,以及以上的组合
- 支持表与字段级别分组。可以灵活定义分组,选择性地导出客户端或者服务器或编辑器所用的表及字段
- 多种导出数据格式支持。支持binary、json、**protobuf**、lua、xml、erlang、**xlsx** 及自定义的导出数据格式
- 支持xlsx与json、lua、protobuf等格式之间互转
- 支持生成**protobuf**、**msgpack**、**flatbuffers**相应的定义文件及相应的数据文件(直接反射导出,高效,并不需要生成代码后再利用生成的代码加载导出)
- 多种导出数据格式支持。支持binary、json、**protobuf**、**msgpack**、**flatbuffers**、lua、xml、erlang、**xlsx** 及自定义的导出数据格式
- 支持xlsx与json、lua、xml、yaml等格式之间互转
- 强大灵活的定制能力
- 支持代码模板,可以用自定义模板定制生成的代码格式
- **支持数据模板**可以用模板文件定制导出格式。意味着可以在不改动现有程序代码的情况下把luban当作**配置处理前端**生成自定义格式的数据与自己项目的配置加载代码配合工作。开发已久的项目或者已经上线的老项目也能从luban强大的数据处理工作流中获益

View File

@ -687,7 +687,7 @@ namespace Luban.Job.Cfg.Defs
);
}
private Field CreateField(string defileFile, string name, string type, string group,
private Field CreateField(string defineFile, string name, string type, string group,
string comment, string tags,
bool ignoreNameValidation)
{
@ -703,13 +703,9 @@ namespace Luban.Job.Cfg.Defs
// 字段与table的默认组不一样。
// table 默认只属于default=1的组
// 字段默认属于所有组
if (f.Groups.Count == 0)
if (!ValidGroup(f.Groups, out var invalidGroup))
{
}
else if (!ValidGroup(f.Groups, out var invalidGroup))
{
throw new Exception($"定义文件:{defileFile} field:'{name}' group:'{invalidGroup}' 不存在");
throw new Exception($"定义文件:{defineFile} field:'{name}' group:'{invalidGroup}' 不存在");
}
f.Type = type;
@ -724,7 +720,7 @@ namespace Luban.Job.Cfg.Defs
return f;
}
private static readonly List<string> _beanOptinsAttrs = new List<string> { "value_type", "alias", "sep", "comment", "tags" };
private static readonly List<string> _beanOptinsAttrs = new List<string> { "value_type", "alias", "sep", "comment", "tags", "group" };
private static readonly List<string> _beanRequireAttrs = new List<string> { "name" };
override protected void AddBean(string defineFile, XElement e, string parent)

View File

@ -14,6 +14,8 @@ namespace Luban.Job.Common.Types
public override TType ElementType { get; }
public override string TypeName => "array";
private TArray(bool isNullable, Dictionary<string, string> tags, TType elementType) : base(isNullable, tags)
{
ElementType = elementType;

View File

@ -18,6 +18,8 @@ namespace Luban.Job.Common.Types
public T GetBeanAs<T>() where T : DefBeanBase => (T)Bean;
public override string TypeName => "bean";
private TBean(bool isNullable, Dictionary<string, string> attrs, DefBeanBase defBean) : base(isNullable, attrs)
{
this.Bean = defBean;

View File

@ -16,6 +16,8 @@ namespace Luban.Job.Common.Types
public bool IsBool => true;
public override string TypeName => "bool";
public override bool TryParseFrom(string s)
{
return bool.TryParse(s, out _);

View File

@ -10,6 +10,8 @@ namespace Luban.Job.Common.Types
return new TByte(isNullable, tags);
}
public override string TypeName => "byte";
private TByte(bool isNullable, Dictionary<string, string> tags) : base(isNullable, tags)
{
}

View File

@ -11,6 +11,8 @@ namespace Luban.Job.Common.Types
return new TBytes(isNullable, tags);
}
public override string TypeName => "bytes";
private TBytes(bool isNullable, Dictionary<string, string> tags) : base(isNullable, tags)
{
}

View File

@ -11,6 +11,8 @@ namespace Luban.Job.Common.Types
return new TDateTime(isNullable, tags);
}
public override string TypeName => "datetime";
private TDateTime(bool isNullable, Dictionary<string, string> tags) : base(isNullable, tags)
{
}

View File

@ -10,6 +10,8 @@ namespace Luban.Job.Common.Types
return new TDouble(isNullable, tags);
}
public override string TypeName => "double";
private TDouble(bool isNullable, Dictionary<string, string> tags) : base(isNullable, tags)
{
}

View File

@ -13,6 +13,8 @@ namespace Luban.Job.Common.Types
return new TEnum(isNullable, DefUtil.MergeTags(defEnum.Tags, tags), defEnum);
}
public override string TypeName => "enum";
public DefEnum DefineEnum { get; }
private TEnum(bool isNullable, Dictionary<string, string> tags, DefEnum defEnum) : base(isNullable, tags)

View File

@ -14,6 +14,8 @@ namespace Luban.Job.Common.Types
{
}
public override string TypeName => "fint";
public override bool TryParseFrom(string s)
{
return int.TryParse(s, out _);

View File

@ -12,6 +12,8 @@ namespace Luban.Job.Common.Types
return new TFloat(isNullable, tags);
}
public override string TypeName => "float";
private TFloat(bool isNullable, Dictionary<string, string> tags) : base(isNullable, tags)
{
}

View File

@ -10,6 +10,8 @@ namespace Luban.Job.Common.Types
return new TFlong(isNullable, tags);
}
public override string TypeName => "flong";
private TFlong(bool isNullable, Dictionary<string, string> tags) : base(isNullable, tags)
{
}

View File

@ -10,6 +10,8 @@ namespace Luban.Job.Common.Types
return new TFshort(isNullable, tags);
}
public override string TypeName => "fshort";
private TFshort(bool isNullable, Dictionary<string, string> tags) : base(isNullable, tags)
{
}

View File

@ -10,6 +10,8 @@ namespace Luban.Job.Common.Types
return new TInt(isNullable, tags);
}
public override string TypeName => "int";
private TInt(bool isNullable, Dictionary<string, string> tags) : base(isNullable, tags)
{
}

View File

@ -12,6 +12,8 @@ namespace Luban.Job.Common.Types
return new TList(isNullable, tags, elementType, isArrayList);
}
public override string TypeName => "list";
public override TType ElementType { get; }
public bool IsArrayList { get; }

View File

@ -10,6 +10,8 @@ namespace Luban.Job.Common.Types
return new TLong(isNullable, tags, isBigInt);
}
public override string TypeName => "long";
public bool IsBigInt { get; }
private TLong(bool isNullable, Dictionary<string, string> tags, bool isBigInt) : base(isNullable, tags)

View File

@ -12,6 +12,8 @@ namespace Luban.Job.Common.Types
return new TMap(isNullable, tags, keyType, valueType, isOrderedMap);
}
public override string TypeName => "map";
public bool IsMap => true;
public TType KeyType { get; }

View File

@ -12,6 +12,8 @@ namespace Luban.Job.Common.Types
return new TSet(isNullable, tags, elementType, isOrdered);
}
public override string TypeName => "set";
public override TType ElementType { get; }
public bool IsOrderSet { get; }

View File

@ -10,6 +10,8 @@ namespace Luban.Job.Common.Types
return new TShort(isNullable, tags);
}
public override string TypeName => "short";
private TShort(bool isNullable, Dictionary<string, string> tags) : base(isNullable, tags)
{
}

View File

@ -10,6 +10,8 @@ namespace Luban.Job.Common.Types
return new TString(isNullable, tags);
}
public override string TypeName => "string";
private TString(bool isNullable, Dictionary<string, string> tags) : base(isNullable, tags)
{
}

View File

@ -12,6 +12,8 @@ namespace Luban.Job.Common.Types
return new TText(isNullable, tags);
}
public override string TypeName => "text";
private TText(bool isNullable, Dictionary<string, string> tags) : base(isNullable, tags)
{
}

View File

@ -18,6 +18,8 @@ namespace Luban.Job.Common.Types
Tags = tags ?? new Dictionary<string, string>();
}
public abstract string TypeName { get; }
public bool HasTag(string attrName)
{
return Tags != null && Tags.ContainsKey(attrName);

View File

@ -11,6 +11,8 @@ namespace Luban.Job.Common.Types
return new TVector2(isNullable, tags);
}
public override string TypeName => "vector2";
private TVector2(bool isNullable, Dictionary<string, string> tags) : base(isNullable, tags)
{
}

View File

@ -11,6 +11,8 @@ namespace Luban.Job.Common.Types
return new TVector3(isNullable, tags);
}
public override string TypeName => "vector3";
private TVector3(bool isNullable, Dictionary<string, string> tags) : base(isNullable, tags)
{
}

View File

@ -11,6 +11,8 @@ namespace Luban.Job.Common.Types
return new TVector4(isNullable, tags);
}
public override string TypeName => "vector4";
private TVector4(bool isNullable, Dictionary<string, string> tags) : base(isNullable, tags)
{
}

View File

@ -59,6 +59,9 @@ public {{x.cs_class_modifier}} class {{name}} : {{if parent_def_type}} {{x.paren
{{~if field.gen_ref~}}
public {{field.cs_ref_validator_define}}
{{~end~}}
{{~if field.ctype.type_name == "datetime" && !field.ctype.is_nullable ~}}
public long {{field.convention_name}}_Millis => {{field.convention_name}} * 1000L;
{{~end~}}
{{~if field.gen_text_key~}}
public {{cs_define_text_key_field field}} { get; }
{{~end~}}

View File

@ -68,6 +68,9 @@ public {{x.cs_class_modifier}} class {{name}} : {{if parent_def_type}} {{parent}
{{~if field.gen_ref~}}
public {{field.cs_ref_validator_define}}
{{~end~}}
{{~if field.ctype.type_name == "datetime" && !field.ctype.is_nullable ~}}
public long {{field.convention_name}}_Millis => {{field.convention_name}} * 1000L;
{{~end~}}
{{~if field.gen_text_key~}}
public {{cs_define_text_key_field field}} { get; }
{{~end~}}

View File

@ -69,6 +69,9 @@ public {{x.cs_class_modifier}} class {{name}} : {{if parent_def_type}} {{parent}
{{~if field.gen_ref~}}
public {{field.cs_ref_validator_define}}
{{~end~}}
{{~if field.ctype.type_name == "datetime" && !field.ctype.is_nullable ~}}
public long {{field.convention_name}}_Millis => {{field.convention_name}} * 1000L;
{{~end~}}
{{~if field.gen_text_key~}}
public {{cs_define_text_key_field field}} { get; }
{{~end~}}