parent
125504e5a7
commit
732297411c
10
README.md
10
README.md
|
|
@ -57,8 +57,10 @@ Luban适合有以下需求的开发者:
|
||||||
- 使用云生成模式。生成极快,MMORPG这样大型项目也能秒内生成。日常增量生成基本在300ms以内。节省迭代时间。支持watch监测模式,数据目录变化立即重新生成。
|
- 使用云生成模式。生成极快,MMORPG这样大型项目也能秒内生成。日常增量生成基本在300ms以内。节省迭代时间。支持watch监测模式,数据目录变化立即重新生成。
|
||||||
- 灵活的数据源定义。一个表可以来自多个文件或者一个文件内定义多个表或者一个目录下所有文件甚至来自云表格,以及以上的组合
|
- 灵活的数据源定义。一个表可以来自多个文件或者一个文件内定义多个表或者一个目录下所有文件甚至来自云表格,以及以上的组合
|
||||||
- 支持表与字段级别分组。可以选择性地导出客户端或者服务器所用的表及字段
|
- 支持表与字段级别分组。可以选择性地导出客户端或者服务器所用的表及字段
|
||||||
- 多种导出数据格式支持。支持binary、json、lua 等导出数据格式
|
- 多种导出数据格式支持。支持binary、json、lua、xml、erlang 等导出数据格式
|
||||||
- 支持自定义数据模板。可以用模板文件定制导出格式。
|
- **====>强大灵活的定制能力<====**
|
||||||
|
- **支持代码模板,可以用自定义模板定制生成的代码格式**
|
||||||
|
- **支持数据模板,可以用模板文件定制导出格式**。意味着可以在不改动现有程序代码的情况下,把luban当作**配置处理前端**,生成自定义格式的数据与自己项目的配置加载代码配合工作。开发已久的项目或者已经上线的老项目,也能从luban强大的数据处理工作流中获益
|
||||||
- 支持数据标签。 可以选择导出符合要求的数据,发布正式数据时策划不必手动注释掉那些测试数据了
|
- 支持数据标签。 可以选择导出符合要求的数据,发布正式数据时策划不必手动注释掉那些测试数据了
|
||||||
- 强大的数据校验能力。支持内建数据格式检查;支持ref表引用检查(策划不用担心填错id);支持path资源检查(策划不用担心填错资源路径);支持range检查
|
- 强大的数据校验能力。支持内建数据格式检查;支持ref表引用检查(策划不用担心填错id);支持path资源检查(策划不用担心填错资源路径);支持range检查
|
||||||
- 支持常量别名。策划不必再为诸如 升级丹 这样的道具手写具体道具id了
|
- 支持常量别名。策划不必再为诸如 升级丹 这样的道具手写具体道具id了
|
||||||
|
|
@ -66,7 +68,6 @@ Luban适合有以下需求的开发者:
|
||||||
- 支持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有良好的配置代码提示能力
|
||||||
- 灵活的自定义生成能力。可以在不修改代码的情况下使用自定义模板取代默认生成模板。大多数自定义对象支持tags属性,允许通过tags生成特殊内容。
|
|
||||||
- **本地化支持**
|
- **本地化支持**
|
||||||
- 支持时间本地化。datetime类型数据会根据指定的timezone,转换为目标地区该时刻的UTC时间,方便程序使用。
|
- 支持时间本地化。datetime类型数据会根据指定的timezone,转换为目标地区该时刻的UTC时间,方便程序使用。
|
||||||
- 支持文本静态本地化。导出时所有text类型数据正确替换为最终的本地化字符串。绝大多数的业务功能不再需要运行根据本地化id去查找文本的内容,简化程序员的工作。
|
- 支持文本静态本地化。导出时所有text类型数据正确替换为最终的本地化字符串。绝大多数的业务功能不再需要运行根据本地化id去查找文本的内容,简化程序员的工作。
|
||||||
|
|
@ -80,7 +81,8 @@ Luban适合有以下需求的开发者:
|
||||||
- go (1.10+)
|
- go (1.10+)
|
||||||
- lua (5.1+)
|
- lua (5.1+)
|
||||||
- js 和 typescript (3.0+)
|
- js 和 typescript (3.0+)
|
||||||
- python (3.0+)
|
- python (3.0+)
|
||||||
|
- erlang (18+)
|
||||||
- 支持主流引擎和平台
|
- 支持主流引擎和平台
|
||||||
- unity + c#
|
- unity + c#
|
||||||
- unity + [tolua](https://github.com/topameng/tolua)、[xlua](https://github.com/Tencent/xLua)
|
- unity + [tolua](https://github.com/topameng/tolua)、[xlua](https://github.com/Tencent/xLua)
|
||||||
|
|
|
||||||
|
|
@ -7,118 +7,110 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.DataExporters
|
namespace Luban.Job.Cfg.DataExporters
|
||||||
{
|
{
|
||||||
class BinaryExportor : IDataActionVisitor<DefAssembly, ByteBuf>
|
class BinaryExportor : IDataActionVisitor<ByteBuf>
|
||||||
{
|
{
|
||||||
public static BinaryExportor Ins { get; } = new BinaryExportor();
|
public static BinaryExportor Ins { get; } = new BinaryExportor();
|
||||||
|
|
||||||
public void WriteList(List<Record> datas, DefAssembly ass, ByteBuf x)
|
public void WriteList(DefTable table, List<Record> datas, ByteBuf x)
|
||||||
{
|
{
|
||||||
x.WriteSize(datas.Count);
|
x.WriteSize(datas.Count);
|
||||||
foreach (var d in datas)
|
foreach (var d in datas)
|
||||||
{
|
{
|
||||||
d.Data.Apply(this, ass, x);
|
d.Data.Apply(this, x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DBool type, DefAssembly ass, ByteBuf x)
|
public void Accept(DBool type, ByteBuf x)
|
||||||
{
|
{
|
||||||
x.WriteBool(type.Value);
|
x.WriteBool(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DByte type, DefAssembly ass, ByteBuf x)
|
public void Accept(DByte type, ByteBuf x)
|
||||||
{
|
{
|
||||||
x.WriteByte(type.Value);
|
x.WriteByte(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DShort type, DefAssembly ass, ByteBuf x)
|
public void Accept(DShort type, ByteBuf x)
|
||||||
{
|
{
|
||||||
x.WriteShort(type.Value);
|
x.WriteShort(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DFshort type, DefAssembly ass, ByteBuf x)
|
public void Accept(DFshort type, ByteBuf x)
|
||||||
{
|
{
|
||||||
x.WriteFshort(type.Value);
|
x.WriteFshort(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DInt type, DefAssembly ass, ByteBuf x)
|
public void Accept(DInt type, ByteBuf x)
|
||||||
{
|
{
|
||||||
x.WriteInt(type.Value);
|
x.WriteInt(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DFint type, DefAssembly ass, ByteBuf x)
|
public void Accept(DFint type, ByteBuf x)
|
||||||
{
|
{
|
||||||
x.WriteFint(type.Value);
|
x.WriteFint(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DLong type, DefAssembly ass, ByteBuf x)
|
public void Accept(DLong type, ByteBuf x)
|
||||||
{
|
{
|
||||||
x.WriteLong(type.Value);
|
x.WriteLong(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DFlong type, DefAssembly ass, ByteBuf x)
|
public void Accept(DFlong type, ByteBuf x)
|
||||||
{
|
{
|
||||||
x.WriteFlong(type.Value);
|
x.WriteFlong(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DFloat type, DefAssembly ass, ByteBuf x)
|
public void Accept(DFloat type, ByteBuf x)
|
||||||
{
|
{
|
||||||
x.WriteFloat(type.Value);
|
x.WriteFloat(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DDouble type, DefAssembly ass, ByteBuf x)
|
public void Accept(DDouble type, ByteBuf x)
|
||||||
{
|
{
|
||||||
x.WriteDouble(type.Value);
|
x.WriteDouble(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DEnum type, DefAssembly ass, ByteBuf x)
|
public void Accept(DEnum type, ByteBuf x)
|
||||||
{
|
{
|
||||||
x.WriteInt(type.Value);
|
x.WriteInt(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DString type, DefAssembly ass, ByteBuf x)
|
public void Accept(DString type, ByteBuf x)
|
||||||
{
|
{
|
||||||
x.WriteString(type.Value);
|
x.WriteString(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DBytes type, DefAssembly ass, ByteBuf x)
|
public void Accept(DBytes type, ByteBuf x)
|
||||||
{
|
{
|
||||||
x.WriteBytes(type.Value);
|
x.WriteBytes(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DText type, DefAssembly ass, ByteBuf x)
|
public void Accept(DText type, ByteBuf x)
|
||||||
{
|
{
|
||||||
x.WriteString(type.Key);
|
x.WriteString(type.Key);
|
||||||
|
var ass = DefAssembly.LocalAssebmly;
|
||||||
x.WriteString(type.GetText(ass.ExportTextTable, ass.NotConvertTextSet));
|
x.WriteString(type.GetText(ass.ExportTextTable, ass.NotConvertTextSet));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DBean type, DefAssembly ass, ByteBuf x)
|
public void Accept(DBean type, ByteBuf x)
|
||||||
{
|
{
|
||||||
var bean = type.Type;
|
var bean = type.Type;
|
||||||
if (bean.IsAbstractType)
|
if (bean.IsAbstractType)
|
||||||
{
|
{
|
||||||
// 调整设计后,多态bean不会为空
|
|
||||||
//if (type.ImplType == null)
|
|
||||||
//{
|
|
||||||
// x.WriteInt(0);
|
|
||||||
// return;
|
|
||||||
//}
|
|
||||||
x.WriteInt(type.ImplType.Id);
|
x.WriteInt(type.ImplType.Id);
|
||||||
}
|
}
|
||||||
int index = -1;
|
|
||||||
|
var defFields = type.ImplType.HierarchyExportFields;
|
||||||
|
int index = 0;
|
||||||
foreach (var field in type.Fields)
|
foreach (var field in type.Fields)
|
||||||
{
|
{
|
||||||
++index;
|
var defField = defFields[index++];
|
||||||
var defField = (DefField)type.ImplType.HierarchyFields[index];
|
|
||||||
if (!defField.NeedExport)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (defField.CType.IsNullable)
|
if (defField.CType.IsNullable)
|
||||||
{
|
{
|
||||||
if (field != null)
|
if (field != null)
|
||||||
{
|
{
|
||||||
x.WriteBool(true);
|
x.WriteBool(true);
|
||||||
field.Apply(this, ass, x);
|
field.Apply(this, x);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -127,64 +119,64 @@ namespace Luban.Job.Cfg.DataExporters
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
field.Apply(this, ass, x);
|
field.Apply(this, x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteList(List<DType> datas, DefAssembly ass, ByteBuf x)
|
public void WriteList(List<DType> datas, ByteBuf x)
|
||||||
{
|
{
|
||||||
x.WriteSize(datas.Count);
|
x.WriteSize(datas.Count);
|
||||||
foreach (var d in datas)
|
foreach (var d in datas)
|
||||||
{
|
{
|
||||||
d.Apply(this, ass, x);
|
d.Apply(this, x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DArray type, DefAssembly ass, ByteBuf x)
|
public void Accept(DArray type, ByteBuf x)
|
||||||
{
|
{
|
||||||
WriteList(type.Datas, ass, x);
|
WriteList(type.Datas, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DList type, DefAssembly ass, ByteBuf x)
|
public void Accept(DList type, ByteBuf x)
|
||||||
{
|
{
|
||||||
WriteList(type.Datas, ass, x);
|
WriteList(type.Datas, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DSet type, DefAssembly ass, ByteBuf x)
|
public void Accept(DSet type, ByteBuf x)
|
||||||
{
|
{
|
||||||
WriteList(type.Datas, ass, x);
|
WriteList(type.Datas, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DMap type, DefAssembly ass, ByteBuf x)
|
public void Accept(DMap type, ByteBuf x)
|
||||||
{
|
{
|
||||||
Dictionary<DType, DType> datas = type.Datas;
|
Dictionary<DType, DType> datas = type.Datas;
|
||||||
x.WriteSize(datas.Count);
|
x.WriteSize(datas.Count);
|
||||||
foreach (var e in datas)
|
foreach (var e in datas)
|
||||||
{
|
{
|
||||||
e.Key.Apply(this, ass, x);
|
e.Key.Apply(this, x);
|
||||||
e.Value.Apply(this, ass, x);
|
e.Value.Apply(this, x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DVector2 type, DefAssembly ass, ByteBuf x)
|
public void Accept(DVector2 type, ByteBuf x)
|
||||||
{
|
{
|
||||||
x.WriteVector2(type.Value);
|
x.WriteVector2(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DVector3 type, DefAssembly ass, ByteBuf x)
|
public void Accept(DVector3 type, ByteBuf x)
|
||||||
{
|
{
|
||||||
x.WriteVector3(type.Value);
|
x.WriteVector3(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DVector4 type, DefAssembly ass, ByteBuf x)
|
public void Accept(DVector4 type, ByteBuf x)
|
||||||
{
|
{
|
||||||
x.WriteVector4(type.Value);
|
x.WriteVector4(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DDateTime type, DefAssembly ass, ByteBuf x)
|
public void Accept(DDateTime type, ByteBuf x)
|
||||||
{
|
{
|
||||||
x.WriteInt(type.GetUnixTime(ass.TimeZone));
|
x.WriteInt(type.GetUnixTime(DefAssembly.LocalAssebmly.TimeZone));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
using Luban.Job.Cfg.Datas;
|
||||||
|
using Luban.Job.Cfg.DataVisitors;
|
||||||
|
using Luban.Job.Cfg.Defs;
|
||||||
|
using Luban.Job.Cfg.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Luban.Job.Cfg.DataExporters
|
||||||
|
{
|
||||||
|
class ErlangExport
|
||||||
|
{
|
||||||
|
public static ErlangExport Ins { get; } = new();
|
||||||
|
|
||||||
|
public void ExportTableSingleton(DefTable t, Record record, StringBuilder s)
|
||||||
|
{
|
||||||
|
s.Append($"-module({t.FullName.Replace('.', '_').ToLower()}).").AppendLine();
|
||||||
|
s.Append($"-export([get_data/0]).").AppendLine();
|
||||||
|
|
||||||
|
|
||||||
|
s.Append("get_data() -> ").AppendLine();
|
||||||
|
s.Append('\t').Append(record.Data.Apply(ToErlangLiteralVisitor.Ins));
|
||||||
|
s.Append('.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ExportTableMap(DefTable t, List<Record> records, StringBuilder s)
|
||||||
|
{
|
||||||
|
s.Append($"-module({t.FullName.Replace('.', '_').ToLower()}).").AppendLine();
|
||||||
|
s.Append($"-export([get_data_map/0, get_key_list/0]).").AppendLine();
|
||||||
|
|
||||||
|
s.Append("get_data_map() -> #{").AppendLine();
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
foreach (Record r in records)
|
||||||
|
{
|
||||||
|
if (index++ > 0)
|
||||||
|
{
|
||||||
|
s.Append(',').AppendLine();
|
||||||
|
}
|
||||||
|
DBean d = r.Data;
|
||||||
|
s.Append($"\t{d.GetField(t.Index).Apply(ToErlangLiteralVisitor.Ins)} => ");
|
||||||
|
s.Append(d.Apply(ToErlangLiteralVisitor.Ins));
|
||||||
|
}
|
||||||
|
s.Append("}.").AppendLine();
|
||||||
|
|
||||||
|
s.Append($"get_key_list() ->").AppendLine();
|
||||||
|
s.Append($"\t[{string.Join(',', records.Select(r => r.Data.GetField(t.Index).Apply(ToErlangLiteralVisitor.Ins)))}].");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -15,13 +15,13 @@ namespace Luban.Job.Cfg.DataExporters
|
||||||
{
|
{
|
||||||
public new static Json2Exportor Ins { get; } = new();
|
public new static Json2Exportor Ins { get; } = new();
|
||||||
|
|
||||||
public void WriteAsObject(DefTable table, List<Record> datas, DefAssembly ass, Utf8JsonWriter x)
|
public void WriteAsObject(DefTable table, List<Record> datas, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
switch (table.Mode)
|
switch (table.Mode)
|
||||||
{
|
{
|
||||||
case RawDefs.ETableMode.ONE:
|
case RawDefs.ETableMode.ONE:
|
||||||
{
|
{
|
||||||
this.Accept(datas[0].Data, ass, x);
|
this.Accept(datas[0].Data, x);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RawDefs.ETableMode.MAP:
|
case RawDefs.ETableMode.MAP:
|
||||||
|
|
@ -34,7 +34,7 @@ namespace Luban.Job.Cfg.DataExporters
|
||||||
var indexFieldData = rec.Data.GetField(indexName);
|
var indexFieldData = rec.Data.GetField(indexName);
|
||||||
|
|
||||||
x.WritePropertyName(indexFieldData.Apply(ToJsonPropertyNameVisitor.Ins));
|
x.WritePropertyName(indexFieldData.Apply(ToJsonPropertyNameVisitor.Ins));
|
||||||
this.Accept(rec.Data, ass, x);
|
this.Accept(rec.Data, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
x.WriteEndObject();
|
x.WriteEndObject();
|
||||||
|
|
@ -47,13 +47,13 @@ namespace Luban.Job.Cfg.DataExporters
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Accept(DMap type, DefAssembly ass, Utf8JsonWriter x)
|
public override void Accept(DMap type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
x.WriteStartObject();
|
x.WriteStartObject();
|
||||||
foreach (var d in type.Datas)
|
foreach (var d in type.Datas)
|
||||||
{
|
{
|
||||||
x.WritePropertyName(d.Key.Apply(ToJsonPropertyNameVisitor.Ins));
|
x.WritePropertyName(d.Key.Apply(ToJsonPropertyNameVisitor.Ins));
|
||||||
d.Value.Apply(this, ass, x);
|
d.Value.Apply(this, x);
|
||||||
}
|
}
|
||||||
x.WriteEndObject();
|
x.WriteEndObject();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,96 +7,97 @@ using System.Text.Json;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.DataExporters
|
namespace Luban.Job.Cfg.DataExporters
|
||||||
{
|
{
|
||||||
class JsonExportor : IDataActionVisitor<DefAssembly, Utf8JsonWriter>
|
class JsonExportor : IDataActionVisitor<Utf8JsonWriter>
|
||||||
{
|
{
|
||||||
public static JsonExportor Ins { get; } = new JsonExportor();
|
public static JsonExportor Ins { get; } = new JsonExportor();
|
||||||
|
|
||||||
public void WriteAsArray(List<Record> datas, DefAssembly ass, Utf8JsonWriter x)
|
public void WriteAsArray(List<Record> datas, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
x.WriteStartArray();
|
x.WriteStartArray();
|
||||||
foreach (var d in datas)
|
foreach (var d in datas)
|
||||||
{
|
{
|
||||||
d.Data.Apply(this, ass, x);
|
d.Data.Apply(this, x);
|
||||||
}
|
}
|
||||||
x.WriteEndArray();
|
x.WriteEndArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DBool type, DefAssembly ass, Utf8JsonWriter x)
|
public void Accept(DBool type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
x.WriteBooleanValue(type.Value);
|
x.WriteBooleanValue(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DByte type, DefAssembly ass, Utf8JsonWriter x)
|
public void Accept(DByte type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
x.WriteNumberValue(type.Value);
|
x.WriteNumberValue(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DShort type, DefAssembly ass, Utf8JsonWriter x)
|
public void Accept(DShort type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
x.WriteNumberValue(type.Value);
|
x.WriteNumberValue(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DFshort type, DefAssembly ass, Utf8JsonWriter x)
|
public void Accept(DFshort type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
x.WriteNumberValue(type.Value);
|
x.WriteNumberValue(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DInt type, DefAssembly ass, Utf8JsonWriter x)
|
public void Accept(DInt type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
x.WriteNumberValue(type.Value);
|
x.WriteNumberValue(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DFint type, DefAssembly ass, Utf8JsonWriter x)
|
public void Accept(DFint type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
x.WriteNumberValue(type.Value);
|
x.WriteNumberValue(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DLong type, DefAssembly ass, Utf8JsonWriter x)
|
public void Accept(DLong type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
x.WriteNumberValue(type.Value);
|
x.WriteNumberValue(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DFlong type, DefAssembly ass, Utf8JsonWriter x)
|
public void Accept(DFlong type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
x.WriteNumberValue(type.Value);
|
x.WriteNumberValue(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DFloat type, DefAssembly ass, Utf8JsonWriter x)
|
public void Accept(DFloat type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
x.WriteNumberValue(type.Value);
|
x.WriteNumberValue(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DDouble type, DefAssembly ass, Utf8JsonWriter x)
|
public void Accept(DDouble type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
x.WriteNumberValue(type.Value);
|
x.WriteNumberValue(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DEnum type, DefAssembly ass, Utf8JsonWriter x)
|
public void Accept(DEnum type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
x.WriteNumberValue(type.Value);
|
x.WriteNumberValue(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DString type, DefAssembly ass, Utf8JsonWriter x)
|
public void Accept(DString type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
x.WriteStringValue(type.Value);
|
x.WriteStringValue(type.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DBytes type, DefAssembly ass, Utf8JsonWriter x)
|
public void Accept(DBytes type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DText type, DefAssembly ass, Utf8JsonWriter x)
|
public void Accept(DText type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
x.WriteStartObject();
|
x.WriteStartObject();
|
||||||
x.WritePropertyName(DText.KEY_NAME);
|
x.WritePropertyName(DText.KEY_NAME);
|
||||||
x.WriteStringValue(type.Key);
|
x.WriteStringValue(type.Key);
|
||||||
x.WritePropertyName(DText.TEXT_NAME);
|
x.WritePropertyName(DText.TEXT_NAME);
|
||||||
|
var ass = DefAssembly.LocalAssebmly;
|
||||||
x.WriteStringValue(type.GetText(ass.ExportTextTable, ass.NotConvertTextSet));
|
x.WriteStringValue(type.GetText(ass.ExportTextTable, ass.NotConvertTextSet));
|
||||||
x.WriteEndObject();
|
x.WriteEndObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DBean type, DefAssembly ass, Utf8JsonWriter x)
|
public void Accept(DBean type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
x.WriteStartObject();
|
x.WriteStartObject();
|
||||||
|
|
||||||
|
|
@ -106,15 +107,11 @@ namespace Luban.Job.Cfg.DataExporters
|
||||||
x.WriteStringValue(type.ImplType.Name);
|
x.WriteStringValue(type.ImplType.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
var defFields = type.ImplType.HierarchyFields;
|
var defFields = type.ImplType.HierarchyExportFields;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
foreach (var d in type.Fields)
|
foreach (var d in type.Fields)
|
||||||
{
|
{
|
||||||
var defField = (DefField)defFields[index++];
|
var defField = defFields[index++];
|
||||||
if (!defField.NeedExport)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 特殊处理 bean 多态类型
|
// 特殊处理 bean 多态类型
|
||||||
// 另外,不生成 xxx:null 这样
|
// 另外,不生成 xxx:null 这样
|
||||||
|
|
@ -125,51 +122,51 @@ namespace Luban.Job.Cfg.DataExporters
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
x.WritePropertyName(defField.Name);
|
x.WritePropertyName(defField.Name);
|
||||||
d.Apply(this, ass, x);
|
d.Apply(this, x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
x.WriteEndObject();
|
x.WriteEndObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteList(List<DType> datas, DefAssembly ass, Utf8JsonWriter x)
|
public void WriteList(List<DType> datas, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
x.WriteStartArray();
|
x.WriteStartArray();
|
||||||
foreach (var d in datas)
|
foreach (var d in datas)
|
||||||
{
|
{
|
||||||
d.Apply(this, ass, x);
|
d.Apply(this, x);
|
||||||
}
|
}
|
||||||
x.WriteEndArray();
|
x.WriteEndArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DArray type, DefAssembly ass, Utf8JsonWriter x)
|
public void Accept(DArray type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
WriteList(type.Datas, ass, x);
|
WriteList(type.Datas, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DList type, DefAssembly ass, Utf8JsonWriter x)
|
public void Accept(DList type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
WriteList(type.Datas, ass, x);
|
WriteList(type.Datas, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DSet type, DefAssembly ass, Utf8JsonWriter x)
|
public void Accept(DSet type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
WriteList(type.Datas, ass, x);
|
WriteList(type.Datas, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Accept(DMap type, DefAssembly ass, Utf8JsonWriter x)
|
public virtual void Accept(DMap type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
x.WriteStartArray();
|
x.WriteStartArray();
|
||||||
foreach (var d in type.Datas)
|
foreach (var d in type.Datas)
|
||||||
{
|
{
|
||||||
x.WriteStartArray();
|
x.WriteStartArray();
|
||||||
d.Key.Apply(this, ass, x);
|
d.Key.Apply(this, x);
|
||||||
d.Value.Apply(this, ass, x);
|
d.Value.Apply(this, x);
|
||||||
x.WriteEndArray();
|
x.WriteEndArray();
|
||||||
}
|
}
|
||||||
x.WriteEndArray();
|
x.WriteEndArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DVector2 type, DefAssembly ass, Utf8JsonWriter x)
|
public void Accept(DVector2 type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
x.WriteStartObject();
|
x.WriteStartObject();
|
||||||
x.WriteNumber("x", type.Value.X);
|
x.WriteNumber("x", type.Value.X);
|
||||||
|
|
@ -177,7 +174,7 @@ namespace Luban.Job.Cfg.DataExporters
|
||||||
x.WriteEndObject();
|
x.WriteEndObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DVector3 type, DefAssembly ass, Utf8JsonWriter x)
|
public void Accept(DVector3 type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
x.WriteStartObject();
|
x.WriteStartObject();
|
||||||
x.WriteNumber("x", type.Value.X);
|
x.WriteNumber("x", type.Value.X);
|
||||||
|
|
@ -186,7 +183,7 @@ namespace Luban.Job.Cfg.DataExporters
|
||||||
x.WriteEndObject();
|
x.WriteEndObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DVector4 type, DefAssembly ass, Utf8JsonWriter x)
|
public void Accept(DVector4 type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
x.WriteStartObject();
|
x.WriteStartObject();
|
||||||
x.WriteNumber("x", type.Value.X);
|
x.WriteNumber("x", type.Value.X);
|
||||||
|
|
@ -196,9 +193,9 @@ namespace Luban.Job.Cfg.DataExporters
|
||||||
x.WriteEndObject();
|
x.WriteEndObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DDateTime type, DefAssembly ass, Utf8JsonWriter x)
|
public void Accept(DDateTime type, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
x.WriteNumberValue(type.GetUnixTime(ass.TimeZone));
|
x.WriteNumberValue(type.GetUnixTime(DefAssembly.LocalAssebmly.TimeZone));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,208 +9,28 @@ using System.Text;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.DataExporters
|
namespace Luban.Job.Cfg.DataExporters
|
||||||
{
|
{
|
||||||
class LuaExportor : IDataActionVisitor<DefAssembly, StringBuilder>
|
class LuaExportor
|
||||||
{
|
{
|
||||||
public static LuaExportor Ins { get; } = new LuaExportor();
|
public static LuaExportor Ins { get; } = new LuaExportor();
|
||||||
|
|
||||||
public void ExportTableOne(DefTable t, List<Record> records, List<string> result)
|
public void ExportTableSingleton(DefTable t, Record record, StringBuilder result)
|
||||||
{
|
{
|
||||||
result.Add("return ");
|
result.Append("return ").AppendLine();
|
||||||
var s = new StringBuilder();
|
result.Append(record.Data.Apply(ToLuaLiteralVisitor.Ins));
|
||||||
Accept(records[0].Data, t.Assembly, s);
|
|
||||||
result.Add(s.ToString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ExportTableOneKeyMap(DefTable t, List<Record> records, List<string> result)
|
public void ExportTableMap(DefTable t, List<Record> records, StringBuilder s)
|
||||||
{
|
{
|
||||||
result.Add("return ");
|
s.Append("return").AppendLine();
|
||||||
result.Add("{");
|
s.Append('{').AppendLine();
|
||||||
var s = new StringBuilder();
|
|
||||||
var ks = new StringBuilder();
|
|
||||||
foreach (Record r in records)
|
foreach (Record r in records)
|
||||||
{
|
{
|
||||||
DBean d = r.Data;
|
DBean d = r.Data;
|
||||||
s.Clear();
|
s.Append($"[{d.GetField(t.Index).Apply(ToLuaLiteralVisitor.Ins)}] = ");
|
||||||
s.Append($"[{ToLuaCodeString(d.GetField(t.Index), t.Assembly, ks)}] = ");
|
s.Append(d.Apply(ToLuaLiteralVisitor.Ins));
|
||||||
Accept(d, t.Assembly, s);
|
s.Append(',').AppendLine();
|
||||||
s.Append(',');
|
|
||||||
result.Add(s.ToString());
|
|
||||||
}
|
}
|
||||||
result.Add("}");
|
s.Append('}');
|
||||||
}
|
|
||||||
|
|
||||||
private string ToLuaCodeString(DType data, DefAssembly ass, StringBuilder b)
|
|
||||||
{
|
|
||||||
b.Clear();
|
|
||||||
data.Apply(this, ass, b);
|
|
||||||
return b.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Accept(DBool type, DefAssembly ass, StringBuilder line)
|
|
||||||
{
|
|
||||||
line.Append(type.Value ? "true" : "false");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Accept(DByte type, DefAssembly ass, StringBuilder line)
|
|
||||||
{
|
|
||||||
line.Append(type.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Accept(DShort type, DefAssembly ass, StringBuilder line)
|
|
||||||
{
|
|
||||||
line.Append(type.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Accept(DFshort type, DefAssembly ass, StringBuilder line)
|
|
||||||
{
|
|
||||||
line.Append(type.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Accept(DInt type, DefAssembly ass, StringBuilder line)
|
|
||||||
{
|
|
||||||
line.Append(type.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Accept(DFint type, DefAssembly ass, StringBuilder line)
|
|
||||||
{
|
|
||||||
line.Append(type.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Accept(DLong type, DefAssembly ass, StringBuilder line)
|
|
||||||
{
|
|
||||||
line.Append(type.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Accept(DFlong type, DefAssembly ass, StringBuilder line)
|
|
||||||
{
|
|
||||||
line.Append(type.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Accept(DFloat type, DefAssembly ass, StringBuilder line)
|
|
||||||
{
|
|
||||||
line.Append(type.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Accept(DDouble type, DefAssembly ass, StringBuilder line)
|
|
||||||
{
|
|
||||||
line.Append(type.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Accept(DEnum type, DefAssembly ass, StringBuilder line)
|
|
||||||
{
|
|
||||||
line.Append(type.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Accept(DString type, DefAssembly ass, StringBuilder line)
|
|
||||||
{
|
|
||||||
line.Append('\'').Append(DataUtil.EscapeString(type.Value)).Append('\'');
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Accept(DBytes type, DefAssembly ass, StringBuilder line)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Accept(DText type, DefAssembly ass, StringBuilder line)
|
|
||||||
{
|
|
||||||
line.Append($"{{{DText.KEY_NAME}='{type.Key}',{DText.TEXT_NAME}='{DataUtil.EscapeString(type.GetText(ass.ExportTextTable, ass.NotConvertTextSet))}'}}");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Accept(DBean type, DefAssembly ass, StringBuilder line)
|
|
||||||
{
|
|
||||||
var bean = type.Type;
|
|
||||||
if (bean.IsAbstractType)
|
|
||||||
{
|
|
||||||
line.Append($"{{ _name='{type.ImplType.Name}',");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
line.Append('{');
|
|
||||||
}
|
|
||||||
int index = -1;
|
|
||||||
foreach (var field in type.Fields)
|
|
||||||
{
|
|
||||||
++index;
|
|
||||||
var defField = (DefField)type.ImplType.HierarchyFields[index];
|
|
||||||
if (!defField.NeedExport)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (field != null)
|
|
||||||
{
|
|
||||||
line.Append(defField.Name).Append('=');
|
|
||||||
field.Apply(this, ass, line);
|
|
||||||
line.Append(',');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
line.Append("}");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Accept(DArray type, DefAssembly ass, StringBuilder line)
|
|
||||||
{
|
|
||||||
line.Append('{');
|
|
||||||
foreach (var d in type.Datas)
|
|
||||||
{
|
|
||||||
d.Apply(this, ass, line);
|
|
||||||
line.Append(',');
|
|
||||||
}
|
|
||||||
line.Append('}');
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Accept(DList type, DefAssembly ass, StringBuilder line)
|
|
||||||
{
|
|
||||||
line.Append('{');
|
|
||||||
foreach (var d in type.Datas)
|
|
||||||
{
|
|
||||||
d.Apply(this, ass, line);
|
|
||||||
line.Append(',');
|
|
||||||
}
|
|
||||||
line.Append('}');
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Accept(DSet type, DefAssembly ass, StringBuilder line)
|
|
||||||
{
|
|
||||||
line.Append('{');
|
|
||||||
foreach (var d in type.Datas)
|
|
||||||
{
|
|
||||||
d.Apply(this, ass, line);
|
|
||||||
line.Append(',');
|
|
||||||
}
|
|
||||||
line.Append('}');
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Accept(DMap type, DefAssembly ass, StringBuilder line)
|
|
||||||
{
|
|
||||||
line.Append('{');
|
|
||||||
foreach ((var k, var v) in type.Datas)
|
|
||||||
{
|
|
||||||
line.Append('[');
|
|
||||||
k.Apply(this, ass, line);
|
|
||||||
line.Append("]=");
|
|
||||||
v.Apply(this, ass, line);
|
|
||||||
line.Append(',');
|
|
||||||
}
|
|
||||||
line.Append('}');
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Accept(DVector2 type, DefAssembly ass, StringBuilder line)
|
|
||||||
{
|
|
||||||
line.Append($"{{x={type.Value.X},y={type.Value.Y}}}");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Accept(DVector3 type, DefAssembly ass, StringBuilder line)
|
|
||||||
{
|
|
||||||
line.Append($"{{x={type.Value.X},y={type.Value.Y},z={type.Value.Z}}}");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Accept(DVector4 type, DefAssembly ass, StringBuilder line)
|
|
||||||
{
|
|
||||||
line.Append($"{{x={type.Value.X},y={type.Value.Y},z={type.Value.Z},w={type.Value.W}}}");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Accept(DDateTime type, DefAssembly ass, StringBuilder line)
|
|
||||||
{
|
|
||||||
line.Append(type.GetUnixTime(ass.TimeZone));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ namespace Luban.Job.Cfg.DataVisitors
|
||||||
|
|
||||||
public bool Accept(DDateTime type)
|
public bool Accept(DDateTime type)
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,126 @@
|
||||||
|
using Luban.Job.Cfg.Datas;
|
||||||
|
using System;
|
||||||
|
using System.Numerics;
|
||||||
|
|
||||||
|
namespace Luban.Job.Cfg.DataVisitors
|
||||||
|
{
|
||||||
|
class IsSimpleLiteralDataVisitor : IDataFuncVisitor<bool>
|
||||||
|
{
|
||||||
|
public static IsSimpleLiteralDataVisitor Ins { get; } = new();
|
||||||
|
|
||||||
|
public bool Accept(DBool type)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Accept(DByte type)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Accept(DShort type)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Accept(DFshort type)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Accept(DInt type)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Accept(DFint type)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Accept(DLong type)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Accept(DFlong type)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Accept(DFloat type)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Accept(DDouble type)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Accept(DEnum type)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Accept(DString type)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Accept(DBytes type)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Accept(DText type)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Accept(DBean type)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Accept(DArray type)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Accept(DList type)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Accept(DSet type)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Accept(DMap type)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Accept(DVector2 type)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Accept(DVector3 type)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Accept(DVector4 type)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Accept(DDateTime type)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -13,39 +13,38 @@ namespace Luban.Job.Cfg.DataVisitors
|
||||||
public override string Accept(DText type)
|
public override string Accept(DText type)
|
||||||
{
|
{
|
||||||
var ass = DefAssembly.LocalAssebmly as DefAssembly;
|
var ass = DefAssembly.LocalAssebmly as DefAssembly;
|
||||||
return $"{{\"{DText.KEY_NAME}\":\"{type.Key}\",\"{DText.TEXT_NAME}\":\"{DataUtil.EscapeString(type.GetText(ass.ExportTextTable, ass.NotConvertTextSet))}\"}}";
|
return $"#{{{DText.KEY_NAME}=>\"{type.Key}\",{DText.TEXT_NAME}=>\"{DataUtil.EscapeString(type.GetText(ass.ExportTextTable, ass.NotConvertTextSet))}\"}}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Accept(DBean type)
|
public override string Accept(DBean type)
|
||||||
{
|
{
|
||||||
var x = new StringBuilder();
|
var x = new StringBuilder();
|
||||||
var bean = type.ImplType;
|
if (type.Type.IsAbstractType)
|
||||||
if (bean.IsAbstractType)
|
|
||||||
{
|
{
|
||||||
x.Append($"{{ \"_name\":\"{type.ImplType.Name}\",");
|
x.Append($"#{{name__ => \"{type.ImplType.Name}\"");
|
||||||
|
if (type.Fields.Count > 0)
|
||||||
|
{
|
||||||
|
x.Append(',');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
x.Append('{');
|
x.Append("#{");
|
||||||
}
|
}
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
foreach (var f in type.Fields)
|
foreach (var f in type.Fields)
|
||||||
{
|
{
|
||||||
if (index >= 1)
|
var defField = type.ImplType.HierarchyFields[index++];
|
||||||
|
if (f == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (index > 1)
|
||||||
{
|
{
|
||||||
x.Append(',');
|
x.Append(',');
|
||||||
}
|
}
|
||||||
var defField = type.ImplType.HierarchyFields[index++];
|
x.Append($"{defField.Name} => {f.Apply(this)}");
|
||||||
x.Append('\"').Append(defField.Name).Append('\"').Append(':');
|
|
||||||
if (f != null)
|
|
||||||
{
|
|
||||||
x.Append(f.Apply(this));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
x.Append("null");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
x.Append('}');
|
x.Append('}');
|
||||||
return x.ToString();
|
return x.ToString();
|
||||||
|
|
@ -58,11 +57,10 @@ namespace Luban.Job.Cfg.DataVisitors
|
||||||
int index = 0;
|
int index = 0;
|
||||||
foreach (var e in datas)
|
foreach (var e in datas)
|
||||||
{
|
{
|
||||||
if (index > 0)
|
if (index++ > 0)
|
||||||
{
|
{
|
||||||
x.Append(',');
|
x.Append(',');
|
||||||
}
|
}
|
||||||
++index;
|
|
||||||
x.Append(e.Apply(this));
|
x.Append(e.Apply(this));
|
||||||
}
|
}
|
||||||
x.Append(']');
|
x.Append(']');
|
||||||
|
|
@ -92,18 +90,15 @@ namespace Luban.Job.Cfg.DataVisitors
|
||||||
public override string Accept(DMap type)
|
public override string Accept(DMap type)
|
||||||
{
|
{
|
||||||
var x = new StringBuilder();
|
var x = new StringBuilder();
|
||||||
x.Append('{');
|
x.Append("#{");
|
||||||
int index = 0;
|
int index = 0;
|
||||||
foreach (var e in type.Datas)
|
foreach (var e in type.Datas)
|
||||||
{
|
{
|
||||||
if (index > 0)
|
if (index++ > 0)
|
||||||
{
|
{
|
||||||
x.Append(',');
|
x.Append(',');
|
||||||
}
|
}
|
||||||
++index;
|
x.Append($"{e.Key.Apply(this)} => {e.Value.Apply(this)}");
|
||||||
x.Append('"').Append(e.Key.ToString()).Append('"');
|
|
||||||
x.Append(':');
|
|
||||||
x.Append(e.Value.Apply(this));
|
|
||||||
}
|
}
|
||||||
x.Append('}');
|
x.Append('}');
|
||||||
return x.ToString();
|
return x.ToString();
|
||||||
|
|
@ -112,19 +107,19 @@ namespace Luban.Job.Cfg.DataVisitors
|
||||||
public override string Accept(DVector2 type)
|
public override string Accept(DVector2 type)
|
||||||
{
|
{
|
||||||
var v = type.Value;
|
var v = type.Value;
|
||||||
return $"{{\"x\":{v.X},\"y\":{v.Y}}}";
|
return $"#{{x=>{v.X},y=>{v.Y}}}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Accept(DVector3 type)
|
public override string Accept(DVector3 type)
|
||||||
{
|
{
|
||||||
var v = type.Value;
|
var v = type.Value;
|
||||||
return $"{{\"x\":{v.X},\"y\":{v.Y},\"z\":{v.Z}}}";
|
return $"#{{x=>{v.X},y=>{v.Y},z=>{v.Z}}}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Accept(DVector4 type)
|
public override string Accept(DVector4 type)
|
||||||
{
|
{
|
||||||
var v = type.Value;
|
var v = type.Value;
|
||||||
return $"{{\"x\":{v.X},\"y\":{v.Y},\"z\":{v.Z},\"w\":{v.W}}}";
|
return $"#{{x=>{v.X},y=>{v.Y},z=>{v.Z},w=>{v.W}}}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,17 +12,20 @@ namespace Luban.Job.Cfg.DataVisitors
|
||||||
|
|
||||||
public override string Accept(DText type)
|
public override string Accept(DText type)
|
||||||
{
|
{
|
||||||
var ass = DefAssembly.LocalAssebmly as DefAssembly;
|
var ass = DefAssembly.LocalAssebmly;
|
||||||
return $"{{\"{DText.KEY_NAME}\":\"{type.Key}\",\"{DText.TEXT_NAME}\":\"{DataUtil.EscapeString(type.GetText(ass.ExportTextTable, ass.NotConvertTextSet))}\"}}";
|
return $"{{\"{DText.KEY_NAME}\":\"{type.Key}\",\"{DText.TEXT_NAME}\":\"{DataUtil.EscapeString(type.GetText(ass.ExportTextTable, ass.NotConvertTextSet))}\"}}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Accept(DBean type)
|
public override string Accept(DBean type)
|
||||||
{
|
{
|
||||||
var x = new StringBuilder();
|
var x = new StringBuilder();
|
||||||
var bean = type.ImplType;
|
if (type.Type.IsAbstractType)
|
||||||
if (bean.IsAbstractType)
|
|
||||||
{
|
{
|
||||||
x.Append($"{{ \"_name\":\"{type.ImplType.Name}\",");
|
x.Append($"{{ \"_name\":\"{type.ImplType.Name}\"");
|
||||||
|
if (type.Fields.Count > 0)
|
||||||
|
{
|
||||||
|
x.Append(',');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -32,20 +35,17 @@ namespace Luban.Job.Cfg.DataVisitors
|
||||||
int index = 0;
|
int index = 0;
|
||||||
foreach (var f in type.Fields)
|
foreach (var f in type.Fields)
|
||||||
{
|
{
|
||||||
if (index >= 1)
|
var defField = type.ImplType.HierarchyExportFields[index++];
|
||||||
|
if (f == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (index > 1)
|
||||||
{
|
{
|
||||||
x.Append(',');
|
x.Append(',');
|
||||||
}
|
}
|
||||||
var defField = type.ImplType.HierarchyExportFields[index++];
|
|
||||||
x.Append('\"').Append(defField.Name).Append('\"').Append(':');
|
x.Append('\"').Append(defField.Name).Append('\"').Append(':');
|
||||||
if (f != null)
|
x.Append(f.Apply(this));
|
||||||
{
|
|
||||||
x.Append(f.Apply(this));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
x.Append("null");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
x.Append('}');
|
x.Append('}');
|
||||||
return x.ToString();
|
return x.ToString();
|
||||||
|
|
@ -58,11 +58,10 @@ namespace Luban.Job.Cfg.DataVisitors
|
||||||
int index = 0;
|
int index = 0;
|
||||||
foreach (var e in datas)
|
foreach (var e in datas)
|
||||||
{
|
{
|
||||||
if (index > 0)
|
if (index++ > 0)
|
||||||
{
|
{
|
||||||
x.Append(',');
|
x.Append(',');
|
||||||
}
|
}
|
||||||
++index;
|
|
||||||
x.Append(e.Apply(this));
|
x.Append(e.Apply(this));
|
||||||
}
|
}
|
||||||
x.Append(']');
|
x.Append(']');
|
||||||
|
|
@ -96,11 +95,10 @@ namespace Luban.Job.Cfg.DataVisitors
|
||||||
int index = 0;
|
int index = 0;
|
||||||
foreach (var e in type.Datas)
|
foreach (var e in type.Datas)
|
||||||
{
|
{
|
||||||
if (index > 0)
|
if (index++ > 0)
|
||||||
{
|
{
|
||||||
x.Append(',');
|
x.Append(',');
|
||||||
}
|
}
|
||||||
++index;
|
|
||||||
x.Append('"').Append(e.Key.Apply(ToJsonPropertyNameVisitor.Ins)).Append('"');
|
x.Append('"').Append(e.Key.Apply(ToJsonPropertyNameVisitor.Ins)).Append('"');
|
||||||
x.Append(':');
|
x.Append(':');
|
||||||
x.Append(e.Value.Apply(this));
|
x.Append(e.Value.Apply(this));
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,7 @@ namespace Luban.Job.Cfg.DataVisitors
|
||||||
public override string Accept(DBean type)
|
public override string Accept(DBean type)
|
||||||
{
|
{
|
||||||
var x = new StringBuilder();
|
var x = new StringBuilder();
|
||||||
var bean = type.ImplType;
|
if (type.Type.IsAbstractType)
|
||||||
if (bean.IsAbstractType)
|
|
||||||
{
|
{
|
||||||
x.Append($"{{ _name='{type.ImplType.Name}',");
|
x.Append($"{{ _name='{type.ImplType.Name}',");
|
||||||
}
|
}
|
||||||
|
|
@ -33,15 +32,12 @@ namespace Luban.Job.Cfg.DataVisitors
|
||||||
foreach (var f in type.Fields)
|
foreach (var f in type.Fields)
|
||||||
{
|
{
|
||||||
var defField = type.ImplType.HierarchyExportFields[index++];
|
var defField = type.ImplType.HierarchyExportFields[index++];
|
||||||
|
if (f == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
x.Append(defField.Name).Append('=');
|
x.Append(defField.Name).Append('=');
|
||||||
if (f != null)
|
x.Append(f.Apply(this));
|
||||||
{
|
|
||||||
x.Append(f.Apply(this));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
x.Append("nil");
|
|
||||||
}
|
|
||||||
x.Append(',');
|
x.Append(',');
|
||||||
}
|
}
|
||||||
x.Append('}');
|
x.Append('}');
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ namespace Luban.Job.Cfg.DataVisitors
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
x.Append("null");
|
x.Append("None");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
x.Append('}');
|
x.Append('}');
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,7 @@ namespace Luban.Job.Cfg.DataVisitors
|
||||||
public override string Accept(DBean type)
|
public override string Accept(DBean type)
|
||||||
{
|
{
|
||||||
var x = new StringBuilder();
|
var x = new StringBuilder();
|
||||||
var bean = type.ImplType;
|
if (type.Type.IsAbstractType)
|
||||||
if (bean.IsAbstractType)
|
|
||||||
{
|
{
|
||||||
x.Append($"{{ _name:\"{type.ImplType.Name}\",");
|
x.Append($"{{ _name:\"{type.ImplType.Name}\",");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ namespace Luban.Job.Cfg.Datas
|
||||||
public TArray Type { get; }
|
public TArray Type { get; }
|
||||||
public List<DType> Datas { get; }
|
public List<DType> Datas { get; }
|
||||||
|
|
||||||
public bool IsArray => true;
|
public override string TypeName => "array";
|
||||||
|
|
||||||
public DArray(TArray type, List<DType> datas)
|
public DArray(TArray type, List<DType> datas)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ namespace Luban.Job.Cfg.Datas
|
||||||
|
|
||||||
public List<DType> Fields { get; }
|
public List<DType> Fields { get; }
|
||||||
|
|
||||||
public bool IsBean => true;
|
public override string TypeName => "bean";
|
||||||
|
|
||||||
public DBean(DefBean defType, DefBean implType, List<DType> fields)
|
public DBean(DefBean defType, DefBean implType, List<DType> fields)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ namespace Luban.Job.Cfg.Datas
|
||||||
return x ? s_true : s_false;
|
return x ? s_true : s_false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string TypeName => "bool";
|
||||||
|
|
||||||
private DBool(bool x) : base(x)
|
private DBool(bool x) : base(x)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ namespace Luban.Job.Cfg.Datas
|
||||||
{
|
{
|
||||||
public static DByte Default { get; } = new DByte(0);
|
public static DByte Default { get; } = new DByte(0);
|
||||||
|
|
||||||
|
public override string TypeName => "byte";
|
||||||
|
|
||||||
public DByte(byte x) : base(x)
|
public DByte(byte x) : base(x)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,9 @@ namespace Luban.Job.Cfg.Datas
|
||||||
{
|
{
|
||||||
public class DBytes : DType<byte[]>
|
public class DBytes : DType<byte[]>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public override string TypeName => "bytes";
|
||||||
|
|
||||||
public DBytes(byte[] x) : base(x)
|
public DBytes(byte[] x) : base(x)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ namespace Luban.Job.Cfg.Datas
|
||||||
//public int UnixTime { get; }
|
//public int UnixTime { get; }
|
||||||
private readonly int _localTime;
|
private readonly int _localTime;
|
||||||
|
|
||||||
|
public override string TypeName => "datetime";
|
||||||
|
|
||||||
public DDateTime(DateTime time)
|
public DDateTime(DateTime time)
|
||||||
{
|
{
|
||||||
this.Time = time;
|
this.Time = time;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ namespace Luban.Job.Cfg.Datas
|
||||||
{
|
{
|
||||||
public static DDouble Default { get; } = new DDouble(0);
|
public static DDouble Default { get; } = new DDouble(0);
|
||||||
|
|
||||||
|
public override string TypeName => "double";
|
||||||
|
|
||||||
public DDouble(double x) : base(x)
|
public DDouble(double x) : base(x)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ namespace Luban.Job.Cfg.Datas
|
||||||
|
|
||||||
public TEnum Type { get; }
|
public TEnum Type { get; }
|
||||||
|
|
||||||
|
public override string TypeName => "enum";
|
||||||
|
|
||||||
public DEnum(TEnum type, string value)
|
public DEnum(TEnum type, string value)
|
||||||
{
|
{
|
||||||
Type = type;
|
Type = type;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ namespace Luban.Job.Cfg.Datas
|
||||||
{
|
{
|
||||||
public static DFint Default { get; } = new DFint(0);
|
public static DFint Default { get; } = new DFint(0);
|
||||||
|
|
||||||
|
public override string TypeName => "fint";
|
||||||
|
|
||||||
public DFint(int x) : base(x)
|
public DFint(int x) : base(x)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ namespace Luban.Job.Cfg.Datas
|
||||||
{
|
{
|
||||||
private static DFloat Default { get; } = new DFloat(0);
|
private static DFloat Default { get; } = new DFloat(0);
|
||||||
|
|
||||||
|
public override string TypeName => "float";
|
||||||
|
|
||||||
public static DFloat ValueOf(float x)
|
public static DFloat ValueOf(float x)
|
||||||
{
|
{
|
||||||
if (x == 0)
|
if (x == 0)
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ namespace Luban.Job.Cfg.Datas
|
||||||
{
|
{
|
||||||
public static DFlong Default { get; } = new DFlong(0);
|
public static DFlong Default { get; } = new DFlong(0);
|
||||||
|
|
||||||
|
public override string TypeName => "flong";
|
||||||
|
|
||||||
public DFlong(long x) : base(x)
|
public DFlong(long x) : base(x)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ namespace Luban.Job.Cfg.Datas
|
||||||
{
|
{
|
||||||
public static DFshort Default { get; } = new DFshort(0);
|
public static DFshort Default { get; } = new DFshort(0);
|
||||||
|
|
||||||
|
public override string TypeName => "fshort";
|
||||||
|
|
||||||
public DFshort(short x) : base(x)
|
public DFshort(short x) : base(x)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ namespace Luban.Job.Cfg.Datas
|
||||||
return new DInt(x);
|
return new DInt(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string TypeName => "int";
|
||||||
|
|
||||||
private DInt(int x) : base(x)
|
private DInt(int x) : base(x)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ namespace Luban.Job.Cfg.Datas
|
||||||
public TList Type { get; }
|
public TList Type { get; }
|
||||||
public List<DType> Datas { get; }
|
public List<DType> Datas { get; }
|
||||||
|
|
||||||
public bool IsList => true;
|
public override string TypeName => "list";
|
||||||
|
|
||||||
public DList(TList type, List<DType> datas)
|
public DList(TList type, List<DType> datas)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ namespace Luban.Job.Cfg.Datas
|
||||||
return new DLong(x);
|
return new DLong(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string TypeName => "long";
|
||||||
|
|
||||||
private DLong(long x) : base(x)
|
private DLong(long x) : base(x)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ namespace Luban.Job.Cfg.Datas
|
||||||
public TMap Type { get; }
|
public TMap Type { get; }
|
||||||
public Dictionary<DType, DType> Datas { get; }
|
public Dictionary<DType, DType> Datas { get; }
|
||||||
|
|
||||||
public bool IsMap => true;
|
public override string TypeName => "map";
|
||||||
|
|
||||||
public DMap(TMap type, Dictionary<DType, DType> datas)
|
public DMap(TMap type, Dictionary<DType, DType> datas)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ namespace Luban.Job.Cfg.Datas
|
||||||
public TSet Type { get; }
|
public TSet Type { get; }
|
||||||
public List<DType> Datas { get; }
|
public List<DType> Datas { get; }
|
||||||
|
|
||||||
public bool IsSet => true;
|
public override string TypeName => "set";
|
||||||
|
|
||||||
public DSet(TSet type, List<DType> datas)
|
public DSet(TSet type, List<DType> datas)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ namespace Luban.Job.Cfg.Datas
|
||||||
{
|
{
|
||||||
public static DShort Default { get; } = new DShort(0);
|
public static DShort Default { get; } = new DShort(0);
|
||||||
|
|
||||||
|
public override string TypeName => "short";
|
||||||
|
|
||||||
public DShort(short x) : base(x)
|
public DShort(short x) : base(x)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ namespace Luban.Job.Cfg.Datas
|
||||||
return new DString(s);
|
return new DString(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string TypeName => "string";
|
||||||
|
|
||||||
private DString(string x) : base(x)
|
private DString(string x) : base(x)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ namespace Luban.Job.Cfg.Datas
|
||||||
|
|
||||||
public string RawValue => _rawValue;
|
public string RawValue => _rawValue;
|
||||||
|
|
||||||
|
public override string TypeName => "text";
|
||||||
|
|
||||||
public DText(string key, string x)
|
public DText(string key, string x)
|
||||||
{
|
{
|
||||||
Key = key;
|
Key = key;
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ namespace Luban.Job.Cfg.Datas
|
||||||
|
|
||||||
public abstract TR Apply<T, TR>(IDataFuncVisitor<T, TR> visitor, T x);
|
public abstract TR Apply<T, TR>(IDataFuncVisitor<T, TR> visitor, T x);
|
||||||
|
|
||||||
|
public abstract string TypeName { get; }
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return this.Apply(ToStringVisitor.Ins);
|
return this.Apply(ToStringVisitor.Ins);
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ namespace Luban.Job.Cfg.Datas
|
||||||
{
|
{
|
||||||
public static DVector2 Default { get; } = new DVector2(default);
|
public static DVector2 Default { get; } = new DVector2(default);
|
||||||
|
|
||||||
|
public override string TypeName => "vector2";
|
||||||
|
|
||||||
public DVector2(Vector2 x) : base(x)
|
public DVector2(Vector2 x) : base(x)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ namespace Luban.Job.Cfg.Datas
|
||||||
{
|
{
|
||||||
public static DVector3 Default { get; } = new DVector3(default);
|
public static DVector3 Default { get; } = new DVector3(default);
|
||||||
|
|
||||||
|
public override string TypeName => "vector3";
|
||||||
|
|
||||||
public DVector3(Vector3 x) : base(x)
|
public DVector3(Vector3 x) : base(x)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ namespace Luban.Job.Cfg.Datas
|
||||||
{
|
{
|
||||||
public static DVector4 Default { get; } = new DVector4(default);
|
public static DVector4 Default { get; } = new DVector4(default);
|
||||||
|
|
||||||
|
public override string TypeName => "vector4";
|
||||||
|
|
||||||
public DVector4(Vector4 x) : base(x)
|
public DVector4(Vector4 x) : base(x)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,8 @@ namespace Luban.Job.Cfg.Defs
|
||||||
{
|
{
|
||||||
private static readonly NLog.Logger s_logger = NLog.LogManager.GetCurrentClassLogger();
|
private static readonly NLog.Logger s_logger = NLog.LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
public new static DefAssembly LocalAssebmly { get => (DefAssembly)DefAssemblyBase.LocalAssebmly; set => DefAssemblyBase.LocalAssebmly = value; }
|
||||||
|
|
||||||
public Service CfgTargetService { get; private set; }
|
public Service CfgTargetService { get; private set; }
|
||||||
|
|
||||||
private readonly string _branchName;
|
private readonly string _branchName;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using Luban.Job.Cfg.Datas;
|
using Luban.Job.Cfg.Datas;
|
||||||
using Luban.Job.Cfg.DataVisitors;
|
using Luban.Job.Cfg.DataVisitors;
|
||||||
|
using Luban.Job.Cfg.Defs;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
@ -10,6 +11,17 @@ namespace Luban.Job.Cfg.Utils
|
||||||
{
|
{
|
||||||
class DTypeTemplateExtends : TTypeTemplateExtends
|
class DTypeTemplateExtends : TTypeTemplateExtends
|
||||||
{
|
{
|
||||||
|
public static bool IsSimpleLiteralData(DType type)
|
||||||
|
{
|
||||||
|
return type.Apply(IsSimpleLiteralDataVisitor.Ins);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string ToLocalizedText(DText type)
|
||||||
|
{
|
||||||
|
var ass = DefAssembly.LocalAssebmly as DefAssembly;
|
||||||
|
return type.GetText(ass.ExportTextTable, ass.NotConvertTextSet);
|
||||||
|
}
|
||||||
|
|
||||||
public static DType GetField(DBean bean, string fieldName)
|
public static DType GetField(DBean bean, string fieldName)
|
||||||
{
|
{
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
@ -31,12 +43,12 @@ namespace Luban.Job.Cfg.Utils
|
||||||
|
|
||||||
public static string ToJsonLiteral(DType type)
|
public static string ToJsonLiteral(DType type)
|
||||||
{
|
{
|
||||||
return type.Apply(ToJsonLiteralVisitor.Ins);
|
return type != null ? type.Apply(ToJsonLiteralVisitor.Ins) : "null";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string ToLuaLiteral(DType type)
|
public static string ToLuaLiteral(DType type)
|
||||||
{
|
{
|
||||||
return type.Apply(ToLuaLiteralVisitor.Ins);
|
return type != null ? type.Apply(ToLuaLiteralVisitor.Ins) : "nil";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string ToXmlLiteral(DType type)
|
public static string ToXmlLiteral(DType type)
|
||||||
|
|
@ -46,7 +58,7 @@ namespace Luban.Job.Cfg.Utils
|
||||||
|
|
||||||
public static string ToPythonLiteral(DType type)
|
public static string ToPythonLiteral(DType type)
|
||||||
{
|
{
|
||||||
return type.Apply(ToPythonLiteralVisitor.Ins);
|
return type != null ? type.Apply(ToPythonLiteralVisitor.Ins) : "None";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string ToErlangLiteral(DType type)
|
public static string ToErlangLiteral(DType type)
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ namespace Luban.Job.Cfg.Utils
|
||||||
case "data_bin":
|
case "data_bin":
|
||||||
{
|
{
|
||||||
var buf = ThreadLocalTemporalByteBufPool.Alloc(1024 * 1024);
|
var buf = ThreadLocalTemporalByteBufPool.Alloc(1024 * 1024);
|
||||||
BinaryExportor.Ins.WriteList(records, table.Assembly, buf);
|
BinaryExportor.Ins.WriteList(table, records, buf);
|
||||||
var bytes = buf.CopyData();
|
var bytes = buf.CopyData();
|
||||||
ThreadLocalTemporalByteBufPool.Free(buf);
|
ThreadLocalTemporalByteBufPool.Free(buf);
|
||||||
return bytes;
|
return bytes;
|
||||||
|
|
@ -52,30 +52,30 @@ namespace Luban.Job.Cfg.Utils
|
||||||
});
|
});
|
||||||
if (dataType == "data_json")
|
if (dataType == "data_json")
|
||||||
{
|
{
|
||||||
JsonExportor.Ins.WriteAsArray(records, table.Assembly, jsonWriter);
|
JsonExportor.Ins.WriteAsArray(records, jsonWriter);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
Json2Exportor.Ins.WriteAsObject(table, records, table.Assembly, jsonWriter);
|
Json2Exportor.Ins.WriteAsObject(table, records, jsonWriter);
|
||||||
}
|
}
|
||||||
jsonWriter.Flush();
|
jsonWriter.Flush();
|
||||||
return System.Text.Encoding.UTF8.GetString(DataUtil.StreamToBytes(ss));
|
return System.Text.Encoding.UTF8.GetString(DataUtil.StreamToBytes(ss));
|
||||||
}
|
}
|
||||||
case "data_lua":
|
case "data_lua":
|
||||||
{
|
{
|
||||||
var content = new List<string>();
|
var content = new StringBuilder();
|
||||||
|
|
||||||
switch (table.Mode)
|
switch (table.Mode)
|
||||||
{
|
{
|
||||||
case ETableMode.ONE:
|
case ETableMode.ONE:
|
||||||
{
|
{
|
||||||
LuaExportor.Ins.ExportTableOne(table, records, content);
|
LuaExportor.Ins.ExportTableSingleton(table, records[0], content);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ETableMode.MAP:
|
case ETableMode.MAP:
|
||||||
{
|
{
|
||||||
LuaExportor.Ins.ExportTableOneKeyMap(table, records, content);
|
LuaExportor.Ins.ExportTableMap(table, records, content);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
@ -85,6 +85,28 @@ namespace Luban.Job.Cfg.Utils
|
||||||
}
|
}
|
||||||
return string.Join('\n', content);
|
return string.Join('\n', content);
|
||||||
}
|
}
|
||||||
|
case "data_erlang":
|
||||||
|
{
|
||||||
|
var content = new StringBuilder();
|
||||||
|
switch (table.Mode)
|
||||||
|
{
|
||||||
|
case ETableMode.ONE:
|
||||||
|
{
|
||||||
|
ErlangExport.Ins.ExportTableSingleton(table, records[0], content);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ETableMode.MAP:
|
||||||
|
{
|
||||||
|
ErlangExport.Ins.ExportTableMap(table, records, content);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return content.ToString();
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
throw new ArgumentException($"not support datatype:{dataType}");
|
throw new ArgumentException($"not support datatype:{dataType}");
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ namespace Luban.Job.Common.Utils
|
||||||
|
|
||||||
public static string GetOutputFileName(string genType, string fileName)
|
public static string GetOutputFileName(string genType, string fileName)
|
||||||
{
|
{
|
||||||
return $"{(genType.Contains("lua") ? fileName.Replace('.', '_') : fileName)}.{GetOutputFileSuffix(genType)}";
|
return $"{fileName.Replace('.', '_')}.{GetOutputFileSuffix(genType)}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue