From 2685a4d5d4c08f0e4d3bc6841072c31af23ee9f6 Mon Sep 17 00:00:00 2001 From: walon Date: Fri, 27 Aug 2021 10:15:34 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E9=87=8D=E6=9E=84=E3=80=91=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E5=88=9B=E5=BB=BATType=E5=AF=B9=E8=B1=A1=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E3=80=82=E5=8F=AA=E5=85=81=E8=AE=B8=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E5=B7=A5=E5=8E=82=E6=A8=A1=E5=BC=8F=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs | 6 +- src/Luban.Job.Cfg/Source/l10n/TextTable.cs | 2 +- .../Source/Defs/DefAssemblyBase.cs | 56 +++++++++---------- src/Luban.Job.Common/Source/Types/TArray.cs | 9 ++- src/Luban.Job.Common/Source/Types/TBean.cs | 8 ++- src/Luban.Job.Common/Source/Types/TBool.cs | 18 +++++- src/Luban.Job.Common/Source/Types/TByte.cs | 19 ++++++- src/Luban.Job.Common/Source/Types/TBytes.cs | 17 +++++- .../Source/Types/TDateTime.cs | 19 ++++++- src/Luban.Job.Common/Source/Types/TDouble.cs | 19 ++++++- src/Luban.Job.Common/Source/Types/TEnum.cs | 8 ++- src/Luban.Job.Common/Source/Types/TFint.cs | 19 ++++++- src/Luban.Job.Common/Source/Types/TFloat.cs | 19 ++++++- src/Luban.Job.Common/Source/Types/TFlong.cs | 19 ++++++- src/Luban.Job.Common/Source/Types/TFshort.cs | 19 ++++++- src/Luban.Job.Common/Source/Types/TInt.cs | 19 ++++++- src/Luban.Job.Common/Source/Types/TList.cs | 8 ++- src/Luban.Job.Common/Source/Types/TLong.cs | 23 ++++++-- src/Luban.Job.Common/Source/Types/TMap.cs | 8 ++- src/Luban.Job.Common/Source/Types/TSet.cs | 8 ++- src/Luban.Job.Common/Source/Types/TShort.cs | 19 ++++++- src/Luban.Job.Common/Source/Types/TString.cs | 19 ++++++- src/Luban.Job.Common/Source/Types/TText.cs | 19 ++++++- src/Luban.Job.Common/Source/Types/TType.cs | 7 ++- src/Luban.Job.Common/Source/Types/TVector2.cs | 19 ++++++- src/Luban.Job.Common/Source/Types/TVector3.cs | 23 ++++++-- src/Luban.Job.Common/Source/Types/TVector4.cs | 19 ++++++- 28 files changed, 354 insertions(+), 95 deletions(-) diff --git a/README.md b/README.md index e2cdbc6..921e9fa 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ Luban适合有以下需求的开发者: - 支持res资源标记。可以一键导出配置中引用的所有资源列表(icon,ui,assetbundle等等) - 统一了自定义编辑器的配置数据。与Unity和UE4的自定义编辑器良好配合,为编辑器生成合适的加载与保存json配置的的c#(Unity)或c++(UE4)代码。保存的json配置能够被luban识别和处理。 - 支持emmylua anntations。生成的lua包含符合emmylua 格式anntations信息。配合emmylua有良好的配置代码提示能力 +- 灵活的自定义生成能力。可以在不修改代码的情况下使用自定义模板取代默认生成模板。大多数自定义对象支持tags属性,允许通过tags生成特殊内容。 - **本地化支持** - 支持时间本地化。datetime类型数据会根据指定的timezone,转换为目标地区该时刻的UTC时间,方便程序使用。 - 支持文本静态本地化。导出时所有text类型数据正确替换为最终的本地化字符串。绝大多数的业务功能不再需要运行根据本地化id去查找文本的内容,简化程序员的工作。 diff --git a/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs b/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs index 52c0dfc..3dd119c 100644 --- a/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs +++ b/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs @@ -464,7 +464,7 @@ namespace Luban.Job.Cfg.Defs defTableRecordType.PreCompile(); defTableRecordType.Compile(); defTableRecordType.PostCompile(); - var tableRecordType = new TBean(defTableRecordType, false); + var tableRecordType = TBean.Create(false, defTableRecordType); foreach (var file in inputFileInfos) { @@ -530,7 +530,7 @@ namespace Luban.Job.Cfg.Defs defTableRecordType.PreCompile(); defTableRecordType.Compile(); defTableRecordType.PostCompile(); - var tableRecordType = new TBean(defTableRecordType, false); + var tableRecordType = TBean.Create(false, defTableRecordType); foreach (var file in inputFileInfos) { @@ -643,7 +643,7 @@ namespace Luban.Job.Cfg.Defs defTableRecordType.Compile(); defTableRecordType.PostCompile(); ass.MarkMultiRows(); - var tableRecordType = new TBean(defTableRecordType, false); + var tableRecordType = TBean.Create(false, defTableRecordType); foreach (var file in inputFileInfos) { diff --git a/src/Luban.Job.Cfg/Source/l10n/TextTable.cs b/src/Luban.Job.Cfg/Source/l10n/TextTable.cs index d17013c..bd93305 100644 --- a/src/Luban.Job.Cfg/Source/l10n/TextTable.cs +++ b/src/Luban.Job.Cfg/Source/l10n/TextTable.cs @@ -53,7 +53,7 @@ namespace Luban.Job.Cfg.l10n defTextRowType.PreCompile(); defTextRowType.Compile(); defTextRowType.PostCompile(); - _textRowType = new TBean(defTextRowType, false); + _textRowType = TBean.Create(false, defTextRowType); } public void AddText(string key, string text) diff --git a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs index 16a5a6f..e3e42f1 100644 --- a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs +++ b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs @@ -83,7 +83,7 @@ namespace Luban.Job.Common.Defs } else { - return cacheDefTTypes[(defType, nullable)] = new TEnum(defType, nullable); + return cacheDefTTypes[(defType, nullable)] = TEnum.Create(nullable, defType); } } @@ -95,7 +95,7 @@ namespace Luban.Job.Common.Defs } else { - return cacheDefTTypes[(defType, nullable)] = new TBean((DefBeanBase)defType, nullable); + return cacheDefTTypes[(defType, nullable)] = TBean.Create(nullable, (DefBeanBase)defType); } } @@ -149,33 +149,33 @@ namespace Luban.Job.Common.Defs } switch (type) { - case "bool": return tags == null ? (nullable ? TBool.NullableIns : TBool.Ins) : new TBool(nullable) { Tags = tags }; + case "bool": return TBool.Create(nullable, tags); case "uint8": - case "byte": return tags == null ? (nullable ? TByte.NullableIns : TByte.Ins) : new TByte(nullable) { Tags = tags }; + case "byte": return TByte.Create(nullable, tags); case "int16": - case "short": return tags == null ? (nullable ? TShort.NullableIns : TShort.Ins) : new TShort(nullable) { Tags = tags }; + case "short": return TShort.Create(nullable, tags); case "fint16": - case "fshort": return tags == null ? (nullable ? TFshort.NullableIns : TFshort.Ins) : new TFshort(nullable) { Tags = tags }; + case "fshort": return TFshort.Create(nullable, tags); case "int32": - case "int": return tags == null ? (nullable ? TInt.NullableIns : TInt.Ins) : new TInt(nullable) { Tags = tags }; + case "int": return TInt.Create(nullable, tags); case "fint32": - case "fint": return tags == null ? (nullable ? TFint.NullableIns : TFint.Ins) : new TFint(nullable) { Tags = tags }; + case "fint": return TFint.Create(nullable, tags); case "int64": - case "long": return tags == null ? (nullable ? TLong.NullableIns : TLong.Ins) : new TLong(nullable, false) { Tags = tags }; - case "bigint": return tags == null ? (nullable ? TLong.NullableBigIns : TLong.BigIns) : new TLong(nullable, true) { Tags = tags }; + case "long": return TLong.Create(nullable, tags, false); + case "bigint": return TLong.Create(nullable, tags, true); case "fint64": - case "flong": return tags == null ? (nullable ? TFlong.NullableIns : TFlong.Ins) : new TFlong(nullable) { Tags = tags }; + case "flong": return TFlong.Create(nullable, tags); case "float32": - case "float": return tags == null ? (nullable ? TFloat.NullableIns : TFloat.Ins) : new TFloat(nullable) { Tags = tags }; + case "float": return TFloat.Create(nullable, tags); case "float64": - case "double": return tags == null ? (nullable ? TDouble.NullableIns : TDouble.Ins) : new TDouble(nullable) { Tags = tags }; - case "bytes": return tags == null ? (nullable ? new TBytes(true) : TBytes.Ins) : new TBytes(false) { Tags = tags }; - case "string": return tags == null ? (nullable ? TString.NullableIns : TString.Ins) : new TString(nullable) { Tags = tags }; - case "text": return tags == null ? (nullable ? TText.NullableIns : TText.Ins) : new TText(nullable) { Tags = tags }; - case "vector2": return tags == null ? (nullable ? TVector2.NullableIns : TVector2.Ins) : new TVector2(nullable) { Tags = tags }; - case "vector3": return tags == null ? (nullable ? TVector3.NullableIns : TVector3.Ins) : new TVector3(nullable) { Tags = tags }; - case "vector4": return tags == null ? (nullable ? TVector4.NullableIns : TVector4.Ins) : new TVector4(nullable) { Tags = tags }; - case "datetime": return SupportDatetimeType ? (tags == null ? (nullable ? TDateTime.NullableIns : TDateTime.Ins) : new TDateTime(nullable) { Tags = tags }) : throw new NotSupportedException($"只有配置支持datetime数据类型"); + case "double": return TDouble.Create(nullable, tags); + case "bytes": return TBytes.Create(nullable, tags); + case "string": return TString.Create(nullable, tags); + case "text": return TText.Create(nullable, tags); + case "vector2": return TVector2.Create(nullable, tags); + case "vector3": return TVector3.Create(nullable, tags); + case "vector4": return TVector4.Create(nullable, tags); + case "datetime": return SupportDatetimeType ? TDateTime.Create(nullable, tags) : throw new NotSupportedException($"只有配置支持datetime数据类型"); default: { var dtype = GetDefTType(module, type, nullable); @@ -198,20 +198,20 @@ namespace Luban.Job.Common.Defs { throw new ArgumentException($"invalid map element type:'{keyValueType}'"); } - return new TMap(CreateNotContainerType(module, elementTypes[0]), CreateNotContainerType(module, elementTypes[1]), isTreeMap); + return TMap.Create(false, null, CreateNotContainerType(module, elementTypes[0]), CreateNotContainerType(module, elementTypes[1]), isTreeMap); } protected TType CreateContainerType(string module, string containerType, string elementType) { switch (containerType) { - case "array": return new TArray(CreateNotContainerType(module, elementType)); - case "list": return new TList(CreateNotContainerType(module, elementType), false); - case "linkedlist": return new TList(CreateNotContainerType(module, elementType), true); - case "arraylist": return new TList(CreateNotContainerType(module, elementType), false); - case "set": return new TSet(CreateNotContainerType(module, elementType), false); - case "hashset": return new TSet(CreateNotContainerType(module, elementType), true); - case "treeset": return new TSet(CreateNotContainerType(module, elementType), false); + case "array": return TArray.Create(false, null, CreateNotContainerType(module, elementType)); + case "list": return TList.Create(false, null, CreateNotContainerType(module, elementType), true); + case "linkedlist": return TList.Create(false, null, CreateNotContainerType(module, elementType), false); + case "arraylist": return TList.Create(false, null, CreateNotContainerType(module, elementType), true); + case "set": return TSet.Create(false, null, CreateNotContainerType(module, elementType), false); + case "hashset": return TSet.Create(false, null, CreateNotContainerType(module, elementType), false); + case "treeset": return TSet.Create(false, null, CreateNotContainerType(module, elementType), true); case "map": return CreateMapType(module, elementType, false); case "treemap": return CreateMapType(module, elementType, true); case "hashmap": return CreateMapType(module, elementType, false); diff --git a/src/Luban.Job.Common/Source/Types/TArray.cs b/src/Luban.Job.Common/Source/Types/TArray.cs index a283854..f1cea66 100644 --- a/src/Luban.Job.Common/Source/Types/TArray.cs +++ b/src/Luban.Job.Common/Source/Types/TArray.cs @@ -1,13 +1,20 @@ using Luban.Job.Common.TypeVisitors; using System; +using System.Collections.Generic; namespace Luban.Job.Common.Types { public class TArray : TType { + + public static TArray Create(bool isNullable, Dictionary tags, TType elementType) + { + return new TArray(isNullable, tags, elementType); + } + public TType ElementType { get; } - public TArray(TType elementType) : base(false) + private TArray(bool isNullable, Dictionary tags, TType elementType) : base(isNullable, tags) { ElementType = elementType; } diff --git a/src/Luban.Job.Common/Source/Types/TBean.cs b/src/Luban.Job.Common/Source/Types/TBean.cs index 789f0e4..ff1e1f3 100644 --- a/src/Luban.Job.Common/Source/Types/TBean.cs +++ b/src/Luban.Job.Common/Source/Types/TBean.cs @@ -1,16 +1,22 @@ using Luban.Job.Common.Defs; using Luban.Job.Common.TypeVisitors; using System; +using System.Collections.Generic; namespace Luban.Job.Common.Types { public class TBean : TType { + public static TBean Create(bool isNullable, DefBeanBase defBean) + { + return new TBean(isNullable, defBean.Tags, defBean); + } + public DefBeanBase Bean { get; set; } public T GetBeanAs() where T : DefBeanBase => (T)Bean; - public TBean(DefBeanBase defBean, bool isNullable) : base(isNullable) + private TBean(bool isNullable, Dictionary attrs, DefBeanBase defBean) : base(isNullable, attrs) { this.Bean = defBean; } diff --git a/src/Luban.Job.Common/Source/Types/TBool.cs b/src/Luban.Job.Common/Source/Types/TBool.cs index d891840..d9957cc 100644 --- a/src/Luban.Job.Common/Source/Types/TBool.cs +++ b/src/Luban.Job.Common/Source/Types/TBool.cs @@ -1,15 +1,27 @@ using Luban.Job.Common.TypeVisitors; +using System.Collections.Generic; namespace Luban.Job.Common.Types { public class TBool : TType { + private static TBool Ins { get; } = new TBool(false, null); - public static TBool Ins { get; } = new TBool(false); + private static TBool NullableIns { get; } = new TBool(true, null); - public static TBool NullableIns { get; } = new TBool(true); + public static TBool Create(bool isNullable, Dictionary tags) + { + if (tags == null) + { + return isNullable ? NullableIns : Ins; + } + else + { + return new TBool(isNullable, tags); + } + } - public TBool(bool isNullable) : base(isNullable) + private TBool(bool isNullable, Dictionary tags) : base(isNullable, tags) { } diff --git a/src/Luban.Job.Common/Source/Types/TByte.cs b/src/Luban.Job.Common/Source/Types/TByte.cs index c567b03..74f8f7a 100644 --- a/src/Luban.Job.Common/Source/Types/TByte.cs +++ b/src/Luban.Job.Common/Source/Types/TByte.cs @@ -1,14 +1,27 @@ using Luban.Job.Common.TypeVisitors; +using System.Collections.Generic; namespace Luban.Job.Common.Types { public class TByte : TType { - public static TByte Ins { get; } = new TByte(false); + private static TByte Ins { get; } = new TByte(false, null); - public static TByte NullableIns { get; } = new TByte(true); + private static TByte NullableIns { get; } = new TByte(true, null); - public TByte(bool isNullable) : base(isNullable) + public static TByte Create(bool isNullable, Dictionary tags) + { + if (tags == null) + { + return isNullable ? NullableIns : Ins; + } + else + { + return new TByte(isNullable, tags); + } + } + + private TByte(bool isNullable, Dictionary tags) : base(isNullable, tags) { } diff --git a/src/Luban.Job.Common/Source/Types/TBytes.cs b/src/Luban.Job.Common/Source/Types/TBytes.cs index 68253b8..5f23e1f 100644 --- a/src/Luban.Job.Common/Source/Types/TBytes.cs +++ b/src/Luban.Job.Common/Source/Types/TBytes.cs @@ -1,13 +1,26 @@ using Luban.Job.Common.TypeVisitors; using System; +using System.Collections.Generic; namespace Luban.Job.Common.Types { public class TBytes : TType { - public static TBytes Ins { get; } = new TBytes(false); + private static TBytes Ins { get; } = new TBytes(false, null); - public TBytes(bool isNullable) : base(isNullable) + public static TBytes Create(bool isNullable, Dictionary tags) + { + if (tags == null) + { + return isNullable ? new TBytes(true, null) : Ins; + } + else + { + return new TBytes(isNullable, tags); + } + } + + private TBytes(bool isNullable, Dictionary tags) : base(isNullable, tags) { } diff --git a/src/Luban.Job.Common/Source/Types/TDateTime.cs b/src/Luban.Job.Common/Source/Types/TDateTime.cs index b707bf9..4ddb289 100644 --- a/src/Luban.Job.Common/Source/Types/TDateTime.cs +++ b/src/Luban.Job.Common/Source/Types/TDateTime.cs @@ -1,15 +1,28 @@ using Luban.Job.Common.TypeVisitors; using System; +using System.Collections.Generic; namespace Luban.Job.Common.Types { public class TDateTime : TType { - public static TDateTime Ins { get; } = new TDateTime(false); + private static TDateTime Ins { get; } = new TDateTime(false, null); - public static TDateTime NullableIns { get; } = new TDateTime(true); + private static TDateTime NullableIns { get; } = new TDateTime(true, null); - public TDateTime(bool isNullable) : base(isNullable) + public static TDateTime Create(bool isNullable, Dictionary tags) + { + if (tags == null) + { + return isNullable ? NullableIns : Ins; + } + else + { + return new TDateTime(isNullable, tags); + } + } + + private TDateTime(bool isNullable, Dictionary tags) : base(isNullable, tags) { } diff --git a/src/Luban.Job.Common/Source/Types/TDouble.cs b/src/Luban.Job.Common/Source/Types/TDouble.cs index 24a7d0b..da36ad2 100644 --- a/src/Luban.Job.Common/Source/Types/TDouble.cs +++ b/src/Luban.Job.Common/Source/Types/TDouble.cs @@ -1,14 +1,27 @@ using Luban.Job.Common.TypeVisitors; +using System.Collections.Generic; namespace Luban.Job.Common.Types { public class TDouble : TType { - public static TDouble Ins { get; } = new TDouble(false); + private static TDouble Ins { get; } = new TDouble(false, null); - public static TDouble NullableIns { get; } = new TDouble(true); + private static TDouble NullableIns { get; } = new TDouble(true, null); - public TDouble(bool isNullable) : base(isNullable) + public static TDouble Create(bool isNullable, Dictionary tags) + { + if (tags == null) + { + return isNullable ? NullableIns : Ins; + } + else + { + return new TDouble(isNullable, tags); + } + } + + private TDouble(bool isNullable, Dictionary tags) : base(isNullable, tags) { } diff --git a/src/Luban.Job.Common/Source/Types/TEnum.cs b/src/Luban.Job.Common/Source/Types/TEnum.cs index 418f195..298b49f 100644 --- a/src/Luban.Job.Common/Source/Types/TEnum.cs +++ b/src/Luban.Job.Common/Source/Types/TEnum.cs @@ -1,14 +1,20 @@ using Luban.Job.Common.Defs; using Luban.Job.Common.TypeVisitors; using System; +using System.Collections.Generic; namespace Luban.Job.Common.Types { public class TEnum : TType { + public static TEnum Create(bool isNullable, DefEnum defEnum) + { + return new TEnum(isNullable, defEnum.Tags, defEnum); + } + public DefEnum DefineEnum { get; } - public TEnum(DefEnum defEnum, bool isNullable) : base(isNullable) + private TEnum(bool isNullable, Dictionary tags, DefEnum defEnum) : base(isNullable, tags) { this.DefineEnum = defEnum; } diff --git a/src/Luban.Job.Common/Source/Types/TFint.cs b/src/Luban.Job.Common/Source/Types/TFint.cs index 3947ace..7bba5db 100644 --- a/src/Luban.Job.Common/Source/Types/TFint.cs +++ b/src/Luban.Job.Common/Source/Types/TFint.cs @@ -1,14 +1,27 @@ using Luban.Job.Common.TypeVisitors; +using System.Collections.Generic; namespace Luban.Job.Common.Types { public class TFint : TType { - public static TFint Ins { get; } = new TFint(false); + private static TFint Ins { get; } = new TFint(false, null); - public static TFint NullableIns { get; } = new TFint(true); + private static TFint NullableIns { get; } = new TFint(true, null); - public TFint(bool isNullable) : base(isNullable) + public static TFint Create(bool isNullable, Dictionary tags) + { + if (tags == null) + { + return isNullable ? NullableIns : Ins; + } + else + { + return new TFint(isNullable, tags); + } + } + + private TFint(bool isNullable, Dictionary tags) : base(isNullable, tags) { } diff --git a/src/Luban.Job.Common/Source/Types/TFloat.cs b/src/Luban.Job.Common/Source/Types/TFloat.cs index a6aebb7..00e1644 100644 --- a/src/Luban.Job.Common/Source/Types/TFloat.cs +++ b/src/Luban.Job.Common/Source/Types/TFloat.cs @@ -1,14 +1,27 @@ using Luban.Job.Common.TypeVisitors; +using System.Collections.Generic; namespace Luban.Job.Common.Types { public class TFloat : TType { - public static TFloat Ins { get; } = new TFloat(false); + public static TFloat Ins { get; } = new TFloat(false, null); - public static TFloat NullableIns { get; } = new TFloat(true); + private static TFloat NullableIns { get; } = new TFloat(true, null); - public TFloat(bool isNullable) : base(isNullable) + public static TFloat Create(bool isNullable, Dictionary tags) + { + if (tags == null) + { + return isNullable ? NullableIns : Ins; + } + else + { + return new TFloat(isNullable, tags); + } + } + + private TFloat(bool isNullable, Dictionary tags) : base(isNullable, tags) { } diff --git a/src/Luban.Job.Common/Source/Types/TFlong.cs b/src/Luban.Job.Common/Source/Types/TFlong.cs index c507c52..3855652 100644 --- a/src/Luban.Job.Common/Source/Types/TFlong.cs +++ b/src/Luban.Job.Common/Source/Types/TFlong.cs @@ -1,14 +1,27 @@ using Luban.Job.Common.TypeVisitors; +using System.Collections.Generic; namespace Luban.Job.Common.Types { public class TFlong : TType { - public static TFlong Ins { get; } = new TFlong(false); + private static TFlong Ins { get; } = new TFlong(false, null); - public static TFlong NullableIns { get; } = new TFlong(true); + private static TFlong NullableIns { get; } = new TFlong(true, null); - public TFlong(bool isNullable) : base(isNullable) + public static TFlong Create(bool isNullable, Dictionary tags) + { + if (tags == null) + { + return isNullable ? NullableIns : Ins; + } + else + { + return new TFlong(isNullable, tags); + } + } + + private TFlong(bool isNullable, Dictionary tags) : base(isNullable, tags) { } diff --git a/src/Luban.Job.Common/Source/Types/TFshort.cs b/src/Luban.Job.Common/Source/Types/TFshort.cs index 8b9185e..93e5ee5 100644 --- a/src/Luban.Job.Common/Source/Types/TFshort.cs +++ b/src/Luban.Job.Common/Source/Types/TFshort.cs @@ -1,14 +1,27 @@ using Luban.Job.Common.TypeVisitors; +using System.Collections.Generic; namespace Luban.Job.Common.Types { public class TFshort : TType { - public static TFshort Ins { get; } = new TFshort(false); + private static TFshort Ins { get; } = new TFshort(false, null); - public static TFshort NullableIns { get; } = new TFshort(true); + private static TFshort NullableIns { get; } = new TFshort(true, null); - public TFshort(bool isNullable) : base(isNullable) + public static TFshort Create(bool isNullable, Dictionary tags) + { + if (tags == null) + { + return isNullable ? NullableIns : Ins; + } + else + { + return new TFshort(isNullable, tags); + } + } + + private TFshort(bool isNullable, Dictionary tags) : base(isNullable, tags) { } diff --git a/src/Luban.Job.Common/Source/Types/TInt.cs b/src/Luban.Job.Common/Source/Types/TInt.cs index 5ce31e8..981babc 100644 --- a/src/Luban.Job.Common/Source/Types/TInt.cs +++ b/src/Luban.Job.Common/Source/Types/TInt.cs @@ -1,14 +1,27 @@ using Luban.Job.Common.TypeVisitors; +using System.Collections.Generic; namespace Luban.Job.Common.Types { public class TInt : TType { - public static TInt Ins { get; } = new TInt(false); + private static TInt Ins { get; } = new TInt(false, null); - public static TInt NullableIns { get; } = new TInt(true); + private static TInt NullableIns { get; } = new TInt(true, null); - public TInt(bool isNullable) : base(isNullable) + public static TInt Create(bool isNullable, Dictionary tags) + { + if (tags == null) + { + return isNullable ? NullableIns : Ins; + } + else + { + return new TInt(isNullable, tags); + } + } + + private TInt(bool isNullable, Dictionary tags) : base(isNullable, tags) { } diff --git a/src/Luban.Job.Common/Source/Types/TList.cs b/src/Luban.Job.Common/Source/Types/TList.cs index 86f6ea2..dd0c2bf 100644 --- a/src/Luban.Job.Common/Source/Types/TList.cs +++ b/src/Luban.Job.Common/Source/Types/TList.cs @@ -1,15 +1,21 @@ using Luban.Job.Common.TypeVisitors; using System; +using System.Collections.Generic; namespace Luban.Job.Common.Types { public class TList : TType { + public static TList Create(bool isNullable, Dictionary tags, TType elementType, bool isArrayList) + { + return new TList(isNullable, tags, elementType, isArrayList); + } + public TType ElementType { get; } public bool IsArrayList { get; } - public TList(TType elementType, bool isArrayList) : base(false) + private TList(bool isNullable, Dictionary tags, TType elementType, bool isArrayList) : base(isNullable, tags) { ElementType = elementType; IsArrayList = isArrayList; diff --git a/src/Luban.Job.Common/Source/Types/TLong.cs b/src/Luban.Job.Common/Source/Types/TLong.cs index 8771ce9..7de448b 100644 --- a/src/Luban.Job.Common/Source/Types/TLong.cs +++ b/src/Luban.Job.Common/Source/Types/TLong.cs @@ -1,20 +1,33 @@ using Luban.Job.Common.TypeVisitors; +using System.Collections.Generic; namespace Luban.Job.Common.Types { public class TLong : TType { - public static TLong Ins { get; } = new TLong(false, false); + private static TLong Ins { get; } = new TLong(false, null, false); - public static TLong NullableIns { get; } = new TLong(true, false); + private static TLong NullableIns { get; } = new TLong(true, null, false); - public static TLong BigIns { get; } = new TLong(false, true); + private static TLong BigIns { get; } = new TLong(false, null, true); - public static TLong NullableBigIns { get; } = new TLong(true, true); + private static TLong NullableBigIns { get; } = new TLong(true, null, true); + + public static TLong Create(bool isNullable, Dictionary tags, bool isBigInt) + { + if (tags == null) + { + return isNullable ? NullableIns : Ins; + } + else + { + return new TLong(isNullable, tags, isBigInt); + } + } public bool IsBigInt { get; } - public TLong(bool isNullable, bool isBigInt) : base(isNullable) + private TLong(bool isNullable, Dictionary tags, bool isBigInt) : base(isNullable, tags) { IsBigInt = isBigInt; } diff --git a/src/Luban.Job.Common/Source/Types/TMap.cs b/src/Luban.Job.Common/Source/Types/TMap.cs index d7a5917..dc4969d 100644 --- a/src/Luban.Job.Common/Source/Types/TMap.cs +++ b/src/Luban.Job.Common/Source/Types/TMap.cs @@ -1,10 +1,16 @@ using Luban.Job.Common.TypeVisitors; using System; +using System.Collections.Generic; namespace Luban.Job.Common.Types { public class TMap : TType { + public static TMap Create(bool isNullable, Dictionary tags, TType keyType, TType valueType, bool isOrderedMap) + { + return new TMap(isNullable, tags, keyType, valueType, isOrderedMap); + } + public bool IsMap => true; public TType KeyType { get; } @@ -13,7 +19,7 @@ namespace Luban.Job.Common.Types public bool IsOrderedMap { get; } - public TMap(TType keyType, TType valueType, bool isOrderedMap) : base(false) + private TMap(bool isNullable, Dictionary tags, TType keyType, TType valueType, bool isOrderedMap) : base(isNullable, tags) { KeyType = keyType; ValueType = valueType; diff --git a/src/Luban.Job.Common/Source/Types/TSet.cs b/src/Luban.Job.Common/Source/Types/TSet.cs index 7a62acd..942f3bc 100644 --- a/src/Luban.Job.Common/Source/Types/TSet.cs +++ b/src/Luban.Job.Common/Source/Types/TSet.cs @@ -1,15 +1,21 @@ using Luban.Job.Common.TypeVisitors; using System; +using System.Collections.Generic; namespace Luban.Job.Common.Types { public class TSet : TType { + public static TSet Create(bool isNullable, Dictionary tags, TType elementType, bool isOrdered) + { + return new TSet(isNullable, tags, elementType, isOrdered); + } + public TType ElementType { get; } public bool IsOrderSet { get; } - public TSet(TType elementType, bool isOrderSet) : base(false) + private TSet(bool isNullable, Dictionary tags, TType elementType, bool isOrderSet) : base(isNullable, tags) { ElementType = elementType; IsOrderSet = isOrderSet; diff --git a/src/Luban.Job.Common/Source/Types/TShort.cs b/src/Luban.Job.Common/Source/Types/TShort.cs index 68e6fed..d1cda43 100644 --- a/src/Luban.Job.Common/Source/Types/TShort.cs +++ b/src/Luban.Job.Common/Source/Types/TShort.cs @@ -1,14 +1,27 @@ using Luban.Job.Common.TypeVisitors; +using System.Collections.Generic; namespace Luban.Job.Common.Types { public class TShort : TType { - public static TShort Ins { get; } = new TShort(false); + private static TShort Ins { get; } = new TShort(false, null); - public static TShort NullableIns { get; } = new TShort(true); + private static TShort NullableIns { get; } = new TShort(true, null); - public TShort(bool isNullable) : base(isNullable) + public static TShort Create(bool isNullable, Dictionary tags) + { + if (tags == null) + { + return isNullable ? NullableIns : Ins; + } + else + { + return new TShort(isNullable, tags); + } + } + + private TShort(bool isNullable, Dictionary tags) : base(isNullable, tags) { } diff --git a/src/Luban.Job.Common/Source/Types/TString.cs b/src/Luban.Job.Common/Source/Types/TString.cs index 2868016..2c1c15a 100644 --- a/src/Luban.Job.Common/Source/Types/TString.cs +++ b/src/Luban.Job.Common/Source/Types/TString.cs @@ -1,14 +1,27 @@ using Luban.Job.Common.TypeVisitors; +using System.Collections.Generic; namespace Luban.Job.Common.Types { public class TString : TType { - public static TString Ins { get; } = new TString(false); + private static TString Ins { get; } = new TString(false, null); - public static TString NullableIns { get; } = new TString(true); + private static TString NullableIns { get; } = new TString(true, null); - public TString(bool isNullable) : base(isNullable) + public static TString Create(bool isNullable, Dictionary tags) + { + if (tags == null) + { + return isNullable ? NullableIns : Ins; + } + else + { + return new TString(isNullable, tags); + } + } + + private TString(bool isNullable, Dictionary tags) : base(isNullable, tags) { } diff --git a/src/Luban.Job.Common/Source/Types/TText.cs b/src/Luban.Job.Common/Source/Types/TText.cs index eea7b69..0f92348 100644 --- a/src/Luban.Job.Common/Source/Types/TText.cs +++ b/src/Luban.Job.Common/Source/Types/TText.cs @@ -1,4 +1,5 @@ using Luban.Job.Common.TypeVisitors; +using System.Collections.Generic; namespace Luban.Job.Common.Types { @@ -6,11 +7,23 @@ namespace Luban.Job.Common.Types { public const string L10N_FIELD_SUFFIX = "_l10n_key"; - public static TText Ins { get; } = new TText(false); + private static TText Ins { get; } = new TText(false, null); - public static TText NullableIns { get; } = new TText(true); + private static TText NullableIns { get; } = new TText(true, null); - public TText(bool isNullable) : base(isNullable) + public static TText Create(bool isNullable, Dictionary tags) + { + if (tags == null) + { + return isNullable ? NullableIns : Ins; + } + else + { + return new TText(isNullable, tags); + } + } + + private TText(bool isNullable, Dictionary tags) : base(isNullable, tags) { } diff --git a/src/Luban.Job.Common/Source/Types/TType.cs b/src/Luban.Job.Common/Source/Types/TType.cs index 6cbd43b..6666bdd 100644 --- a/src/Luban.Job.Common/Source/Types/TType.cs +++ b/src/Luban.Job.Common/Source/Types/TType.cs @@ -7,13 +7,14 @@ namespace Luban.Job.Common.Types { public bool IsNullable { get; } - protected TType(bool isNullable) + public Dictionary Tags { get; } + + protected TType(bool isNullable, Dictionary tags) { IsNullable = isNullable; + Tags = tags; } - public Dictionary Tags { get; set; } - public bool HasTag(string attrName) { return Tags != null && Tags.ContainsKey(attrName); diff --git a/src/Luban.Job.Common/Source/Types/TVector2.cs b/src/Luban.Job.Common/Source/Types/TVector2.cs index 695225f..0a6cb58 100644 --- a/src/Luban.Job.Common/Source/Types/TVector2.cs +++ b/src/Luban.Job.Common/Source/Types/TVector2.cs @@ -1,15 +1,28 @@ using Luban.Job.Common.TypeVisitors; using System; +using System.Collections.Generic; namespace Luban.Job.Common.Types { public class TVector2 : TType { - public static TVector2 Ins { get; } = new TVector2(false); + private static TVector2 Ins { get; } = new TVector2(false, null); - public static TVector2 NullableIns { get; } = new TVector2(true); + private static TVector2 NullableIns { get; } = new TVector2(true, null); - public TVector2(bool isNullable) : base(isNullable) + public static TVector2 Create(bool isNullable, Dictionary tags) + { + if (tags == null) + { + return isNullable ? NullableIns : Ins; + } + else + { + return new TVector2(isNullable, tags); + } + } + + private TVector2(bool isNullable, Dictionary tags) : base(isNullable, tags) { } diff --git a/src/Luban.Job.Common/Source/Types/TVector3.cs b/src/Luban.Job.Common/Source/Types/TVector3.cs index 4d69a35..0c84385 100644 --- a/src/Luban.Job.Common/Source/Types/TVector3.cs +++ b/src/Luban.Job.Common/Source/Types/TVector3.cs @@ -1,15 +1,28 @@ using Luban.Job.Common.TypeVisitors; using System; +using System.Collections.Generic; namespace Luban.Job.Common.Types { public class TVector3 : TType { - public static TVector3 Ins { get; } = new TVector3(false); + private static TVector3 Ins { get; } = new TVector3(false, null); - public static TVector3 NullableIns { get; } = new TVector3(true); + private static TVector3 NullableIns { get; } = new TVector3(true, null); - public TVector3(bool isNullable) : base(isNullable) + public static TVector3 Create(bool isNullable, Dictionary tags) + { + if (tags == null) + { + return isNullable ? NullableIns : Ins; + } + else + { + return new TVector3(isNullable, tags); + } + } + + private TVector3(bool isNullable, Dictionary tags) : base(isNullable, tags) { } @@ -23,7 +36,7 @@ namespace Luban.Job.Common.Types visitor.Accept(this, x); } - public override void Apply(ITypeActionVisitor visitor, T1 x, T2 y) + public override void Apply(ITypeActionVisitor visitor, T1 x, T3 y) { visitor.Accept(this, x, y); } @@ -38,7 +51,7 @@ namespace Luban.Job.Common.Types return visitor.Accept(this, x); } - public override TR Apply(ITypeFuncVisitor visitor, T1 x, T2 y) + public override TR Apply(ITypeFuncVisitor visitor, T1 x, T3 y) { return visitor.Accept(this, x, y); } diff --git a/src/Luban.Job.Common/Source/Types/TVector4.cs b/src/Luban.Job.Common/Source/Types/TVector4.cs index fd117e6..63ff5f3 100644 --- a/src/Luban.Job.Common/Source/Types/TVector4.cs +++ b/src/Luban.Job.Common/Source/Types/TVector4.cs @@ -1,15 +1,28 @@ using Luban.Job.Common.TypeVisitors; using System; +using System.Collections.Generic; namespace Luban.Job.Common.Types { public class TVector4 : TType { - public static TVector4 Ins { get; } = new TVector4(false); + private static TVector4 Ins { get; } = new TVector4(false, null); - public static TVector4 NullableIns { get; } = new TVector4(true); + private static TVector4 NullableIns { get; } = new TVector4(true, null); - public TVector4(bool isNullable) : base(isNullable) + public static TVector4 Create(bool isNullable, Dictionary tags) + { + if (tags == null) + { + return isNullable ? NullableIns : Ins; + } + else + { + return new TVector4(isNullable, tags); + } + } + + private TVector4(bool isNullable, Dictionary tags) : base(isNullable, tags) { }