【特性】新增对外部class类的支持。 可以在定义中引用现成的外部类,如UnityEngine.Color

main
walon 2021-12-02 14:59:25 +08:00
parent 7fc75871d4
commit edc09b6742
10 changed files with 64 additions and 11 deletions

View File

@ -56,6 +56,7 @@ luban相较于常规的excel导表工具有以下核心优势
- 强大的数据校验能力。支持内建数据格式检查支持ref表引用检查策划不用担心填错id;支持path资源检查策划不用担心填错资源路径;支持range检查 - 强大的数据校验能力。支持内建数据格式检查支持ref表引用检查策划不用担心填错id;支持path资源检查策划不用担心填错资源路径;支持range检查
- 支持常量别名。策划不必再为诸如 升级丹 这样的道具手写具体道具id了 - 支持常量别名。策划不必再为诸如 升级丹 这样的道具手写具体道具id了
- 支持多种常见数据表模式。 singleton(单例表)、map常规key-value表、**list(支持无索引、多主键联合索引、多主键独立索引)** - 支持多种常见数据表模式。 singleton(单例表)、map常规key-value表、**list(支持无索引、多主键联合索引、多主键独立索引)**
- 支持**external type**,即外部类。 你可以在配置中引用现成的enum和class类比如 UnityEngine.ColorUnityEngine.AudioType。
- 支持res资源标记。可以一键导出配置中引用的所有资源列表(icon,ui,assetbundle等等) - 支持res资源标记。可以一键导出配置中引用的所有资源列表(icon,ui,assetbundle等等)
- 统一了自定义编辑器的配置数据。与Unity和UE4的自定义编辑器良好配合为编辑器生成合适的加载与保存json配置的的c#(Unity)或c++(UE4)代码。保存的json配置能够被luban识别和处理。 - 统一了自定义编辑器的配置数据。与Unity和UE4的自定义编辑器良好配合为编辑器生成合适的加载与保存json配置的的c#(Unity)或c++(UE4)代码。保存的json配置能够被luban识别和处理。
- 支持emmylua anntations。生成的lua包含符合emmylua 格式anntations信息。配合emmylua有良好的配置代码提示能力 - 支持emmylua anntations。生成的lua包含符合emmylua 格式anntations信息。配合emmylua有良好的配置代码提示能力

View File

@ -770,7 +770,7 @@ namespace Luban.Job.Cfg.Defs
return f; return f;
} }
private static readonly List<string> _beanOptinsAttrs = new List<string> { "value_type", "alias", "sep", "comment", "tags", "group" }; private static readonly List<string> _beanOptinsAttrs = new List<string> { "value_type", "alias", "sep", "comment", "tags", "group", "externaltype" };
private static readonly List<string> _beanRequireAttrs = new List<string> { "name" }; private static readonly List<string> _beanRequireAttrs = new List<string> { "name" };
override protected void AddBean(string defineFile, XElement e, string parent) override protected void AddBean(string defineFile, XElement e, string parent)
@ -789,6 +789,7 @@ namespace Luban.Job.Cfg.Defs
Sep = XmlUtil.GetOptionalAttribute(e, "sep"), Sep = XmlUtil.GetOptionalAttribute(e, "sep"),
Comment = XmlUtil.GetOptionalAttribute(e, "comment"), Comment = XmlUtil.GetOptionalAttribute(e, "comment"),
Tags = XmlUtil.GetOptionalAttribute(e, "tags"), Tags = XmlUtil.GetOptionalAttribute(e, "tags"),
ExternalType = XmlUtil.GetOptionalAttribute(e, "externaltype"),
}; };
var childBeans = new List<XElement>(); var childBeans = new List<XElement>();

View File

@ -170,6 +170,8 @@ namespace Luban.Job.Cfg.Defs
public override void Compile() public override void Compile()
{ {
ResolveExternalType();
var cs = new List<DefBeanBase>(); var cs = new List<DefBeanBase>();
if (Children != null) if (Children != null)
{ {

View File

@ -28,7 +28,7 @@ namespace Luban.Job.Cfg.Defs
// 如果ref了多个表不再生成 xxx_ref之类的字段也不会resolve // 如果ref了多个表不再生成 xxx_ref之类的字段也不会resolve
public bool GenRef => Ref != null && Ref.GenRef; public bool GenRef => Ref != null && Ref.GenRef;
public bool HasRecursiveRef => (CType.IsBean) public bool HasRecursiveRef => (CType is TBean tb && tb.Bean.CurrentExternalTypeMapper == null)
|| (CType is TArray ta && ta.ElementType.IsBean) || (CType is TArray ta && ta.ElementType.IsBean)
|| (CType is TList tl && tl.ElementType.IsBean) || (CType is TList tl && tl.ElementType.IsBean)
|| (CType is TMap tm && tm.ValueType.IsBean); || (CType is TMap tm && tm.ValueType.IsBean);

View File

@ -217,10 +217,10 @@ namespace Luban.Job.Common.Defs
AddBean(defineFile, e, ""); AddBean(defineFile, e, "");
} }
private static readonly List<string> _beanOptinsAttrs1 = new List<string> { "compatible", "value_type", "comment", "tags" }; private static readonly List<string> _beanOptinsAttrs1 = new List<string> { "compatible", "value_type", "comment", "tags", "externaltype" };
private static readonly List<string> _beanRequireAttrs1 = new List<string> { "id", "name" }; 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", "tags" }; private static readonly List<string> _beanOptinsAttrs2 = new List<string> { "id", "compatible", "value_type", "comment", "tags", "externaltype" };
private static readonly List<string> _beanRequireAttrs2 = new List<string> { "name" }; private static readonly List<string> _beanRequireAttrs2 = new List<string> { "name" };
protected virtual void AddBean(string defineFile, XElement e, string parent) protected virtual void AddBean(string defineFile, XElement e, string parent)
@ -243,6 +243,7 @@ namespace Luban.Job.Common.Defs
IsValueType = XmlUtil.GetOptionBoolAttribute(e, "value_type"), IsValueType = XmlUtil.GetOptionBoolAttribute(e, "value_type"),
Comment = XmlUtil.GetOptionalAttribute(e, "comment"), Comment = XmlUtil.GetOptionalAttribute(e, "comment"),
Tags = XmlUtil.GetOptionalAttribute(e, "tags"), Tags = XmlUtil.GetOptionalAttribute(e, "tags"),
ExternalType = XmlUtil.GetOptionalAttribute(e, "externaltype"),
}; };
var childBeans = new List<XElement>(); var childBeans = new List<XElement>();
@ -414,6 +415,11 @@ namespace Luban.Job.Common.Defs
m.TypeName = attrEle.Value; m.TypeName = attrEle.Value;
break; break;
} }
case "create_external_object_function":
{
m.CreateExternalObjectFunction = attrEle.Value;
break;
}
default: throw new LoadDefException($"定义文件:{defineFile} externaltype:{externalType} 非法 tag:{tagName}"); default: throw new LoadDefException($"定义文件:{defineFile} externaltype:{externalType} 非法 tag:{tagName}");
} }
} }

View File

@ -31,6 +31,8 @@ namespace Luban.Job.Common.Defs
public string FullNameWithTopModule => TypeUtil.MakeFullName(AssemblyBase.TopModule, FullName); public string FullNameWithTopModule => TypeUtil.MakeFullName(AssemblyBase.TopModule, FullName);
public string CsFullName => TypeUtil.MakeFullName(Namespace, Name);
public string JavaFullName => TypeUtil.MakeFullName(Namespace, Name); public string JavaFullName => TypeUtil.MakeFullName(Namespace, Name);
public string GoFullName => TypeUtil.MakeGoFullName(Namespace, Name); public string GoFullName => TypeUtil.MakeGoFullName(Namespace, Name);
@ -83,9 +85,7 @@ namespace Luban.Job.Common.Defs
} }
} }
public virtual void PreCompile() { } protected void ResolveExternalType()
public virtual void Compile()
{ {
if (!string.IsNullOrEmpty(_externalTypeName)) if (!string.IsNullOrEmpty(_externalTypeName))
{ {
@ -100,6 +100,13 @@ namespace Luban.Job.Common.Defs
} }
} }
public virtual void PreCompile() { }
public virtual void Compile()
{
ResolveExternalType();
}
public virtual void PostCompile() { } public virtual void PostCompile() { }
} }
} }

View File

@ -14,6 +14,8 @@ namespace Luban.Job.Common.RawDefs
public ELanguage Lan { get; set; } public ELanguage Lan { get; set; }
public string TypeName { get; set; } public string TypeName { get; set; }
public string CreateExternalObjectFunction { get; set; }
} }
public class ExternalType public class ExternalType

View File

@ -1,5 +1,6 @@
using Luban.Job.Common.Defs; using Luban.Job.Common.Defs;
using Luban.Job.Common.Types; using Luban.Job.Common.Types;
using Luban.Job.Common.Utils;
namespace Luban.Job.Common.TypeVisitors namespace Luban.Job.Common.TypeVisitors
{ {
@ -59,8 +60,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TEnum type) public string Accept(TEnum type)
{ {
var mapper = type.DefineEnum.CurrentExternalTypeMapper; return ExternalTypeUtil.CsMapperToExternalType(type.DefineEnum);
return mapper != null ? mapper.TypeName : type.DefineEnum.FullName;
} }
public string Accept(TString type) public string Accept(TString type)
@ -80,7 +80,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TBean type) public string Accept(TBean type)
{ {
return type.Bean.FullName; return ExternalTypeUtil.CsMapperToExternalType(type.Bean);
} }
public string Accept(TArray type) public string Accept(TArray type)

View File

@ -1,5 +1,6 @@
using Luban.Job.Common.Defs; using Luban.Job.Common.Defs;
using Luban.Job.Common.Types; using Luban.Job.Common.Types;
using Luban.Job.Common.Utils;
namespace Luban.Job.Common.TypeVisitors namespace Luban.Job.Common.TypeVisitors
{ {
@ -79,7 +80,8 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TBean type, string bufName, string fieldName) public string Accept(TBean type, string bufName, string fieldName)
{ {
return $"{fieldName} = {type.Bean.FullName}.Deserialize{type.Bean.Name}({bufName});"; string src = $"{type.Bean.FullName}.Deserialize{type.Bean.Name}({bufName})";
return $"{fieldName} = {ExternalTypeUtil.CsCloneToExternal(type.Bean, src)};";
} }
public string Accept(TArray type, string bufName, string fieldName) public string Accept(TArray type, string bufName, string fieldName)

View File

@ -0,0 +1,32 @@
using Luban.Job.Common.Defs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Luban.Job.Common.Utils
{
public static class ExternalTypeUtil
{
public static string CsMapperToExternalType(DefTypeBase type)
{
var mapper = type.CurrentExternalTypeMapper;
return mapper != null ? mapper.TypeName : type.CsFullName;
}
public static string CsCloneToExternal(DefTypeBase type, string src)
{
var mapper = type.CurrentExternalTypeMapper;
if (mapper == null)
{
return src;
}
if (string.IsNullOrWhiteSpace(mapper.CreateExternalObjectFunction))
{
throw new Exception($"type:{type.FullName} externaltype:{type.ExternalType.Name} lan:{mapper.Lan} selector:{mapper.Selector} 未定义clone_to_external元素");
}
return $"{mapper.CreateExternalObjectFunction}({src})";
}
}
}