【特性】为enum,enum.item,bean,bean.field,bean.field.type,table 等大多数定义的对象加上attrs属性。同时添加 has_attr和get_attr模板函数,通过对对象标签识别做一些标准以外的自定义生成。
parent
04b51fccc4
commit
2955cbac52
|
|
@ -260,11 +260,12 @@ namespace Luban.Job.Cfg.Defs
|
|||
string input = XmlUtil.GetRequiredAttribute(e, "input");
|
||||
string branchInput = XmlUtil.GetOptionalAttribute(e, "branch_input");
|
||||
string mode = XmlUtil.GetOptionalAttribute(e, "mode");
|
||||
AddTable(CurImportFile, name, module, valueType, index, mode, group, comment, defineFromFile, input, branchInput);
|
||||
string attrs = XmlUtil.GetOptionalAttribute(e, "attrs");
|
||||
AddTable(CurImportFile, name, module, valueType, index, mode, group, comment, defineFromFile, input, branchInput, attrs);
|
||||
}
|
||||
|
||||
private void AddTable(string defineFile, string name, string module, string valueType, string index, string mode, string group,
|
||||
string comment, bool defineFromExcel, string input, string branchInput)
|
||||
string comment, bool defineFromExcel, string input, string branchInput, string attrs)
|
||||
{
|
||||
var p = new Table()
|
||||
{
|
||||
|
|
@ -276,6 +277,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
Groups = CreateGroups(group),
|
||||
Comment = comment,
|
||||
Mode = ConvertMode(name, mode, index),
|
||||
Attrs = attrs,
|
||||
};
|
||||
|
||||
if (p.Groups.Count == 0)
|
||||
|
|
@ -454,6 +456,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
new CfgField() { Name = "define_from_excel", Type = "bool" },
|
||||
new CfgField() { Name = "input", Type = "string" },
|
||||
new CfgField() { Name = "branch_input", Type = "string" },
|
||||
new CfgField() { Name = "attrs", Type = "string" },
|
||||
}
|
||||
})
|
||||
{
|
||||
|
|
@ -488,7 +491,8 @@ namespace Luban.Job.Cfg.Defs
|
|||
bool isDefineFromExcel = (data.GetField("define_from_excel") as DBool).Value;
|
||||
string inputFile = (data.GetField("input") as DString).Value.Trim();
|
||||
string branchInput = (data.GetField("branch_input") as DString).Value.Trim();
|
||||
AddTable(file.OriginFile, name, module, valueType, index, mode, group, comment, isDefineFromExcel, inputFile, branchInput);
|
||||
string attrs = (data.GetField("attrs") as DString).Value.Trim();
|
||||
AddTable(file.OriginFile, name, module, valueType, index, mode, group, comment, isDefineFromExcel, inputFile, branchInput, attrs);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -518,6 +522,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
new CfgField() { Name = "alias", Type = "string" },
|
||||
new CfgField() { Name = "value", Type = "int" },
|
||||
new CfgField() { Name = "comment", Type = "string" },
|
||||
new CfgField() { Name = "attrs", Type = "string" },
|
||||
}
|
||||
})
|
||||
{
|
||||
|
|
@ -561,7 +566,8 @@ namespace Luban.Job.Cfg.Defs
|
|||
string alias = (data.GetField("alias") as DString).Value.Trim();
|
||||
string value = (data.GetField("value") as DInt).Value.ToString();
|
||||
string comment = (data.GetField("comment") as DString).Value.Trim();
|
||||
curEnum.Items.Add(new EnumItem() { Name = item, Alias = alias, Value = value, Comment = comment });
|
||||
string attrs = (data.GetField("attrs") as DString).Value.Trim();
|
||||
curEnum.Items.Add(new EnumItem() { Name = item, Alias = alias, Value = value, Comment = comment, Attrs = attrs });
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -598,6 +604,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
new CfgField() { Name = "reference", Type = "string" },
|
||||
new CfgField() { Name = "path", Type = "string" },
|
||||
new CfgField() { Name = "comment", Type = "string" },
|
||||
new CfgField() { Name = "attrs", Type = "string" },
|
||||
}
|
||||
})
|
||||
{
|
||||
|
|
@ -625,6 +632,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
new CfgField() { Name = "full_name", Type = "string" },
|
||||
new CfgField() { Name = "sep", Type = "string" },
|
||||
new CfgField() { Name = "comment", Type = "string" },
|
||||
new CfgField() { Name = "attrs", Type = "string" },
|
||||
new CfgField() { Name = "fields", Type = "list,__FieldInfo__", IsMultiRow = true },
|
||||
}
|
||||
})
|
||||
|
|
@ -659,6 +667,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
|
||||
string sep = (data.GetField("sep") as DString).Value.Trim();
|
||||
string comment = (data.GetField("comment") as DString).Value.Trim();
|
||||
string attrs = (data.GetField("attrs") as DString).Value.Trim();
|
||||
DList fields = data.GetField("fields") as DList;
|
||||
var curBean = new CfgBean()
|
||||
{
|
||||
|
|
@ -666,6 +675,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
Namespace = module,
|
||||
Sep = sep,
|
||||
Comment = comment,
|
||||
Attrs = attrs,
|
||||
Parent = "",
|
||||
Fields = fields.Datas.Select(d => (DBean)d).Select(b => this.CreateField(
|
||||
(b.GetField("name") as DString).Value.Trim(),
|
||||
|
|
@ -682,7 +692,8 @@ namespace Luban.Job.Cfg.Defs
|
|||
"",
|
||||
"",
|
||||
"",
|
||||
""
|
||||
"",
|
||||
(b.GetField("attrs") as DString).Value.Trim()
|
||||
)).ToList(),
|
||||
};
|
||||
this._beans.Add(curBean);
|
||||
|
|
@ -698,7 +709,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
|
||||
private static readonly List<string> _fieldOptionalAttrs = new List<string> {
|
||||
"index", "sep", "validator", "key_validator", "value_validator",
|
||||
"ref", "path", "range", "multi_rows", "group", "res", "convert", "comment" };
|
||||
"ref", "path", "range", "multi_rows", "group", "res", "convert", "comment", "attrs" };
|
||||
|
||||
private static readonly List<string> _fieldRequireAttrs = new List<string> { "name", "type" };
|
||||
|
||||
|
|
@ -720,12 +731,13 @@ namespace Luban.Job.Cfg.Defs
|
|||
XmlUtil.GetOptionalAttribute(e, "range"),
|
||||
XmlUtil.GetOptionalAttribute(e, "key_validator"),
|
||||
XmlUtil.GetOptionalAttribute(e, "value_validator"),
|
||||
XmlUtil.GetOptionalAttribute(e, "validator")
|
||||
XmlUtil.GetOptionalAttribute(e, "validator"),
|
||||
XmlUtil.GetOptionalAttribute(e, "attrs")
|
||||
);
|
||||
}
|
||||
|
||||
private Field CreateField(string name, string type, string index, string sep, bool isMultiRow, string group, string resource, string converter,
|
||||
string comment, string refs, string path, string range, string keyValidator, string valueValidator, string validator)
|
||||
string comment, string refs, string path, string range, string keyValidator, string valueValidator, string validator, string attrs)
|
||||
{
|
||||
var f = new CfgField()
|
||||
{
|
||||
|
|
@ -737,6 +749,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
Resource = resource,
|
||||
Converter = converter,
|
||||
Comment = comment,
|
||||
Attrs = attrs,
|
||||
};
|
||||
|
||||
// 字段与table的默认组不一样。
|
||||
|
|
@ -763,7 +776,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
return f;
|
||||
}
|
||||
|
||||
private static readonly List<string> _beanOptinsAttrs = new List<string> { "value_type", "alias", "sep", "comment" };
|
||||
private static readonly List<string> _beanOptinsAttrs = new List<string> { "value_type", "alias", "sep", "comment", "attrs" };
|
||||
private static readonly List<string> _beanRequireAttrs = new List<string> { "name" };
|
||||
|
||||
protected override void AddBean(XElement e, string parent)
|
||||
|
|
@ -781,6 +794,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
Alias = XmlUtil.GetOptionalAttribute(e, "alias"),
|
||||
Sep = XmlUtil.GetOptionalAttribute(e, "sep"),
|
||||
Comment = XmlUtil.GetOptionalAttribute(e, "comment"),
|
||||
Attrs = XmlUtil.GetOptionalAttribute(e, "attrs"),
|
||||
};
|
||||
var childBeans = new List<XElement>();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using Luban.Job.Cfg.RawDefs;
|
||||
using Luban.Job.Common.Types;
|
||||
using Luban.Job.Common.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
|
@ -21,6 +22,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
Groups = b.Groups;
|
||||
_branchInputFiles = b.BranchInputFiles;
|
||||
Comment = b.Comment;
|
||||
Attrs = DefUtil.ParseAttrs(b.Attrs);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ namespace Luban.Job.Cfg.RawDefs
|
|||
|
||||
public string Comment { get; set; }
|
||||
|
||||
public string Attrs { get; set; }
|
||||
|
||||
public List<string> Groups { get; set; } = new List<string>();
|
||||
|
||||
public List<string> InputFiles { get; set; } = new List<string>();
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ namespace Luban.Job.Common.Defs
|
|||
}
|
||||
|
||||
private static readonly List<string> _fieldRequireAttrs = new List<string> { "name", "type", };
|
||||
private static readonly List<string> _fieldOptionalAttrs = new List<string> { "id", "comment" };
|
||||
private static readonly List<string> _fieldOptionalAttrs = new List<string> { "id", "comment", "attrs" };
|
||||
|
||||
protected virtual Field CreateField(XElement e)
|
||||
{
|
||||
|
|
@ -206,6 +206,7 @@ namespace Luban.Job.Common.Defs
|
|||
Name = XmlUtil.GetRequiredAttribute(e, "name"),
|
||||
Type = CreateType(e, "type"),
|
||||
Comment = XmlUtil.GetOptionalAttribute(e, "comment"),
|
||||
Attrs = XmlUtil.GetOptionalAttribute(e, "attrs"),
|
||||
};
|
||||
return f;
|
||||
}
|
||||
|
|
@ -215,10 +216,10 @@ namespace Luban.Job.Common.Defs
|
|||
AddBean(e, "");
|
||||
}
|
||||
|
||||
private static readonly List<string> _beanOptinsAttrs1 = new List<string> { "compatible", "value_type", "comment" };
|
||||
private static readonly List<string> _beanOptinsAttrs1 = new List<string> { "compatible", "value_type", "comment", "attrs" };
|
||||
private static readonly List<string> _beanRequireAttrs1 = new List<string> { "id", "name" };
|
||||
|
||||
private static readonly List<string> _beanOptinsAttrs2 = new List<string> { "id", "compatible", "value_type", "comment" };
|
||||
private static readonly List<string> _beanOptinsAttrs2 = new List<string> { "id", "compatible", "value_type", "comment", "attrs" };
|
||||
private static readonly List<string> _beanRequireAttrs2 = new List<string> { "name" };
|
||||
|
||||
protected virtual void AddBean(XElement e, string parent)
|
||||
|
|
@ -240,6 +241,7 @@ namespace Luban.Job.Common.Defs
|
|||
IsSerializeCompatible = XmlUtil.GetOptionBoolAttribute(e, "compatible", IsBeanDefaultCompatible),
|
||||
IsValueType = XmlUtil.GetOptionBoolAttribute(e, "value_type"),
|
||||
Comment = XmlUtil.GetOptionalAttribute(e, "comment"),
|
||||
Attrs = XmlUtil.GetOptionalAttribute(e, "attrs"),
|
||||
};
|
||||
var childBeans = new List<XElement>();
|
||||
|
||||
|
|
@ -334,11 +336,11 @@ namespace Luban.Job.Common.Defs
|
|||
_consts.Add(c);
|
||||
}
|
||||
|
||||
private static readonly List<string> _enumOptionalAttrs = new List<string> { "flags", "comment" };
|
||||
private static readonly List<string> _enumOptionalAttrs = new List<string> { "flags", "comment", "attrs" };
|
||||
private static readonly List<string> _enumRequiredAttrs = new List<string> { "name" };
|
||||
|
||||
|
||||
private static readonly List<string> _enumItemOptionalAttrs = new List<string> { "value", "alias", "comment" };
|
||||
private static readonly List<string> _enumItemOptionalAttrs = new List<string> { "value", "alias", "comment", "attrs" };
|
||||
private static readonly List<string> _enumItemRequiredAttrs = new List<string> { "name" };
|
||||
|
||||
protected void AddEnum(XElement e)
|
||||
|
|
@ -350,6 +352,7 @@ namespace Luban.Job.Common.Defs
|
|||
Namespace = CurNamespace,
|
||||
Comment = XmlUtil.GetOptionalAttribute(e, "comment"),
|
||||
IsFlags = XmlUtil.GetOptionBoolAttribute(e, "flags"),
|
||||
Attrs = XmlUtil.GetOptionalAttribute(e, "attrs"),
|
||||
};
|
||||
|
||||
foreach (XElement item in e.Elements())
|
||||
|
|
@ -361,6 +364,7 @@ namespace Luban.Job.Common.Defs
|
|||
Alias = XmlUtil.GetOptionalAttribute(item, "alias"),
|
||||
Value = XmlUtil.GetOptionalAttribute(item, "value"),
|
||||
Comment = XmlUtil.GetOptionalAttribute(item, "comment"),
|
||||
Attrs = XmlUtil.GetOptionalAttribute(item, "attrs"),
|
||||
});
|
||||
}
|
||||
s_logger.Trace("add enum:{@enum}", en);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
using Luban.Common.Utils;
|
||||
using Luban.Job.Common.Types;
|
||||
using Luban.Job.Common.Utils;
|
||||
using Luban.Server.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -128,9 +129,11 @@ namespace Luban.Job.Common.Defs
|
|||
}
|
||||
}
|
||||
|
||||
protected TType CreateNotContainerType(string module, string type)
|
||||
protected TType CreateNotContainerType(string module, string rawType)
|
||||
{
|
||||
bool nullable;
|
||||
var (type, attrs) = DefUtil.ParseType(rawType);
|
||||
|
||||
if (type.EndsWith('?'))
|
||||
{
|
||||
if (!SupportNullable)
|
||||
|
|
@ -146,33 +149,33 @@ namespace Luban.Job.Common.Defs
|
|||
}
|
||||
switch (type)
|
||||
{
|
||||
case "bool": return nullable ? TBool.NullableIns : TBool.Ins;
|
||||
case "bool": return attrs == null ? (nullable ? TBool.NullableIns : TBool.Ins) : new TBool(nullable) { Attrs = attrs };
|
||||
case "uint8":
|
||||
case "byte": return nullable ? TByte.NullableIns : TByte.Ins;
|
||||
case "byte": return attrs == null ? (nullable ? TByte.NullableIns : TByte.Ins) : new TByte(nullable) { Attrs = attrs };
|
||||
case "int16":
|
||||
case "short": return nullable ? TShort.NullableIns : TShort.Ins;
|
||||
case "short": return attrs == null ? (nullable ? TShort.NullableIns : TShort.Ins) : new TShort(nullable) { Attrs = attrs };
|
||||
case "fint16":
|
||||
case "fshort": return nullable ? TFshort.NullableIns : TFshort.Ins;
|
||||
case "fshort": return attrs == null ? (nullable ? TFshort.NullableIns : TFshort.Ins) : new TFshort(nullable) { Attrs = attrs };
|
||||
case "int32":
|
||||
case "int": return nullable ? TInt.NullableIns : TInt.Ins;
|
||||
case "int": return attrs == null ? (nullable ? TInt.NullableIns : TInt.Ins) : new TInt(nullable) { Attrs = attrs };
|
||||
case "fint32":
|
||||
case "fint": return nullable ? TFint.NullableIns : TFint.Ins;
|
||||
case "fint": return attrs == null ? (nullable ? TFint.NullableIns : TFint.Ins) : new TFint(nullable) { Attrs = attrs };
|
||||
case "int64":
|
||||
case "long": return nullable ? TLong.NullableIns : TLong.Ins;
|
||||
case "bigint": return nullable ? TLong.NullableBigIns : TLong.BigIns;
|
||||
case "long": return attrs == null ? (nullable ? TLong.NullableIns : TLong.Ins) : new TLong(nullable, false) { Attrs = attrs };
|
||||
case "bigint": return attrs == null ? (nullable ? TLong.NullableBigIns : TLong.BigIns) : new TLong(nullable, true) { Attrs = attrs };
|
||||
case "fint64":
|
||||
case "flong": return nullable ? TFlong.NullableIns : TFlong.Ins;
|
||||
case "flong": return attrs == null ? (nullable ? TFlong.NullableIns : TFlong.Ins) : new TFlong(nullable) { Attrs = attrs };
|
||||
case "float32":
|
||||
case "float": return nullable ? TFloat.NullableIns : TFloat.Ins;
|
||||
case "float": return attrs == null ? (nullable ? TFloat.NullableIns : TFloat.Ins) : new TFloat(nullable) { Attrs = attrs };
|
||||
case "float64":
|
||||
case "double": return nullable ? TDouble.NullableIns : TDouble.Ins;
|
||||
case "bytes": return TBytes.Ins;
|
||||
case "string": return nullable ? TString.NullableIns : TString.Ins;
|
||||
case "text": return nullable ? TText.NullableIns : TText.Ins;
|
||||
case "vector2": return nullable ? TVector2.NullableIns : TVector2.Ins;
|
||||
case "vector3": return nullable ? TVector3.NullableIns : TVector3.Ins;
|
||||
case "vector4": return nullable ? TVector4.NullableIns : TVector4.Ins;
|
||||
case "datetime": return SupportDatetimeType ? (nullable ? TDateTime.NullableIns : TDateTime.Ins) : throw new NotSupportedException($"只有配置支持datetime数据类型");
|
||||
case "double": return attrs == null ? (nullable ? TDouble.NullableIns : TDouble.Ins) : new TDouble(nullable) { Attrs = attrs };
|
||||
case "bytes": return attrs == null ? (nullable ? new TBytes(true) : TBytes.Ins) : new TBytes(false) { Attrs = attrs };
|
||||
case "string": return attrs == null ? (nullable ? TString.NullableIns : TString.Ins) : new TString(nullable) { Attrs = attrs };
|
||||
case "text": return attrs == null ? (nullable ? TText.NullableIns : TText.Ins) : new TText(nullable) { Attrs = attrs };
|
||||
case "vector2": return attrs == null ? (nullable ? TVector2.NullableIns : TVector2.Ins) : new TVector2(nullable) { Attrs = attrs };
|
||||
case "vector3": return attrs == null ? (nullable ? TVector3.NullableIns : TVector3.Ins) : new TVector3(nullable) { Attrs = attrs };
|
||||
case "vector4": return attrs == null ? (nullable ? TVector4.NullableIns : TVector4.Ins) : new TVector4(nullable) { Attrs = attrs };
|
||||
case "datetime": return SupportDatetimeType ? (attrs == null ? (nullable ? TDateTime.NullableIns : TDateTime.Ins) : new TDateTime(nullable) { Attrs = attrs }) : throw new NotSupportedException($"只有配置支持datetime数据类型");
|
||||
default:
|
||||
{
|
||||
var dtype = GetDefTType(module, type, nullable);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Luban.Job.Common.RawDefs;
|
||||
using Luban.Job.Common.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
|
@ -50,6 +51,7 @@ namespace Luban.Job.Common.Defs
|
|||
Id = b.TypeId;
|
||||
IsValueType = b.IsValueType;
|
||||
Comment = b.Comment;
|
||||
Attrs = DefUtil.ParseAttrs(b.Attrs);
|
||||
foreach (var field in b.Fields)
|
||||
{
|
||||
Fields.Add(CreateField(field, 0));
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Luban.Job.Common.RawDefs;
|
||||
using Luban.Job.Common.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
|
@ -21,15 +22,27 @@ namespace Luban.Job.Common.Defs
|
|||
public int IntValue { get; set; }
|
||||
|
||||
public string Comment { get; init; }
|
||||
|
||||
public Dictionary<string, string> Attrs { get; init; }
|
||||
|
||||
public bool HasAttr(string attrName)
|
||||
{
|
||||
return Attrs != null && Attrs.ContainsKey(attrName);
|
||||
}
|
||||
|
||||
public bool IsFlags { get; set; }
|
||||
public string GetAttr(string attrName)
|
||||
{
|
||||
return Attrs != null && Attrs.TryGetValue(attrName, out var value) ? value : null;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsUniqueItemId { get; set; }
|
||||
public bool IsFlags { get; }
|
||||
|
||||
public List<Item> Items { get; set; } = new List<Item>();
|
||||
public bool IsUniqueItemId { get; }
|
||||
|
||||
private readonly Dictionary<string, int> _nameOrAlias2Value = new Dictionary<string, int>();
|
||||
public List<Item> Items { get; } = new List<Item>();
|
||||
|
||||
private readonly Dictionary<string, int> _nameOrAlias2Value = new();
|
||||
|
||||
public bool TryValueByNameOrAlias(string name, out int value)
|
||||
{
|
||||
|
|
@ -71,6 +84,7 @@ namespace Luban.Job.Common.Defs
|
|||
IsFlags = e.IsFlags;
|
||||
IsUniqueItemId = e.IsUniqueItemId;
|
||||
Comment = e.Comment;
|
||||
Attrs = DefUtil.ParseAttrs(e.Attrs);
|
||||
|
||||
foreach (var item in e.Items)
|
||||
{
|
||||
|
|
@ -81,6 +95,7 @@ namespace Luban.Job.Common.Defs
|
|||
Alias = item.Alias,
|
||||
Value = item.Value,
|
||||
Comment = string.IsNullOrWhiteSpace(item.Comment) ? item.Alias : item.Comment,
|
||||
Attrs = DefUtil.ParseAttrs(item.Attrs),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using Luban.Common.Utils;
|
||||
using Luban.Job.Common.RawDefs;
|
||||
using Luban.Job.Common.Types;
|
||||
using Luban.Job.Common.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
|
@ -71,6 +72,18 @@ namespace Luban.Job.Common.Defs
|
|||
|
||||
public string Comment { get; }
|
||||
|
||||
public Dictionary<string, string> Attrs { get; }
|
||||
|
||||
public bool HasAttr(string attrName)
|
||||
{
|
||||
return Attrs != null && Attrs.ContainsKey(attrName);
|
||||
}
|
||||
|
||||
public string GetAttr(string attrName)
|
||||
{
|
||||
return Attrs != null && Attrs.TryGetValue(attrName, out var value) ? value : null;
|
||||
}
|
||||
|
||||
public DefFieldBase(DefTypeBase host, Field f, int idOffset)
|
||||
{
|
||||
HostType = host;
|
||||
|
|
@ -78,6 +91,7 @@ namespace Luban.Job.Common.Defs
|
|||
Name = f.Name;
|
||||
Type = f.Type;
|
||||
Comment = f.Comment;
|
||||
Attrs = DefUtil.ParseAttrs(f.Attrs);
|
||||
}
|
||||
|
||||
public virtual void Compile()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using Luban.Common.Utils;
|
||||
using Luban.Server.Common;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Luban.Job.Common.Defs
|
||||
{
|
||||
|
|
@ -45,6 +46,18 @@ namespace Luban.Job.Common.Defs
|
|||
|
||||
public string Comment { get; protected set; }
|
||||
|
||||
public Dictionary<string, string> Attrs { get; protected set; }
|
||||
|
||||
public bool HasAttr(string attrName)
|
||||
{
|
||||
return Attrs != null && Attrs.ContainsKey(attrName);
|
||||
}
|
||||
|
||||
public string GetAttr(string attrName)
|
||||
{
|
||||
return Attrs != null && Attrs.TryGetValue(attrName, out var value) ? value : null;
|
||||
}
|
||||
|
||||
public virtual void PreCompile() { }
|
||||
|
||||
public abstract void Compile();
|
||||
|
|
|
|||
|
|
@ -162,5 +162,15 @@ namespace Luban.Job.Common.Defs
|
|||
{
|
||||
return type.Apply(LuaConstValueVisitor.Ins, value);
|
||||
}
|
||||
|
||||
public static bool HasAttr(dynamic obj, string attrName)
|
||||
{
|
||||
return obj.HasAttr(attrName);
|
||||
}
|
||||
|
||||
public static string GetAttr(dynamic obj, string attrName)
|
||||
{
|
||||
return obj.GetAttr(attrName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ namespace Luban.Job.Common.RawDefs
|
|||
|
||||
public string Comment { get; set; }
|
||||
|
||||
public string Attrs { get; set; }
|
||||
|
||||
public List<Field> Fields { get; set; } = new List<Field>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,5 +10,7 @@ namespace Luban.Job.Common.RawDefs
|
|||
public string Type { get; set; }
|
||||
|
||||
public string Comment { get; set; }
|
||||
|
||||
public string Attrs { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ namespace Luban.Job.Common.RawDefs
|
|||
public string Value { get; set; }
|
||||
|
||||
public string Comment { get; set; }
|
||||
|
||||
public string Attrs { get; set; }
|
||||
}
|
||||
|
||||
public class PEnum
|
||||
|
|
@ -26,6 +28,8 @@ namespace Luban.Job.Common.RawDefs
|
|||
|
||||
public string Comment { get; set; }
|
||||
|
||||
public string Attrs { get; set; }
|
||||
|
||||
public List<EnumItem> Items { get; set; } = new List<EnumItem>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Luban.Job.Common.TypeVisitors;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Luban.Job.Common.Types
|
||||
{
|
||||
|
|
@ -11,6 +12,18 @@ namespace Luban.Job.Common.Types
|
|||
IsNullable = isNullable;
|
||||
}
|
||||
|
||||
public Dictionary<string, string> Attrs { get; set; }
|
||||
|
||||
public bool HasAttr(string attrName)
|
||||
{
|
||||
return Attrs != null && Attrs.ContainsKey(attrName);
|
||||
}
|
||||
|
||||
public string GetAttr(string attrName)
|
||||
{
|
||||
return Attrs != null && Attrs.TryGetValue(attrName, out var value) ? value : null;
|
||||
}
|
||||
|
||||
public abstract bool TryParseFrom(string s);
|
||||
|
||||
public virtual bool IsCollection => false;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Luban.Job.Common.Utils
|
||||
{
|
||||
public class DefUtil
|
||||
{
|
||||
private readonly static char[] s_attrSep = new char[] { '|', '#', '&' };
|
||||
|
||||
private readonly static char[] s_attrKeyValueSep = new char[] { '=', ':' };
|
||||
|
||||
public static Dictionary<string, string> ParseAttrs(string attrs)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(attrs))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var am = new Dictionary<string, string>();
|
||||
foreach (var pair in attrs.Split(s_attrSep))
|
||||
{
|
||||
int sepIndex = pair.IndexOfAny(s_attrKeyValueSep);
|
||||
if (sepIndex >= 0)
|
||||
{
|
||||
am.Add(pair[..sepIndex].Trim(), pair[(sepIndex + 1)..].Trim());
|
||||
}
|
||||
else
|
||||
{
|
||||
am.Add(pair.Trim(), pair.Trim());
|
||||
}
|
||||
}
|
||||
return am;
|
||||
}
|
||||
|
||||
public static (string, Dictionary<string, string>) ParseType(string s)
|
||||
{
|
||||
int sepIndex = s.IndexOfAny(s_attrSep);
|
||||
if (sepIndex < 0)
|
||||
{
|
||||
return (s, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (s[..sepIndex], ParseAttrs(s[(sepIndex + 1)..]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue