【调整】【重大】将配置中的多态类型字段由统一的__type__改成 excel优先$type,json优先$type,xml优先type,lua优先_type_,如果找不到再找默认__type__。
parent
e76b20b24f
commit
657bd19c77
10
README.md
10
README.md
|
|
@ -324,7 +324,7 @@ Reward为包含 "int item_id; int count; string desc; " 这三个字段的子结
|
|||
|
||||
<tr align="center"><td>##var</td><td>id</td><td colspan="4">shape</td><td colspan="4">shape2</td></tr>
|
||||
<tr align="center"><td>##type</td><td>int</td><td colspan="4">Shape</td><td colspan="4">Shape</td></tr>
|
||||
<tr align="center"><td>##var</td><td></td><td>__type__</td><td>radius</td><td>width</td><td>height</td><td></td><td></td><td></td><td></td></tr>
|
||||
<tr align="center"><td>##var</td><td></td><td>$type</td><td>radius</td><td>width</td><td>height</td><td></td><td></td><td></td><td></td></tr>
|
||||
<tr align="center"><td/><td>1</td><td>Circle</td><td>10</td><td/><td/><td>Circle</td><td>100</td><td></td><td></td></tr>
|
||||
<tr align="center"><td/><td>2</td><td>Rectangle</td><td></td><td>10</td><td>20</td><td>矩形</td><td>10</td><td>20</td><td></td></tr>
|
||||
<tr align="center"><td/><td>3</td><td>圆</td><td>10</td><td/><td/><td>Triangle</td><td>15</td><td>15</td><td>15</td></tr>
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<string, string>(),
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue