diff --git a/README.md b/README.md
index 65fd54f..764f2b8 100644
--- a/README.md
+++ b/README.md
@@ -324,7 +324,7 @@ Reward为包含 "int item_id; int count; string desc; " 这三个字段的子结
| ##var | id | shape | shape2 |
| ##type | int | Shape | Shape |
-| ##var | | __type__ | radius | width | height | | | | |
+| ##var | | $type | radius | width | height | | | | |
| 1 | Circle | 10 | | | Circle | 100 | | |
| 2 | Rectangle | | 10 | 20 | 矩形 | 10 | 20 | |
| 3 | 圆 | 10 | | | Triangle | 15 | 15 | 15 |
@@ -404,14 +404,14 @@ Reward为包含 "int item_id; int count; string desc; " 这三个字段的子结
"executor": "SERVER",
"blackboard_id": "demo",
"root": {
- "__type__": "Sequence",
+ "$type": "Sequence",
"id": 1,
"node_name": "test",
"desc": "root",
"services": [],
"decorators": [
{
- "__type__": "UeLoop",
+ "$type": "UeLoop",
"id": 3,
"node_name": "",
"flow_abort_mode": "SELF",
@@ -422,7 +422,7 @@ Reward为包含 "int item_id; int count; string desc; " 这三个字段的子结
],
"children": [
{
- "__type__": "UeWait",
+ "$type": "UeWait",
"id": 30,
"node_name": "",
"ignore_restart_self": false,
@@ -432,7 +432,7 @@ Reward为包含 "int item_id; int count; string desc; " 这三个字段的子结
"decorators": []
},
{
- "__type__": "MoveToRandomLocation",
+ "$type": "MoveToRandomLocation",
"id": 75,
"node_name": "",
"ignore_restart_self": false,
diff --git a/src/Luban.Job.Cfg/Source/DataConverts/FillSheetVisitor.cs b/src/Luban.Job.Cfg/Source/DataConverts/FillSheetVisitor.cs
index 70197dd..ee52814 100644
--- a/src/Luban.Job.Cfg/Source/DataConverts/FillSheetVisitor.cs
+++ b/src/Luban.Job.Cfg/Source/DataConverts/FillSheetVisitor.cs
@@ -130,9 +130,9 @@ namespace Luban.Job.Cfg.DataConverts
{
if (data.Type.IsAbstractType)
{
- if (!x.SubTitles.TryGetValue(DefBean.TYPE_NAME_KEY, out var typeTitle))
+ if (!x.SubTitles.TryGetValue(DefBean.FALLBACK_TYPE_NAME_KEY, out var typeTitle) && !x.SubTitles.TryGetValue(DefBean.EXCEL_TYPE_NAME_KEY, out typeTitle))
{
- throw new Exception($"多态bean:{data.Type.FullName} 缺失 {DefBean.TYPE_NAME_KEY} 标题列");
+ throw new Exception($"多态bean:{data.Type.FullName} 缺失 {DefBean.EXCEL_TYPE_NAME_KEY} 标题列");
}
if (data.ImplType != null)
{
diff --git a/src/Luban.Job.Cfg/Source/DataConverts/JsonConvertor.cs b/src/Luban.Job.Cfg/Source/DataConverts/JsonConvertor.cs
index f64ccfc..6c7ab50 100644
--- a/src/Luban.Job.Cfg/Source/DataConverts/JsonConvertor.cs
+++ b/src/Luban.Job.Cfg/Source/DataConverts/JsonConvertor.cs
@@ -35,7 +35,7 @@ namespace Luban.Job.Cfg.DataConverts
if (type.Type.IsAbstractType)
{
- x.WritePropertyName(DefBean.TYPE_NAME_KEY);
+ x.WritePropertyName(DefBean.JSON_TYPE_NAME_KEY);
x.WriteStringValue(type.ImplType.Name);
}
diff --git a/src/Luban.Job.Cfg/Source/DataConverts/LuaConvertor.cs b/src/Luban.Job.Cfg/Source/DataConverts/LuaConvertor.cs
index 3814a52..6cc7f97 100644
--- a/src/Luban.Job.Cfg/Source/DataConverts/LuaConvertor.cs
+++ b/src/Luban.Job.Cfg/Source/DataConverts/LuaConvertor.cs
@@ -12,7 +12,7 @@ namespace Luban.Job.Cfg.DataConverts
{
class LuaConvertor : DataVisitors.ToLuaLiteralVisitor
{
- public static new LuaConvertor Ins { get; } = new();
+ //public static new LuaConvertor Ins { get; } = new();
private string _indentStr = "";
@@ -43,7 +43,7 @@ namespace Luban.Job.Cfg.DataConverts
x.AppendLine("{");
if (type.Type.IsAbstractType)
{
- x.Append(subIndent).AppendLine($"_name = '{type.ImplType.Name}',");
+ x.Append(subIndent).AppendLine($"{DefBean.LUA_TYPE_NAME_KEY} = '{type.ImplType.Name}',");
}
int index = 0;
diff --git a/src/Luban.Job.Cfg/Source/DataConverts/TitleCreator.cs b/src/Luban.Job.Cfg/Source/DataConverts/TitleCreator.cs
index 3324045..a90a72c 100644
--- a/src/Luban.Job.Cfg/Source/DataConverts/TitleCreator.cs
+++ b/src/Luban.Job.Cfg/Source/DataConverts/TitleCreator.cs
@@ -36,7 +36,7 @@ namespace Luban.Job.Cfg.DataConverts
{
title.AddSubTitle(new Title()
{
- Name = DefBean.TYPE_NAME_KEY,
+ Name = DefBean.EXCEL_TYPE_NAME_KEY,
FromIndex = lastColumn + 1,
ToIndex = lastColumn + 1,
Tags = new Dictionary(),
diff --git a/src/Luban.Job.Cfg/Source/DataCreators/JsonDataCreator.cs b/src/Luban.Job.Cfg/Source/DataCreators/JsonDataCreator.cs
index 15e3480..16b7d86 100644
--- a/src/Luban.Job.Cfg/Source/DataCreators/JsonDataCreator.cs
+++ b/src/Luban.Job.Cfg/Source/DataCreators/JsonDataCreator.cs
@@ -112,9 +112,9 @@ namespace Luban.Job.Cfg.DataCreators
DefBean implBean;
if (bean.IsAbstractType)
{
- if (!x.TryGetProperty(DefBean.TYPE_NAME_KEY, out var typeNameProp))
+ if (!x.TryGetProperty(DefBean.FALLBACK_TYPE_NAME_KEY, out var typeNameProp) && !x.TryGetProperty(DefBean.JSON_TYPE_NAME_KEY, out typeNameProp))
{
- throw new Exception($"结构:'{bean.FullName}' 是多态类型,必须用 '{DefBean.TYPE_NAME_KEY}' 字段指定 子类名");
+ throw new Exception($"结构:'{bean.FullName}' 是多态类型,必须用 '{DefBean.JSON_TYPE_NAME_KEY}' 字段指定 子类名");
}
string subType = typeNameProp.GetString();
implBean = DataUtil.GetImplTypeByNameOrAlias(bean, subType);
diff --git a/src/Luban.Job.Cfg/Source/DataCreators/LuaDataCreator.cs b/src/Luban.Job.Cfg/Source/DataCreators/LuaDataCreator.cs
index 940b960..bf17fb9 100644
--- a/src/Luban.Job.Cfg/Source/DataCreators/LuaDataCreator.cs
+++ b/src/Luban.Job.Cfg/Source/DataCreators/LuaDataCreator.cs
@@ -153,11 +153,19 @@ namespace Luban.Job.Cfg.DataCreators
DefBean implBean;
if (bean.IsAbstractType)
{
- if (!table.ContainsKey(DefBean.TYPE_NAME_KEY))
+ string subType;
+ if (table.ContainsKey(DefBean.FALLBACK_TYPE_NAME_KEY))
{
- throw new Exception($"结构:{bean.FullName} 是多态类型,必须用 {DefBean.TYPE_NAME_KEY} 字段指定 子类名");
+ subType = (string)table[DefBean.FALLBACK_TYPE_NAME_KEY];
+ }
+ else if(table.ContainsKey(DefBean.LUA_TYPE_NAME_KEY))
+ {
+ subType = (string)(table[DefBean.LUA_TYPE_NAME_KEY]);
+ }
+ else
+ {
+ throw new Exception($"结构:{bean.FullName} 是多态类型,必须用 {DefBean.LUA_TYPE_NAME_KEY} 字段指定 子类名");
}
- var subType = (string)table[DefBean.TYPE_NAME_KEY];
implBean = DataUtil.GetImplTypeByNameOrAlias(bean, subType);
}
else
diff --git a/src/Luban.Job.Cfg/Source/DataCreators/SheetDataCreator.cs b/src/Luban.Job.Cfg/Source/DataCreators/SheetDataCreator.cs
index 75050ed..b65f24b 100644
--- a/src/Luban.Job.Cfg/Source/DataCreators/SheetDataCreator.cs
+++ b/src/Luban.Job.Cfg/Source/DataCreators/SheetDataCreator.cs
@@ -399,10 +399,10 @@ namespace Luban.Job.Cfg.DataCreators
var originBean = (DefBean)type.Bean;
if (originBean.IsAbstractType)
{
- TitleRow typeTitle = row.GetSubTitleNamedRow(DefBean.TYPE_NAME_KEY);
+ TitleRow typeTitle = row.GetSubTitleNamedRow(DefBean.FALLBACK_TYPE_NAME_KEY) ?? row.GetSubTitleNamedRow(DefBean.EXCEL_TYPE_NAME_KEY);
if (typeTitle == null)
{
- throw new Exception($"type:'{originBean.FullName}' 是多态类型,需要定义'{DefBean.TYPE_NAME_KEY}'列来指定具体子类型");
+ throw new Exception($"type:'{originBean.FullName}' 是多态类型,需要定义'{DefBean.EXCEL_TYPE_NAME_KEY}'列来指定具体子类型");
}
string subType = typeTitle.Current?.ToString()?.Trim();
@@ -421,10 +421,10 @@ namespace Luban.Job.Cfg.DataCreators
{
if (type.IsNullable)
{
- TitleRow typeTitle = row.GetSubTitleNamedRow(DefBean.TYPE_NAME_KEY);
+ TitleRow typeTitle = row.GetSubTitleNamedRow(DefBean.FALLBACK_TYPE_NAME_KEY) ?? row.GetSubTitleNamedRow(DefBean.EXCEL_TYPE_NAME_KEY);
if (typeTitle == null)
{
- throw new Exception($"type:'{originBean.FullName}' 是可空类型,需要定义'{DefBean.TYPE_NAME_KEY}'列来指明是否可空");
+ throw new Exception($"type:'{originBean.FullName}' 是可空类型,需要定义'{DefBean.EXCEL_TYPE_NAME_KEY}'列来指明是否可空");
}
string subType = typeTitle.Current?.ToString()?.Trim();
if (subType == null || subType == DefBean.BEAN_NULL_STR)
diff --git a/src/Luban.Job.Cfg/Source/DataCreators/XmlDataCreator.cs b/src/Luban.Job.Cfg/Source/DataCreators/XmlDataCreator.cs
index ccaec89..ccd6b13 100644
--- a/src/Luban.Job.Cfg/Source/DataCreators/XmlDataCreator.cs
+++ b/src/Luban.Job.Cfg/Source/DataCreators/XmlDataCreator.cs
@@ -96,10 +96,14 @@ namespace Luban.Job.Cfg.DataCreators
DefBean implBean;
if (bean.IsAbstractType)
{
- string subType = x.Attribute(DefBean.TYPE_NAME_KEY)?.Value;
+ string subType = x.Attribute(DefBean.FALLBACK_TYPE_NAME_KEY)?.Value;
+ if (string.IsNullOrEmpty(subType))
+ {
+ subType = x.Attribute(DefBean.XML_TYPE_NAME_KEY)?.Value;
+ }
if (string.IsNullOrWhiteSpace(subType))
{
- throw new Exception($"bean:'{bean.FullName}'是多态,需要指定{DefBean.TYPE_NAME_KEY}属性.\n xml:{x}");
+ throw new Exception($"bean:'{bean.FullName}'是多态,需要指定{DefBean.XML_TYPE_NAME_KEY}属性.\n xml:{x}");
}
implBean = DataUtil.GetImplTypeByNameOrAlias(bean, subType);
}
diff --git a/src/Luban.Job.Cfg/Source/DataCreators/YamlDataCreator.cs b/src/Luban.Job.Cfg/Source/DataCreators/YamlDataCreator.cs
index 50b418c..e1c3e76 100644
--- a/src/Luban.Job.Cfg/Source/DataCreators/YamlDataCreator.cs
+++ b/src/Luban.Job.Cfg/Source/DataCreators/YamlDataCreator.cs
@@ -102,7 +102,8 @@ namespace Luban.Job.Cfg.DataCreators
return new DText(key, text);
}
- private static readonly YamlScalarNode s_typeNodeName = new(DefBean.TYPE_NAME_KEY);
+ private static readonly YamlScalarNode s_typeNodeName = new(DefBean.FALLBACK_TYPE_NAME_KEY);
+ private static readonly YamlScalarNode s_typeNodeName2 = new(DefBean.JSON_TYPE_NAME_KEY);
public DType Accept(TBean type, YamlNode x, DefAssembly y)
{
@@ -112,10 +113,14 @@ namespace Luban.Job.Cfg.DataCreators
DefBean implBean;
if (bean.IsAbstractType)
{
- string subType = m.Children.TryGetValue(s_typeNodeName, out var typeNode) ? (string)typeNode : null;
+ if (!m.Children.TryGetValue(s_typeNodeName, out var typeNode) && !m.Children.TryGetValue(s_typeNodeName2, out typeNode))
+ {
+ throw new Exception($"bean:'{bean.FullName}'是多态,需要指定{DefBean.JSON_TYPE_NAME_KEY}属性.\n xml:{x}");
+ }
+ string subType = (string)typeNode;
if (string.IsNullOrWhiteSpace(subType))
{
- throw new Exception($"bean:'{bean.FullName}'是多态,需要指定{DefBean.TYPE_NAME_KEY}属性.\n xml:{x}");
+ throw new Exception($"bean:'{bean.FullName}'是多态,需要指定{DefBean.JSON_TYPE_NAME_KEY}属性.\n xml:{x}");
}
implBean = DataUtil.GetImplTypeByNameOrAlias(bean, subType);
}
diff --git a/src/Luban.Job.Cfg/Source/DataExporters/JsonExportor.cs b/src/Luban.Job.Cfg/Source/DataExporters/JsonExportor.cs
index ab1dd15..e58c76b 100644
--- a/src/Luban.Job.Cfg/Source/DataExporters/JsonExportor.cs
+++ b/src/Luban.Job.Cfg/Source/DataExporters/JsonExportor.cs
@@ -104,7 +104,7 @@ namespace Luban.Job.Cfg.DataExporters
if (type.Type.IsAbstractType)
{
- x.WritePropertyName(DefBean.TYPE_NAME_KEY);
+ x.WritePropertyName(DefBean.JSON_TYPE_NAME_KEY);
x.WriteStringValue(DataUtil.GetImplTypeName(type));
}
diff --git a/src/Luban.Job.Cfg/Source/DataExporters/MsgPackExportor.cs b/src/Luban.Job.Cfg/Source/DataExporters/MsgPackExportor.cs
index a5023b9..1bd5959 100644
--- a/src/Luban.Job.Cfg/Source/DataExporters/MsgPackExportor.cs
+++ b/src/Luban.Job.Cfg/Source/DataExporters/MsgPackExportor.cs
@@ -183,7 +183,7 @@ namespace Luban.Job.Cfg.DataExporters
writer.WriteMapHeader(exportCount);
if (type.Type.IsAbstractType)
{
- writer.Write(DefBean.TYPE_NAME_KEY);
+ writer.Write(DefBean.JSON_TYPE_NAME_KEY);
writer.Write(DataUtil.GetImplTypeName(type));
}
diff --git a/src/Luban.Job.Cfg/Source/DataExporters/RawJsonExportor.cs b/src/Luban.Job.Cfg/Source/DataExporters/RawJsonExportor.cs
index 8032a52..46d60db 100644
--- a/src/Luban.Job.Cfg/Source/DataExporters/RawJsonExportor.cs
+++ b/src/Luban.Job.Cfg/Source/DataExporters/RawJsonExportor.cs
@@ -104,7 +104,7 @@ namespace Luban.Job.Cfg.DataExporters
if (type.Type.IsAbstractType)
{
- x.WritePropertyName(DefBean.TYPE_NAME_KEY);
+ x.WritePropertyName(DefBean.JSON_TYPE_NAME_KEY);
x.WriteStringValue(DataUtil.GetImplTypeName(type));
}
diff --git a/src/Luban.Job.Cfg/Source/DataVisitors/ToLuaLiteralVisitor.cs b/src/Luban.Job.Cfg/Source/DataVisitors/ToLuaLiteralVisitor.cs
index 713bbaf..5148012 100644
--- a/src/Luban.Job.Cfg/Source/DataVisitors/ToLuaLiteralVisitor.cs
+++ b/src/Luban.Job.Cfg/Source/DataVisitors/ToLuaLiteralVisitor.cs
@@ -20,7 +20,7 @@ namespace Luban.Job.Cfg.DataVisitors
var x = new StringBuilder();
if (type.Type.IsAbstractType)
{
- x.Append($"{{ _name='{DataUtil.GetImplTypeName(type)}',");
+ x.Append($"{{ {DefBean.LUA_TYPE_NAME_KEY}='{DataUtil.GetImplTypeName(type)}',");
}
else
{
diff --git a/src/Luban.Job.Cfg/Source/Defs/DefBean.cs b/src/Luban.Job.Cfg/Source/Defs/DefBean.cs
index 0ef2985..a13821d 100644
--- a/src/Luban.Job.Cfg/Source/Defs/DefBean.cs
+++ b/src/Luban.Job.Cfg/Source/Defs/DefBean.cs
@@ -10,13 +10,21 @@ namespace Luban.Job.Cfg.Defs
{
public class DefBean : DefBeanBase
{
- public const string TYPE_NAME_KEY = "__type__";
+ public const string FALLBACK_TYPE_NAME_KEY = "__type__";
public const string BEAN_NULL_STR = "null";
public const string BEAN_NOT_NULL_STR = "{}";
- public string JsonTypeNameKey => TYPE_NAME_KEY;
+ public const string JSON_TYPE_NAME_KEY = "$type";
+
+ public const string XML_TYPE_NAME_KEY = "type";
+
+ public const string LUA_TYPE_NAME_KEY = "_type_";
+
+ public const string EXCEL_TYPE_NAME_KEY = "$type";
+
+ public string JsonTypeNameKey => JSON_TYPE_NAME_KEY;
diff --git a/src/Luban.Job.Cfg/Source/Utils/DataConvertUtil.cs b/src/Luban.Job.Cfg/Source/Utils/DataConvertUtil.cs
index a0db009..1384991 100644
--- a/src/Luban.Job.Cfg/Source/Utils/DataConvertUtil.cs
+++ b/src/Luban.Job.Cfg/Source/Utils/DataConvertUtil.cs
@@ -37,7 +37,7 @@ namespace Luban.Job.Cfg.Utils
}
case "convert_lua":
{
- return LuaConvertor.Ins.ExportRecord(table, record);
+ return (new LuaConvertor()).ExportRecord(table, record);
}
default:
{
diff --git a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs
index bbacac9..f3adf55 100644
--- a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs
+++ b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs
@@ -114,7 +114,7 @@ namespace Luban.Job.Common.Defs
this.ExternalSelectors = defines.ExternalSelectors;
this.ExternalTypes = defines.ExternalTypes;
this.Options = defines.Options;
- this.EditorTopModule = defines.Options.TryGetValue("editor.topmodule", out var editorTopModule) ? editorTopModule : TypeUtil.MakeFullName("editor", defines.TopModule);
+ this.EditorTopModule = GetOptionOr("editor.topmodule", TypeUtil.MakeFullName("editor", defines.TopModule));
this.Args = args;
diff --git a/src/Luban.Job.Common/Source/Defs/TTypeTemplateCommonExtends.cs b/src/Luban.Job.Common/Source/Defs/TTypeTemplateCommonExtends.cs
index 9ac7816..9407bdf 100644
--- a/src/Luban.Job.Common/Source/Defs/TTypeTemplateCommonExtends.cs
+++ b/src/Luban.Job.Common/Source/Defs/TTypeTemplateCommonExtends.cs
@@ -303,5 +303,10 @@ namespace Luban.Job.Common.Defs
{
return DefAssemblyBase.LocalAssebmly.GetOption(optionName);
}
+
+ public static string GetOptionOr(string optionName, string defaultValue)
+ {
+ return DefAssemblyBase.LocalAssebmly.GetOptionOr(optionName, defaultValue);
+ }
}
}