【特性】新增对外部class类的支持。 可以在定义中引用现成的外部类,如UnityEngine.Color
parent
7fc75871d4
commit
edc09b6742
|
|
@ -56,6 +56,7 @@ luban相较于常规的excel导表工具有以下核心优势:
|
|||
- 强大的数据校验能力。支持内建数据格式检查;支持ref表引用检查(策划不用担心填错id);支持path资源检查(策划不用担心填错资源路径);支持range检查
|
||||
- 支持常量别名。策划不必再为诸如 升级丹 这样的道具手写具体道具id了
|
||||
- 支持多种常见数据表模式。 singleton(单例表)、map(常规key-value表)、**list(支持无索引、多主键联合索引、多主键独立索引)**
|
||||
- 支持**external type**,即外部类。 你可以在配置中引用现成的enum和class类,比如 UnityEngine.Color,UnityEngine.AudioType。
|
||||
- 支持res资源标记。可以一键导出配置中引用的所有资源列表(icon,ui,assetbundle等等)
|
||||
- 统一了自定义编辑器的配置数据。与Unity和UE4的自定义编辑器良好配合,为编辑器生成合适的加载与保存json配置的的c#(Unity)或c++(UE4)代码。保存的json配置能够被luban识别和处理。
|
||||
- 支持emmylua anntations。生成的lua包含符合emmylua 格式anntations信息。配合emmylua有良好的配置代码提示能力
|
||||
|
|
|
|||
|
|
@ -770,7 +770,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
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" };
|
||||
|
||||
override protected void AddBean(string defineFile, XElement e, string parent)
|
||||
|
|
@ -789,6 +789,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
Sep = XmlUtil.GetOptionalAttribute(e, "sep"),
|
||||
Comment = XmlUtil.GetOptionalAttribute(e, "comment"),
|
||||
Tags = XmlUtil.GetOptionalAttribute(e, "tags"),
|
||||
ExternalType = XmlUtil.GetOptionalAttribute(e, "externaltype"),
|
||||
};
|
||||
var childBeans = new List<XElement>();
|
||||
|
||||
|
|
|
|||
|
|
@ -170,6 +170,8 @@ namespace Luban.Job.Cfg.Defs
|
|||
|
||||
public override void Compile()
|
||||
{
|
||||
ResolveExternalType();
|
||||
|
||||
var cs = new List<DefBeanBase>();
|
||||
if (Children != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
// 如果ref了多个表,不再生成 xxx_ref之类的字段,也不会resolve
|
||||
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 TList tl && tl.ElementType.IsBean)
|
||||
|| (CType is TMap tm && tm.ValueType.IsBean);
|
||||
|
|
|
|||
|
|
@ -217,10 +217,10 @@ namespace Luban.Job.Common.Defs
|
|||
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> _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" };
|
||||
|
||||
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"),
|
||||
Comment = XmlUtil.GetOptionalAttribute(e, "comment"),
|
||||
Tags = XmlUtil.GetOptionalAttribute(e, "tags"),
|
||||
ExternalType = XmlUtil.GetOptionalAttribute(e, "externaltype"),
|
||||
};
|
||||
var childBeans = new List<XElement>();
|
||||
|
||||
|
|
@ -414,6 +415,11 @@ namespace Luban.Job.Common.Defs
|
|||
m.TypeName = attrEle.Value;
|
||||
break;
|
||||
}
|
||||
case "create_external_object_function":
|
||||
{
|
||||
m.CreateExternalObjectFunction = attrEle.Value;
|
||||
break;
|
||||
}
|
||||
default: throw new LoadDefException($"定义文件:{defineFile} externaltype:{externalType} 非法 tag:{tagName}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ namespace Luban.Job.Common.Defs
|
|||
|
||||
public string FullNameWithTopModule => TypeUtil.MakeFullName(AssemblyBase.TopModule, FullName);
|
||||
|
||||
public string CsFullName => TypeUtil.MakeFullName(Namespace, Name);
|
||||
|
||||
public string JavaFullName => TypeUtil.MakeFullName(Namespace, Name);
|
||||
|
||||
public string GoFullName => TypeUtil.MakeGoFullName(Namespace, Name);
|
||||
|
|
@ -83,9 +85,7 @@ namespace Luban.Job.Common.Defs
|
|||
}
|
||||
}
|
||||
|
||||
public virtual void PreCompile() { }
|
||||
|
||||
public virtual void Compile()
|
||||
protected void ResolveExternalType()
|
||||
{
|
||||
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() { }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ namespace Luban.Job.Common.RawDefs
|
|||
public ELanguage Lan { get; set; }
|
||||
|
||||
public string TypeName { get; set; }
|
||||
|
||||
public string CreateExternalObjectFunction { get; set; }
|
||||
}
|
||||
|
||||
public class ExternalType
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using Luban.Job.Common.Defs;
|
||||
using Luban.Job.Common.Types;
|
||||
using Luban.Job.Common.Utils;
|
||||
|
||||
namespace Luban.Job.Common.TypeVisitors
|
||||
{
|
||||
|
|
@ -59,8 +60,7 @@ namespace Luban.Job.Common.TypeVisitors
|
|||
|
||||
public string Accept(TEnum type)
|
||||
{
|
||||
var mapper = type.DefineEnum.CurrentExternalTypeMapper;
|
||||
return mapper != null ? mapper.TypeName : type.DefineEnum.FullName;
|
||||
return ExternalTypeUtil.CsMapperToExternalType(type.DefineEnum);
|
||||
}
|
||||
|
||||
public string Accept(TString type)
|
||||
|
|
@ -80,7 +80,7 @@ namespace Luban.Job.Common.TypeVisitors
|
|||
|
||||
public string Accept(TBean type)
|
||||
{
|
||||
return type.Bean.FullName;
|
||||
return ExternalTypeUtil.CsMapperToExternalType(type.Bean);
|
||||
}
|
||||
|
||||
public string Accept(TArray type)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using Luban.Job.Common.Defs;
|
||||
using Luban.Job.Common.Types;
|
||||
using Luban.Job.Common.Utils;
|
||||
|
||||
namespace Luban.Job.Common.TypeVisitors
|
||||
{
|
||||
|
|
@ -79,7 +80,8 @@ namespace Luban.Job.Common.TypeVisitors
|
|||
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -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})";
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue