Start TEngine3.0

Start TEngine3.0
This commit is contained in:
ALEXTANG
2023-03-31 17:27:49 +08:00
parent 179765c43c
commit 36353294d6
1032 changed files with 21868 additions and 102407 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,36 @@
<module name="Battle">
<enum name="ActorAttrDataType">
<var name="None" alias="无效数据" value="0"/>
<var name="MaxHp" alias="最大血量" value="1"/>
<var name="Attack" alias="攻击力" value="2"/>
<var name="PhyDamage" alias="物理伤害" value="3"/>
<var name="PhyDef" alias="物理防御" value="4"/>
<var name="MagicDamage" alias="法术伤害" value="5"/>
<var name="MagicDef" alias="法术防御" value="6"/>
<var name="MoveSpeed" alias="移动速度" value="7"/>
<var name="AttackSpeed" alias="攻击速度" value="8"/>
<var name="Hit" alias="命中率" value="9"/>
<var name="Dodge" alias="闪避率" value="10"/>
<var name="CriticalAtkRatio" alias="暴击率" value="11"/>
<var name="SanValue" alias="San值(疯狂值)" value="12"/>
<var name="MaxMp" alias="最大MP" value="13"/>
<var name="PhyDamageRatio" alias="物理伤害倍率" value="14"/>
<var name="MagicDamageRatio" alias="魔法伤害倍率" value="15"/>
<var name="CriticalRatio" alias="暴击倍率" value="16"/>
<var name="CriticalReduce" alias="暴击减免" value="17"/>
</enum>
<enum name="ActorAttrAddType">
<var name="NONE" alias="无效数据" value="0"/>
<var name="ABSOLUTE_VAL" alias="加法计算" value="1"/>
<var name="SUM_PERCENT_VAL" alias="多个项结果累加,然后对加法做乘法" value="2"/>
<var name="MUL_PERCENT_VAL" alias="每一项都是对最终结果做乘法" value="3"/>
</enum>
<bean name="ResAttrImpactData" sep="," parent="">
<var name="DataType" type="ActorAttrDataType"/>
<var name="AddType" type="ActorAttrAddType"/>
<var name="Value" type="float"/>
</bean>
</module>

View File

@@ -0,0 +1,68 @@
<module name="Battle">
<enum name="BuffTimeType">
<var name="BUFF_TIME_DURING" alias="指定持续时间" value="0"/>
<var name="BUFF_TIME_INFINIT" alias="无尽时间" value="1"/>
</enum>
<enum name="BuffReplaceType">
<var name="BUFF_REPLACE_INSTEAD" alias="更新时间范围" value="0"/>
<var name="BUFF_REPLACE_FORBIT" alias="不允许叠加" value="1"/>
<var name="BUFF_REPLACE_ADD_TIME" alias="累加时间范围" value="2"/>
<var name="BUFF_REPLACE_ADD_ATTR" alias="叠加数值" value="3"/>
<var name="BUFF_REPLACE_TYPE_COUNT" alias="叠加种类" value="4"/>
</enum>
<enum name="BuffStateID">
<var name="BUFF_STATE_NONE" alias="无状态" value="0"/>
<var name="BUFF_STATE_STUN" alias="眩晕状态" value="1"/>
<var name="BUFF_STATE_UNDEAD" alias="无敌状态" value="2"/>
<var name="BUFF_STATE_INVISIBLE" alias="隐身状态" value="3"/>
<var name="BUFF_STATE_BIGGER" alias="体形变大" value="4"/>
<var name="BUFF_STATE_NO_MOVE" alias="定身,不能移动" value="5"/>
<var name="BUFF_STATE_NO_SKILL" alias="沉默,不能放技能" value="6"/>
<var name="BUFF_STATE_SLEEP" alias="昏睡" value="7"/>
<var name="BUFF_STATE_FORCE_COLLIDER" alias="强制开启阻挡" value="8"/>
<var name="BUFF_STATE_IGNORE_COLLIDER" alias="无视阻挡" value="9"/>
<var name="BUFF_STATE_MAX" alias="最大状态" value="10"/>
</enum>
<enum name="BuffResultType">
<var name="BUFF_RESULT_NONE" alias="无" value="0"/>
<var name="BUFF_RESULT_PHY_ATK_UP" alias="物理攻击提升" value="1"/>
<var name="BUFF_RESULT_PHY_ATK_DOWN" alias="物理攻击降低" value="2"/>
<var name="BUFF_RESULT_PHY_DEF_UP" alias="物理防御提升" value="3"/>
<var name="BUFF_RESULT_PHY_DEF_DOWN" alias="物理防御降低" value="4"/>
<var name="BUFF_RESULT_PHY_HIT_UP" alias="物理命中提升" value="5"/>
<var name="BUFF_RESULT_PHY_HIT_DOWN" alias="物理命中降低" value="6"/>
<var name="BUFF_RESULT_PHY_LOSE_HP" alias="物理持续掉血" value="7"/>
<var name="BUFF_RESULT_MAG_ATK_UP" alias="法术攻击提升" value="8"/>
<var name="BUFF_RESULT_MAG_ATK_DOWN" alias="法术攻击降低" value="9"/>
<var name="BUFF_RESULT_MAG_DEF_UP" alias="法术防御提升" value="10"/>
<var name="BUFF_RESULT_MAG_DEF_DOWN" alias="法术防御降低" value="11"/>
<var name="BUFF_RESULT_MAG_HIT_UP" alias="法术命中提升" value="12"/>
<var name="BUFF_RESULT_MAG_HIT_DOWN" alias="法术命中降低" value="13"/>
<var name="BUFF_RESULT_MAG_LOSE_HP" alias="法术持续掉血" value="14"/>
<var name="BUFF_RESULT_CIRT_UP" alias="暴击率提升" value="15"/>
<var name="BUFF_RESULT_CIRT_DOWN" alias="暴击率降低" value="16"/>
<var name="BUFF_RESULT_CIRT_VALUE_UP" alias="暴击倍率提升" value="17"/>
<var name="BUFF_RESULT_CIRT_VALUE_DOWN" alias="暴击倍率降低" value="18"/>
<var name="BUFF_RESULT_MOVE_SPEED_UP" alias="移速提升" value="19"/>
<var name="BUFF_RESULT_MOVE_SPEED_DOWN" alias="移速降低" value="20"/>
</enum>
<bean name="BuffTriggleState" sep="," parent="">
<var name="StateID" type="BuffStateID"/>
<var name="StateParam" type="float"/>
</bean>
<bean name="BuffDotTickConfig" sep="," parent="">
<!-- 触发间隔,如果为0, 则只加一次 -->
<var name="TickTime" type="float"/>
<!-- 1增加buff的时候立刻触发,否则等待TickTime后再触发 -->
<var name="TickWhenAdd" type="int"/>
</bean>
</module>

View File

@@ -0,0 +1,25 @@
<module name="Battle">
<enum name="SkillMagicType"> 技能元素类型
<var name="SKILL_TYPE_NONE" alias="无类型" value="0"/>
<var name="SKILL_TYPE_DMG_PHY" alias="物理伤害属性" value="1"/>
<var name="SKILL_TYPE_DMG_MAGIC" alias="魔法伤害属性" value="2"/>
</enum>
<enum name="SkillAttrDamageType"> 伤害类型
<var name="ATTR_TYPE_NONE" alias="无数值" value="0"/>
<var name="ATTR_TYPE_DMG_WEAPON" alias="按释放者的伤害类型*X%+固定值计算,目标有防御计算" value="1"/>
<var name="ATTR_TYPE_DMG_NO_DEFEND" alias="按释放者的伤害类型*X%+固定值计算(无视目标的防御)" value="2"/>
<var name="ATTR_TYPE_DMG_TARGET_HP_NO_DEFEND" alias="按受击者的气血上限*X%+固定值计算(无视目标的防御)" value="3"/>
<var name="ATTR_TYPE_HP_AS_ATK" alias="按释放者的攻击类型*X%+固定值计算,恢复当前生命" value="4"/>
<var name="ATTR_TYPE_HP_RATIO" alias="按受击者的HP上限*X%+固定值计算,恢复当前生命" value="5"/>
</enum>
<bean name="SkillAttrDamageData" sep="," parent="">
<var name="MagicType" type="SkillMagicType"/>
<var name="AttrType" type="SkillAttrDamageType"/>
<var name="Param1" type="float"/>
<var name="Param2" type="float"/>
<var name="Param3" type="float"/>
<var name="MaxLimit" type="float"/>
</bean>
</module>

View File

@@ -0,0 +1,23 @@
<root>
<topmodule name="GameConfig"/>
<externalselector name="unity"/>
<patch name="cn"/>
<patch name="en"/>
<group name="c" default="1"/> client
<group name="s" default="1"/> server
<group name="e" default="1"/> editor
<import name="."/>
<importexcel name="__tables__.xlsx" type="table"/> 相对data目录
<importexcel name="__enums__.xlsx" type="enum"/>相对data目录
<importexcel name="__beans__.xlsx" type="bean"/>相对data目录
<service name="server" manager="Tables" group="s"/>
<service name="client" manager="Tables" group="c"/>
<service name="all" manager="Tables" group="c,s,e"/>
</root>

10
Luban/Config/gen.bat Normal file
View File

@@ -0,0 +1,10 @@
set GEN_CLIENT=dotnet ..\Tools\Luban.ClientServer\Luban.ClientServer.dll
%GEN_CLIENT% -j cfg --^
-d Defines\__root__.xml ^
--input_data_dir Datas ^
--output_data_dir output_json ^
--output_code_dir Gen ^
--gen_types code_cs_unity_json,data_json ^
-s all
pause

10
Luban/Config/gen.sh Normal file
View File

@@ -0,0 +1,10 @@
#!/bin/zsh
GEN_CLIENT=../Tools/Luban.ClientServer/Luban.ClientServer.dll
dotnet ${GEN_CLIENT} -j cfg --\
-d Defines/__root__.xml \
--input_data_dir Datas \
--output_data_dir output_json \
--output_code_dir Gen \
--gen_types code_cs_unity_json,data_json \
-s all

View File

@@ -0,0 +1,98 @@
//-----------------------------------------------------------------------
// Copyright (c) TEngine. All rights reserved.
// Author: TangXiao
// Date: 2022/5/14 16:29:13
//-----------------------------------------------------------------------
const http = require("http");
const url = require("url");
const fs = require("fs");
const path = require("path");
const mime = {
css: "text/css",
gif: "image/gif",
html: "text/html",
ico: "image/x-icon",
jpeg: "image/jpeg",
jpg: "image/jpeg",
js: "text/javascript",
json: "application/json",
pdf: "application/pdf",
png: "image/png",
svg: "image/svg+xml",
swf: "application/x-shockwave-flash",
tiff: "image/tiff",
txt: "text/plain",
wav: "audio/x-wav",
wma: "audio/x-ms-wma",
wmv: "video/x-ms-wmv",
xml: "text/xml",
};
const port = 8088;
const httpServer = http.createServer((request, response) => {
const requestUrl = request.url;
let pathName = url.parse(requestUrl).pathname;
// 对路径解码,防止中文乱码
pathName = decodeURI(pathName);
// 绝对路径
const filePath = path.resolve(__dirname + pathName);
// 扩展名
let ext = path.extname(pathName);
ext = ext ? ext.slice(1) : "unknown";
// 未知的类型一律用"text/plain"类型
const contentType = mime[ext] || "text/plain";
// fs.stat()方法用于判断给定的路径是否存在
fs.stat(filePath, (err, stats) => {
// 路径不存在则返回404
if (err) {
response.writeHead(404, { "content-type": "text/html" });
response.end("<h1>404 Not Found</h1>");
}
// 如果是文件
if (!err && stats.isFile()) {
response.writeHead(200, { "content-type": contentType });
// 建立流对象,读文件
const stream = fs.createReadStream(filePath);
// 错误处理
stream.on("error", function() {
response.writeHead(500, { "content-type": contentType });
response.end("<h1>500 Server Error</h1>");
});
// 读取文件
stream.pipe(response);
//response.end(); // 这个地方有坑,加了会关闭对话,看不到内容了
}
// 如果是路径
if (!err && stats.isDirectory()) {
let html = " <head><meta charset = 'utf-8'/></head>";
// 读取该路径下文件
fs.readdir(filePath, (err, files) => {
if (err) {
response.writeHead(500, { "content-type": contentType });
response.end("<h1>路径读取失败!</h1>");
} else {
for (const file of files) {
if (file === "index.html") {
response.writeHead(200, { "content-type": "text/html" });
response.end(file);
break;
}
html += `<div><a href='${file}'>${file}</a></div>`;
}
response.writeHead(200, { "content-type": "text/html" });
response.end(html);
}
});
}
});
});
httpServer.listen(port, function() {
console.log(`File Service: ${port}`);
});

View File

@@ -0,0 +1 @@
node FileSys.js

View File

@@ -0,0 +1 @@
node FileSys.js

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,12 @@
{
"runtimeOptions": {
"tfm": "net6.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
},
"configProperties": {
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false
}
}
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,12 @@
{
"runtimeOptions": {
"tfm": "net6.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
},
"configProperties": {
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false
}
}
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,12 @@
{
"runtimeOptions": {
"tfm": "net6.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
},
"configProperties": {
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,25 @@
{{~
name = x.name
namespace_with_top_module = x.namespace_with_top_module
comment = x.comment
items = x.items
~}}
{{x.cpp_namespace_begin}}
{{~if comment != '' ~}}
/**
* {{comment | html.escape}}
*/
{{~end~}}
enum class {{name}}
{
{{~ for item in items ~}}
{{~if item.comment != '' ~}}
/**
* {{item.escape_comment}}
*/
{{~end~}}
{{item.name}} = {{item.value}},
{{~end~}}
};
{{x.cpp_namespace_end}}

View File

@@ -0,0 +1,30 @@
{{~
name = x.name
namespace_with_top_module = x.namespace_with_top_module
comment = x.comment
items = x.items
~}}
{{cs_start_name_space_grace x.namespace_with_top_module}}
{{~if comment != '' ~}}
/// <summary>
/// {{comment | html.escape}}
/// </summary>
{{~end~}}
{{~if x.is_flags~}}
[System.Flags]
{{~end~}}
public enum {{name}}
{
{{~ for item in items ~}}
{{~if item.comment != '' ~}}
/// <summary>
/// {{item.escape_comment}}
/// </summary>
{{~end~}}
{{item.name}} = {{item.value}},
{{~end~}}
}
{{cs_end_name_space_grace x.namespace_with_top_module}}

View File

@@ -0,0 +1,15 @@
{{~
name = x.name
namespace_with_top_module = x.namespace_with_top_module
comment = x.comment
items = x.items
~}}
enum {{x.flat_buffers_full_name}}:int {
{{~if !x.has_zero_value_item~}}
__GENERATE_DEFAULT_VALUE = 0,
{{~end~}}
{{~for item in items ~}}
{{x.pb_full_name}}_{{item.name}} = {{item.int_value}},
{{~end~}}
}

View File

@@ -0,0 +1,20 @@
{{~
name = x.name
namespace_with_top_module = x.namespace_with_top_module
comment = x.comment
items = x.items
~}}
{{~if comment != '' ~}}
# {{comment | html.escape}}
{{~end~}}
enum {{x.gdscript_full_name}}{
{{~ for item in items ~}}
{{~if item.comment != '' ~}}
{{item.name}} = {{item.int_value}}, # {{item.escape_comment}}
{{~else~}}
{{item.name}} = {{item.int_value}},
{{~end~}}
{{~end~}}
}

View File

@@ -0,0 +1,14 @@
{{~
name = x.name
namespace_with_top_module = x.namespace_with_top_module
comment = x.comment
items = x.items
~}}
package {{x.top_module}}
const (
{{~for item in items ~}}
{{x.go_full_name}}_{{item.name}} = {{item.int_value}}
{{~end~}}
)

View File

@@ -0,0 +1,23 @@
{{~
name = x.name
namespace_with_top_module = x.namespace_with_top_module
comment = x.comment
items = x.items
~}}
package {{namespace_with_top_module}};
{{~if comment != '' ~}}
/**
* {{comment | html.escape}}
*/
{{~end~}}
public final class {{name}} {
{{~ for item in items ~}}
{{~if item.comment != '' ~}}
/**
* {{item.escape_comment}}
*/
{{~end~}}
public static final int {{item.name}} = {{item.int_value}};
{{~end~}}
}

View File

@@ -0,0 +1,30 @@
{{
enums = x.enums
beans = x.beans
tables = x.tables
}}
local setmetatable = setmetatable
local pairs = pairs
local ipairs = ipairs
local tinsert = table.insert
local function SimpleClass()
local class = {}
class.__index = class
class.New = function(...)
local ctor = class.ctor
local o = ctor and ctor(...) or {}
setmetatable(o, class)
return o
end
return class
end
local function get_map_size(m)
local n = 0
for _ in pairs(m) do
n = n + 1
end
return n
end

View File

@@ -0,0 +1,15 @@
{{~
name = x.name
namespace_with_top_module = x.namespace_with_top_module
comment = x.comment
items = x.items
~}}
enum {{x.pb_full_name}} {
{{~for item in items ~}}
{{x.pb_full_name}}_{{item.name}} = {{item.int_value}};
{{~end~}}
{{~if items.empty?}}
{{x.pb_full_name}}_EMPTY_PLACEHOLDER = 0;
{{~end~}}
}

View File

@@ -0,0 +1,15 @@
{{~
name = x.name
namespace_with_top_module = x.namespace_with_top_module
comment = x.comment
items = x.items
~}}
enum {{x.pb_full_name}} {
{{~if items.empty? || items[0].int_value != 0~}}
{{x.pb_full_name}}_EMPTY_PLACEHOLDER = 0;
{{~end~}}
{{~for item in items ~}}
{{x.pb_full_name}}_{{item.name}} = {{item.int_value}};
{{~end~}}
}

View File

@@ -0,0 +1,24 @@
{{~
name = x.name
namespace_with_top_module = x.namespace_with_top_module
comment = x.comment
items = x.items
~}}
{{~if comment != '' ~}}
'''
{{comment | html.escape}}
'''
{{~end~}}
class {{x.py_full_name}}(Enum):
{{~ for item in items ~}}
{{~if item.comment != '' ~}}
'''
{{item.escape_comment}}
'''
{{~end~}}
{{item.name}} = {{item.value}}
{{~end~}}
{{~if (items == empty)~}}
pass
{{~end~}}

View File

@@ -0,0 +1,25 @@
{{~
name = x.name
namespace_with_top_module = x.namespace_with_top_module
comment = x.comment
items = x.items
~}}
{{~if comment != '' ~}}
/**
* {{comment | html.escape}}
*/
{{~end~}}
#[allow(dead_code)]
#[allow(non_camel_case_types)]
pub enum {{x.rust_full_name}} {
{{~for item in items ~}}
{{~if item.comment != '' ~}}
/**
* {{item.escape_comment}}
*/
{{~end~}}
{{item.name}} = {{item.int_value}},
{{~end~}}
}

View File

@@ -0,0 +1,24 @@
{{~
name = x.name
namespace_with_top_module = x.namespace_with_top_module
comment = x.comment
items = x.items
~}}
{{x.typescript_namespace_begin}}
{{~if comment != '' ~}}
/**
* {{comment | html.escape}}
*/
{{~end~}}
export enum {{name}} {
{{~for item in items ~}}
{{~if item.comment != '' ~}}
/**
* {{item.escape_comment}}
*/
{{~end~}}
{{item.name}} = {{item.value}},
{{~end~}}
}
{{x.typescript_namespace_end}}

View File

@@ -0,0 +1,30 @@
#pragma once
#include <functional>
#include "bright/serialization/ByteBuf.h"
#include "bright/CfgBean.hpp"
using ByteBuf = ::bright::serialization::ByteBuf;
namespace {{assembly.top_module}}
{
{{~for e in x.enum_codes~}}
{{e}}
{{~end~}}
{{~for b in x.beans~}}
{{b.cpp_namespace_begin}} class {{b.name}}; {{b.cpp_namespace_end}}
{{~end~}}
{{~for b in x.bean_codes~}}
{{b}}
{{~end~}}
{{~for t in x.table_codes~}}
{{t}}
{{~end~}}
{{x.tables_code}}
}

View File

@@ -0,0 +1,66 @@
{{x.cpp_namespace_begin}}
{{
name = x.name
parent_def_type = x.parent_def_type
export_fields = x.export_fields
hierarchy_export_fields = x.hierarchy_export_fields
}}
{{~if x.comment != '' ~}}
/**
* {{x.escape_comment}}
*/
{{~end~}}
class {{name}} : public {{if parent_def_type}} {{parent_def_type.cpp_full_name}} {{else}} bright::CfgBean {{end}}
{
public:
static bool deserialize{{name}}(ByteBuf& _buf, ::bright::SharedPtr<{{name}}>& _out);
{{name}}()
{
}
{{~if !hierarchy_export_fields.empty?~}}
{{name}}({{- for field in hierarchy_export_fields }}{{cpp_define_type field.ctype}} {{field.name}}{{if !for.last}},{{end}} {{end}})
{{~if parent_def_type~}}
: {{parent_def_type.cpp_full_name}}({{ for field in parent_def_type.hierarchy_export_fields }}{{field.name}}{{if !for.last}}, {{end}}{{end}})
{{~end~}}
{
{{~ for field in export_fields ~}}
this->{{field.convention_name}} = {{field.name}};
{{~end~}}
}
{{~end~}}
virtual ~{{name}}() {}
bool deserialize(ByteBuf& _buf);
{{~ for field in export_fields ~}}
{{~if field.comment != '' ~}}
/**
* {{field.escape_comment}}
*/
{{~end~}}
{{cpp_define_type field.ctype}} {{field.convention_name}};
{{~if field.index_field~}}
::bright::HashMap<{{cpp_define_type field.index_field.ctype}}, {{cpp_define_type field.ctype.element_type}}> {{field.convention_name}}_Index;
{{~end~}}
{{~if field.gen_ref~}}
{{field.cpp_ref_validator_define}}
{{~end~}}
{{~end~}}
{{~if !x.is_abstract_type~}}
static constexpr int __ID__ = {{x.id}};
int getTypeId() const { return __ID__; }
{{~end~}}
virtual void resolve(::bright::HashMap<::bright::String, void*>& _tables);
};
{{x.cpp_namespace_end}}

View File

@@ -0,0 +1,72 @@
#include <algorithm>
#include "gen_types.h"
using ByteBuf = bright::serialization::ByteBuf;
namespace {{assembly.top_module}}
{
{{~for type in x.types~}}
bool {{type.cpp_full_name}}::deserialize(ByteBuf& _buf)
{
{{~if type.parent_def_type~}}
if (!{{type.parent_def_type.cpp_full_name}}::deserialize(_buf))
{
return false;
}
{{~end~}}
{{~ for field in type.export_fields ~}}
{{cpp_deserialize '_buf' field.convention_name field.ctype}}
{{~if field.index_field ~}}
for(auto& _v : this->{{field.convention_name}})
{
{{field.convention_name}}_Index.insert({_v->{{field.index_field.convention_name}}, _v});
}
{{~end~}}
{{~end~}}
return true;
}
bool {{type.cpp_full_name}}::deserialize{{type.name}}(ByteBuf& _buf, ::bright::SharedPtr<{{type.cpp_full_name}}>& _out)
{
{{~if type.is_abstract_type~}}
int id;
if (!_buf.readInt(id)) return false;
switch (id)
{
{{~for child in type.hierarchy_not_abstract_children~}}
case {{child.cpp_full_name}}::__ID__: { _out.reset(new {{child.cpp_full_name}}()); if (_out->deserialize(_buf)) { return true; } else { _out.reset(); return false;} }
{{~end~}}
default: { _out = nullptr; return false;}
}
{{~else~}}
_out.reset(new {{type.cpp_full_name}}());
if (_out->deserialize(_buf))
{
return true;
}
else
{
_out.reset();
return false;
}
{{~end~}}
}
void {{type.cpp_full_name}}::resolve(::bright::HashMap<::bright::String, void*>& _tables)
{
{{~if type.parent_def_type~}}
{{type.parent_def_type.name}}::resolve(_tables);
{{~end~}}
{{~ for field in type.export_fields ~}}
{{~if field.gen_ref~}}
{{cpp_ref_validator_resolve field}}
{{~else if field.has_recursive_ref~}}
{{cpp_recursive_resolve field '_tables'}}
{{~end~}}
{{~end~}}
}
{{~end~}}
}

View File

@@ -0,0 +1,215 @@
{{x.cpp_namespace_begin}}
{{~
name = x.name
key_type = x.key_ttype
key_type1 = x.key_ttype1
key_type2 = x.key_ttype2
value_type = x.value_ttype
~}}
{{~if x.comment != '' ~}}
/**
* {{x.escape_comment}}
*/
{{~end~}}
{{~if x.is_list_table ~}}
{{~if x.is_union_index~}}
typedef struct t_{{name}}_MultiKey
{
{{~for idx in x.index_list~}}
{{cpp_define_type idx.type}} {{idx.index_field.name}};
{{~end~}}
bool operator==(const t_{{name}}_MultiKey& stOther) const
{
bool bEqual = true;
{{~for idx in x.index_list~}}
bEqual = bEqual && (stOther.{{idx.index_field.name}} == {{idx.index_field.name}});
{{~end~}}
return bEqual;
}
}t_{{name}}_MultiKey;
typedef struct t_{{name}}_MultiKey_HashFunc
{
std::size_t operator()(const t_{{name}}_MultiKey& stMK) const
{
std::size_t sHash = 0;
{{~for idx in x.index_list~}}
sHash ^= std::hash<{{cpp_define_type idx.type}}>()(stMK.{{idx.index_field.name}});
{{~end~}}
return sHash;
}
}t_{{name}}_MultiKey_HashFunc;
{{~end~}}
{{~end~}}
class {{name}}
{
{{~if x.is_map_table ~}}
private:
::bright::HashMap<{{cpp_define_type key_type}}, {{cpp_define_type value_type}}> _dataMap;
::bright::Vector<{{cpp_define_type value_type}}> _dataList;
public:
bool load(ByteBuf& _buf)
{
int n;
if (!_buf.readSize(n)) return false;
for(; n > 0 ; --n)
{
{{cpp_define_type value_type}} _v;
{{cpp_deserialize '_buf' '_v' value_type}}
_dataList.push_back(_v);
_dataMap[_v->{{x.index_field.convention_name}}] = _v;
}
return true;
}
const ::bright::HashMap<{{cpp_define_type key_type}}, {{cpp_define_type value_type}}>& getDataMap() const { return _dataMap; }
const ::bright::Vector<{{cpp_define_type value_type}}>& getDataList() const { return _dataList; }
{{value_type.bean.cpp_full_name}}* getRaw({{cpp_define_type key_type}} key)
{
auto it = _dataMap.find(key);
return it != _dataMap.end() ? it->second.get() : nullptr;
}
{{cpp_define_type value_type}} get({{cpp_define_type key_type}} key)
{
auto it = _dataMap.find(key);
return it != _dataMap.end() ? it->second : nullptr;
}
void resolve(::bright::HashMap<::bright::String, void*>& _tables)
{
for(auto v : _dataList)
{
v->resolve(_tables);
}
}
{{~else if x.is_list_table~}}
private:
::bright::Vector<{{cpp_define_type value_type}}> _dataList;
{{~if x.is_union_index~}}
::bright::HashMapMultiKey<t_{{name}}_MultiKey, {{cpp_define_type value_type}}, t_{{name}}_MultiKey_HashFunc> _dataMap;
{{~else if !x.index_list.empty?~}}
{{~for idx in x.index_list~}}
::bright::HashMap<{{cpp_define_type idx.type}}, {{cpp_define_type value_type}}> _dataMap_{{idx.index_field.name}};
{{~end~}}
{{~else~}}
{{~end~}}
public:
bool load(ByteBuf& _buf)
{
int n;
if (!_buf.readSize(n)) return false;
for(; n > 0 ; --n)
{
{{cpp_define_type value_type}} _v;
{{cpp_deserialize '_buf' '_v' value_type}}
_dataList.push_back(_v);
{{~if x.is_union_index~}}
t_{{name}}_MultiKey stKey;
{{~for idx in x.index_list~}}
stKey.{{idx.index_field.name}} = _v->{{idx.index_field.name}};
{{~end~}}
_dataMap[stKey] = _v;
{{~else if !x.index_list.empty?~}}
{{~for idx in x.index_list~}}
_dataMap_{{idx.index_field.name}}[_v->{{idx.index_field.name}}] = _v;
{{~end~}}
{{~else~}}
{{~end~}}
}
return true;
}
const ::bright::Vector<{{cpp_define_type value_type}}>& getDataList() const { return _dataList; }
{{~if x.is_union_index~}}
::bright::HashMapMultiKey<t_{{name}}_MultiKey, {{cpp_define_type value_type}}, t_{{name}}_MultiKey_HashFunc>& getDataMap()
{
return _dataMap;
}
{{value_type.bean.cpp_full_name}}* getRaw(t_{{name}}_MultiKey& key)
{
auto it = _dataMap.find(key);
return it != _dataMap.end() ? it->second.get() : nullptr;
}
{{cpp_define_type value_type}} get(t_{{name}}_MultiKey& key)
{
auto it = _dataMap.find(key);
return it != _dataMap.end() ? it->second : nullptr;
}
{{~else if !x.index_list.empty?~}}
{{~for idx in x.index_list~}}
::bright::HashMap<{{cpp_define_type idx.type}}, {{cpp_define_type value_type}}>& getDataMapBy{{idx.index_field.name}}()
{
return _dataMap_{{idx.index_field.name}};
}
{{value_type.bean.cpp_full_name}}* getRawBy{{idx.index_field.name}}({{cpp_define_type idx.type}} key)
{
auto it = _dataMap_{{idx.index_field.name}}.find(key);
return it != _dataMap_{{idx.index_field.name}}.end() ? it->second.get() : nullptr;
}
{{cpp_define_type value_type}} getBy{{idx.index_field.name}}({{cpp_define_type idx.type}} key)
{
auto it = _dataMap_{{idx.index_field.name}}.find(key);
return it != _dataMap_{{idx.index_field.name}}.end() ? it->second : nullptr;
}
{{~end~}}
{{~else~}}
{{value_type.bean.cpp_full_name}}* getRaw(size_t index) const
{
return _dataList[index].get();
}
{{cpp_define_type value_type}} get(size_t index) const
{
return _dataList[index];
}
{{~end~}}
void resolve(::bright::HashMap<::bright::String, void*>& _tables)
{
for(auto v : _dataList)
{
v->resolve(_tables);
}
}
{{~else~}}
private:
{{cpp_define_type value_type}} _data;
public:
{{cpp_define_type value_type}} data() const { return _data; }
bool load(ByteBuf& _buf)
{
int n;
if (!_buf.readSize(n)) return false;
if (n != 1) return false;
{{cpp_deserialize '_buf' '_data' value_type}}
return true;
}
void resolve(::bright::HashMap<::bright::String, void*>& _tables)
{
_data->resolve(_tables);
}
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
{{~if field.comment != '' ~}}
/**
* {{field.escape_comment}}
*/
{{~end~}}
{{cpp_define_type field.ctype}}& {{field.convention_getter_name}}() const { return _data->{{field.convention_name}}; }
{{~end~}}
{{~end~}}
};
{{x.cpp_namespace_end}}

View File

@@ -0,0 +1,33 @@
{{~
tables = x.tables
name = x.name
~}}
class {{name}}
{
public:
{{~for table in tables ~}}
{{~if table.comment != '' ~}}
/**
* {{table.escape_comment}}
*/
{{~end~}}
{{table.cpp_full_name}} {{table.name}};
{{~end~}}
bool load(::bright::Loader<ByteBuf> loader)
{
::bright::HashMap<::bright::String, void*> __tables__;
ByteBuf buf;
{{~for table in tables~}}
if (!loader(buf, "{{table.output_data_file}}")) return false;
if (!{{table.name}}.load(buf)) return false;
__tables__["{{table.full_name}}"] = &{{table.name}};
{{~end~}}
{{~for table in tables ~}}
{{table.name}}.resolve(__tables__);
{{~end~}}
return true;
}
};

View File

@@ -0,0 +1,22 @@
#pragma once
#include ""CoreMinimal.h""
#include ""UCfgObj.h""
{{ue_bp_includes}}
#include ""{{ue_bp_header_file_name_without_suffix}}.generated.h""
UCLASS(BlueprintType)
class X6PROTO_API {{ue_bp_full_name}} : public {{if parent_def_type}} {{parent_def_type.ue_bp_full_name}} {{else}} UCfgObj {{end}}
{
GENERATED_BODY()
public:
{{~for field in export_fields ~}}
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (DisplayName = ""{{field.name}}""))
{{field.ctype.ue_bp_cpp_define_type}} {{field.name}};
{{~end~}}
};

View File

@@ -0,0 +1,19 @@
#pragma once
#include ""CoreMinimal.h""
#include ""{{ue_bp_header_file_name_without_suffix}}.generated.h""
UENUM(BlueprintType)
enum class {{ue_bp_full_name}} : uint8
{
{{~if !contains_value_equal0_item~}}
__DEFAULT__ = 0,
{{~end~}}
{{~if contains_any_ue_enum_compatible_item~}}
{{~for item in items ~}}
{{if item.int_value >= 256}}//{{end}}{{item.name}} = {{item.value}} UMETA(DisplayName = ""{{item.alias_or_name}}""),
{{~end~}}
{{~else~}}
DUMMY UMETA(DisplayName = ""DUMMY""),
{{~end~}}
};

View File

@@ -0,0 +1,27 @@
#pragma once
#include ""CoreMinimal.h""
#include ""FCfgObj.h""
{{editor_cpp_includes}}
namespace editor
{
{{cpp_namespace_begin}}
struct X6PROTOEDITOR_API {{ue_fname}} : public {{if parent_def_type}} {{parent_def_type.ue_fname}}{{else}}FCfgObj{{end}}
{
{{~for field in fields ~}}
{{field.ctype.editor_ue_cpp_define_type}} {{field.name}};
{{~end~}}
{{~if !is_abstract_type~}}
bool Load(FJsonObject* _json) override;
bool Save(FJsonObject*& result) override;
{{~end~}}
static bool Create(FJsonObject* _json, {{ue_fname}}*& result);
};
{{cpp_namespace_end}}

View File

@@ -0,0 +1,21 @@
#pragma once
#include ""CoreMinimal.h""
namespace editor
{
{{cpp_namespace_begin}}
enum class {{ue_fname}}
{
{{~for item in items ~}}
{{item.name}} = {{item.value}},
{{~end~}}
};
bool X6PROTOEDITOR_API {{ue_fname}}ToString({{ue_fname}} value, FString& s);
bool X6PROTOEDITOR_API {{ue_fname}}FromString(const FString& s, {{ue_fname}}& x);
{{cpp_namespace_end}}
}

View File

@@ -0,0 +1,97 @@
#include ""JsonUtil.h""
{{includes}}
namespace editor
{
{{~for type in types~}}
{{type.cpp_namespace_begin}}
{{~if type.is_bean~}}
{{~if type.is_abstract_type~}}
bool {{type.ue_fname}}::Create(FJsonObject* _json, {{type.ue_fname}}*& result)
{
FString type;
if (_json->TryGetStringField(FString(""{{type.json_type_name_key}}""), type))
{
{{~for child in type.hierarchy_not_abstract_children~}}
if (type == ""{{cs_impl_data_type child x}}"")
{
result = new {{child.ue_fname}}();
} else
{{~end~}}
{
result = nullptr;
return false;
}
if (!result->Load(_json))
{
delete result;
return false;
}
return true;
}
else
{
result = nullptr;
return false;
}
}
{{~else~}}
bool {{type.ue_fname}}::Create(FJsonObject* _json, {{type.ue_fname}}*& result)
{
result = new {{type.ue_fname}}();
if (!result->Load(_json))
{
delete result;
return false;
}
return true;
}
bool {{type.ue_fname}}::Save(FJsonObject*& result)
{
auto _json = new FJsonObject();
_json->SetStringField(""{{type.json_type_name_key}}"", ""{{type.name}}"");
{{~for field in type.hierarchy_fields~}}
{{field.editor_ue_cpp_save}}
{{~end~}}
result = _json;
return true;
}
bool {{type.ue_fname}}::Load(FJsonObject* _json)
{
{{~for field in type.hierarchy_fields~}}
{{field.editor_ue_cpp_load}}
{{~end~}}
return true;
}
{{~end~}}
{{~else~}}
bool {{type.ue_fname}}ToString({{type.ue_fname}} value, FString& s)
{
{{~for item in type.items ~}}
if (value == {{type.ue_fname}}::{{item.name}}) { s = ""{{item.name}}""; return true; }
{{~end~}}
return false;
}
bool {{type.ue_fname}}FromString(const FString& s, {{type.ue_fname}}& value)
{
{{~for item in type.items ~}}
if (s == ""{{item.name}}"")
{
value = {{type.ue_fname}}::{{item.name}};
return true;
}
{{~end~}}
return false;
}
{{~end~}}
{{type.cpp_namespace_end}}
{{~end~}}
}

View File

@@ -0,0 +1,115 @@
using Bright.Serialization;
using System.Collections.Generic;
{{
name = x.name
parent_def_type = x.parent_def_type
export_fields = x.export_fields
hierarchy_export_fields = x.hierarchy_export_fields
}}
{{cs_start_name_space_grace x.namespace_with_top_module}}
{{~if x.comment != '' ~}}
/// <summary>
/// {{x.escape_comment}}
/// </summary>
{{~end~}}
public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {{x.parent}} {{else}} Bright.Config.BeanBase {{end}}
{
public {{name}}(ByteBuf _buf) {{if parent_def_type}} : base(_buf) {{end}}
{
{{~ for field in export_fields ~}}
{{cs_deserialize '_buf' field.convention_name field.ctype}}
{{~if field.index_field~}}
foreach(var _v in {{field.convention_name}})
{
{{field.convention_name}}_Index.Add(_v.{{field.index_field.convention_name}}, _v);
}
{{~end~}}
{{~end~}}
PostInit();
}
public static {{name}} Deserialize{{name}}(ByteBuf _buf)
{
{{~if x.is_abstract_type~}}
switch (_buf.ReadInt())
{
{{~for child in x.hierarchy_not_abstract_children~}}
case {{child.full_name}}.__ID__: return new {{child.full_name}}(_buf);
{{~end~}}
default: throw new SerializationException();
}
{{~else~}}
return new {{x.full_name}}(_buf);
{{~end~}}
}
{{~ for field in export_fields ~}}
{{~if field.comment != '' ~}}
/// <summary>
/// {{field.escape_comment}}
/// </summary>
{{~end~}}
public {{cs_define_type field.ctype}} {{field.convention_name}} { get; private set; }
{{~if field.index_field~}}
public readonly Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}> {{field.convention_name}}_Index = new Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}>();
{{~end~}}
{{~if field.gen_ref~}}
public {{field.cs_ref_validator_define}}
{{~end~}}
{{~if (gen_datetime_mills field.ctype) ~}}
public long {{field.convention_name}}_Millis => {{field.convention_name}} * 1000L;
{{~end~}}
{{~if field.gen_text_key~}}
public {{cs_define_text_key_field field}} { get; }
{{~end~}}
{{~end~}}
{{~if !x.is_abstract_type~}}
public const int __ID__ = {{x.id}};
public override int GetTypeId() => __ID__;
{{~end~}}
public {{x.cs_method_modifier}} void Resolve(Dictionary<string, object> _tables)
{
{{~if parent_def_type~}}
base.Resolve(_tables);
{{~end~}}
{{~ for field in export_fields ~}}
{{~if field.gen_ref~}}
{{cs_ref_validator_resolve field}}
{{~else if field.has_recursive_ref~}}
{{cs_recursive_resolve field '_tables'}}
{{~end~}}
{{~end~}}
PostResolve();
}
public {{x.cs_method_modifier}} void TranslateText(System.Func<string, string, string> translator)
{
{{~if parent_def_type~}}
base.TranslateText(translator);
{{~end~}}
{{~ for field in export_fields ~}}
{{~if field.gen_text_key~}}
{{cs_translate_text field 'translator'}}
{{~else if field.has_recursive_text~}}
{{cs_recursive_translate_text field 'translator'}}
{{~end~}}
{{~end~}}
}
public override string ToString()
{
return "{{full_name}}{ "
{{~for field in hierarchy_export_fields ~}}
+ "{{field.convention_name}}:" + {{cs_to_string field.convention_name field.ctype}} + ","
{{~end~}}
+ "}";
}
partial void PostInit();
partial void PostResolve();
}
{{cs_end_name_space_grace x.namespace_with_top_module}}

View File

@@ -0,0 +1,173 @@
using Bright.Serialization;
using System.Collections.Generic;
{{cs_start_name_space_grace x.namespace_with_top_module}}
{{
name = x.name
key_type = x.key_ttype
key_type1 = x.key_ttype1
key_type2 = x.key_ttype2
value_type = x.value_ttype
}}
{{~if x.comment != '' ~}}
/// <summary>
/// {{x.escape_comment}}
/// </summary>
{{~end~}}
public partial class {{name}}
{
{{~if x.is_map_table ~}}
private readonly Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> _dataMap;
private readonly List<{{cs_define_type value_type}}> _dataList;
public {{name}}(ByteBuf _buf)
{
_dataMap = new Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}>();
_dataList = new List<{{cs_define_type value_type}}>();
for(int n = _buf.ReadSize() ; n > 0 ; --n)
{
{{cs_define_type value_type}} _v;
{{cs_deserialize '_buf' '_v' value_type}}
_dataList.Add(_v);
_dataMap.Add(_v.{{x.index_field.convention_name}}, _v);
}
PostInit();
}
public Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> DataMap => _dataMap;
public List<{{cs_define_type value_type}}> DataList => _dataList;
{{~if value_type.is_dynamic~}}
public T GetOrDefaultAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => _dataMap.TryGetValue(key, out var v) ? (T)v : null;
public T GetAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => (T)_dataMap[key];
{{~end~}}
public {{cs_define_type value_type}} GetOrDefault({{cs_define_type key_type}} key) => _dataMap.TryGetValue(key, out var v) ? v : null;
public {{cs_define_type value_type}} Get({{cs_define_type key_type}} key) => _dataMap[key];
public {{cs_define_type value_type}} this[{{cs_define_type key_type}} key] => _dataMap[key];
public void Resolve(Dictionary<string, object> _tables)
{
foreach(var v in _dataList)
{
v.Resolve(_tables);
}
PostResolve();
}
public void TranslateText(System.Func<string, string, string> translator)
{
foreach(var v in _dataList)
{
v.TranslateText(translator);
}
}
{{~else if x.is_list_table ~}}
private readonly List<{{cs_define_type value_type}}> _dataList;
{{~if x.is_union_index~}}
private {{cs_table_union_map_type_name x}} _dataMapUnion;
{{~else if !x.index_list.empty?~}}
{{~for idx in x.index_list~}}
private Dictionary<{{cs_define_type idx.type}}, {{cs_define_type value_type}}> _dataMap_{{idx.index_field.name}};
{{~end~}}
{{~end~}}
public {{name}}(ByteBuf _buf)
{
_dataList = new List<{{cs_define_type value_type}}>();
for(int n = _buf.ReadSize() ; n > 0 ; --n)
{
{{cs_define_type value_type}} _v;
{{cs_deserialize '_buf' '_v' value_type}}
_dataList.Add(_v);
}
{{~if x.is_union_index~}}
_dataMapUnion = new {{cs_table_union_map_type_name x}}();
foreach(var _v in _dataList)
{
_dataMapUnion.Add(({{cs_table_key_list x "_v"}}), _v);
}
{{~else if !x.index_list.empty?~}}
{{~for idx in x.index_list~}}
_dataMap_{{idx.index_field.name}} = new Dictionary<{{cs_define_type idx.type}}, {{cs_define_type value_type}}>();
{{~end~}}
foreach(var _v in _dataList)
{
{{~for idx in x.index_list~}}
_dataMap_{{idx.index_field.name}}.Add(_v.{{idx.index_field.convention_name}}, _v);
{{~end~}}
}
{{~end~}}
PostInit();
}
public List<{{cs_define_type value_type}}> DataList => _dataList;
{{~if x.is_union_index~}}
public {{cs_define_type value_type}} Get({{cs_table_get_param_def_list x}}) => _dataMapUnion.TryGetValue(({{cs_table_get_param_name_list x}}), out {{cs_define_type value_type}} __v) ? __v : null;
{{~else if !x.index_list.empty? ~}}
{{~for idx in x.index_list~}}
public {{cs_define_type value_type}} GetBy{{idx.index_field.convention_name}}({{cs_define_type idx.type}} key) => _dataMap_{{idx.index_field.name}}.TryGetValue(key, out {{cs_define_type value_type}} __v) ? __v : null;
{{~end~}}
{{~end~}}
public void Resolve(Dictionary<string, object> _tables)
{
foreach(var v in _dataList)
{
v.Resolve(_tables);
}
PostResolve();
}
public void TranslateText(System.Func<string, string, string> translator)
{
foreach(var v in _dataList)
{
v.TranslateText(translator);
}
}
{{~else~}}
private readonly {{cs_define_type value_type}} _data;
public {{name}}(ByteBuf _buf)
{
int n = _buf.ReadSize();
if (n != 1) throw new SerializationException("table mode=one, but size != 1");
{{cs_deserialize '_buf' '_data' value_type}}
PostInit();
}
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
{{~if field.comment != '' ~}}
/// <summary>
/// {{field.escape_comment}}
/// </summary>
{{~end~}}
public {{cs_define_type field.ctype}} {{field.convention_name}} => _data.{{field.convention_name}};
{{~end~}}
public void Resolve(Dictionary<string, object> _tables)
{
_data.Resolve(_tables);
PostResolve();
}
public void TranslateText(System.Func<string, string, string> translator)
{
_data.TranslateText(translator);
}
{{~end~}}
partial void PostInit();
partial void PostResolve();
}
{{cs_end_name_space_grace x.namespace_with_top_module}}

View File

@@ -0,0 +1,48 @@
using Bright.Serialization;
{{
name = x.name
namespace = x.namespace
tables = x.tables
}}
{{cs_start_name_space_grace x.namespace}}
public partial class {{name}}
{
{{~for table in tables ~}}
{{~if table.comment != '' ~}}
/// <summary>
/// {{table.escape_comment}}
/// </summary>
{{~end~}}
public {{table.full_name}} {{table.name}} {get; }
{{~end~}}
public {{name}}(System.Func<string, ByteBuf> loader)
{
var tables = new System.Collections.Generic.Dictionary<string, object>();
{{~for table in tables ~}}
{{table.name}} = new {{table.full_name}}(loader("{{table.output_data_file}}"));
tables.Add("{{table.full_name}}", {{table.name}});
{{~end~}}
PostInit();
{{~for table in tables ~}}
{{table.name}}.Resolve(tables);
{{~end~}}
PostResolve();
}
public void TranslateText(System.Func<string, string, string> translator)
{
{{~for table in tables ~}}
{{table.name}}.TranslateText(translator);
{{~end~}}
}
partial void PostInit();
partial void PostResolve();
}
{{cs_end_name_space_grace x.namespace}}

View File

@@ -0,0 +1,126 @@
using Bright.Serialization;
using System.Collections.Generic;
using System.Text.Json;
{{
name = x.name
parent_def_type = x.parent_def_type
parent = x.parent
export_fields = x.export_fields
hierarchy_export_fields = x.hierarchy_export_fields
}}
{{cs_start_name_space_grace x.namespace_with_top_module}}
{{~if x.comment != '' ~}}
/// <summary>
/// {{x.escape_comment}}
/// </summary>
{{~end~}}
public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {{parent}} {{else}} Bright.Config.BeanBase {{end}}
{
public {{name}}(JsonElement _json) {{if parent_def_type}} : base(_json) {{end}}
{
{{~ for field in export_fields ~}}
{{cs_json_deserialize '_json' field.convention_name field.name field.ctype}}
{{~if field.index_field~}}
foreach(var _v in {{field.convention_name}}) { {{field.convention_name}}_Index.Add(_v.{{field.index_field.convention_name}}, _v); }
{{~end~}}
{{~end~}}
PostInit();
}
public {{name}}({{~for field in hierarchy_export_fields }}{{cs_define_type field.ctype}} {{field.name}}{{if !for.last}},{{end}} {{end}}) {{if parent_def_type}} : base({{- for field in parent_def_type.hierarchy_export_fields }}{{field.name}}{{if !for.last}},{{end}}{{end}}) {{end}}
{
{{~ for field in export_fields ~}}
this.{{field.convention_name}} = {{field.name}};
{{~if field.index_field~}}
foreach(var _v in {{field.convention_name}}) { {{field.convention_name}}_Index.Add(_v.{{field.index_field.convention_name}}, _v); }
{{~end~}}
{{~end~}}
PostInit();
}
public static {{name}} Deserialize{{name}}(JsonElement _json)
{
{{~if x.is_abstract_type~}}
switch (_json.GetProperty("{{x.json_type_name_key}}").GetString())
{
{{~for child in x.hierarchy_not_abstract_children~}}
case "{{cs_impl_data_type child x}}": return new {{child.full_name}}(_json);
{{~end~}}
default: throw new SerializationException();
}
{{~else~}}
return new {{x.full_name}}(_json);
{{~end~}}
}
{{~ for field in export_fields ~}}
{{~if field.comment != '' ~}}
/// <summary>
/// {{field.escape_comment}}
/// </summary>
{{~end~}}
public {{cs_define_type field.ctype}} {{field.convention_name}} { get; private set; }
{{~if field.index_field~}}
public readonly Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}> {{field.convention_name}}_Index = new Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}>();
{{~end~}}
{{~if field.gen_ref~}}
public {{field.cs_ref_validator_define}}
{{~end~}}
{{~if (gen_datetime_mills field.ctype) ~}}
public long {{field.convention_name}}_Millis => {{field.convention_name}} * 1000L;
{{~end~}}
{{~if field.gen_text_key~}}
public {{cs_define_text_key_field field}} { get; }
{{~end~}}
{{~end~}}
{{~if !x.is_abstract_type~}}
public const int __ID__ = {{x.id}};
public override int GetTypeId() => __ID__;
{{~end~}}
public {{x.cs_method_modifier}} void Resolve(Dictionary<string, object> _tables)
{
{{~if parent_def_type~}}
base.Resolve(_tables);
{{~end~}}
{{~ for field in export_fields ~}}
{{~if field.gen_ref~}}
{{cs_ref_validator_resolve field}}
{{~else if field.has_recursive_ref~}}
{{cs_recursive_resolve field '_tables'}}
{{~end~}}
{{~end~}}
PostResolve();
}
public {{x.cs_method_modifier}} void TranslateText(System.Func<string, string, string> translator)
{
{{~if parent_def_type~}}
base.TranslateText(translator);
{{~end~}}
{{~ for field in export_fields ~}}
{{~if field.gen_text_key~}}
{{cs_translate_text field 'translator'}}
{{~else if field.has_recursive_text~}}
{{cs_recursive_translate_text field 'translator'}}
{{~end~}}
{{~end~}}
}
public override string ToString()
{
return "{{full_name}}{ "
{{~ for field in hierarchy_export_fields ~}}
+ "{{field.convention_name}}:" + {{cs_to_string field.convention_name field.ctype}} + ","
{{~end~}}
+ "}";
}
partial void PostInit();
partial void PostResolve();
}
{{cs_end_name_space_grace x.namespace_with_top_module}}

View File

@@ -0,0 +1,173 @@
using Bright.Serialization;
using System.Collections.Generic;
using System.Text.Json;
{{
name = x.name
key_type = x.key_ttype
key_type1 = x.key_ttype1
key_type2 = x.key_ttype2
value_type = x.value_ttype
}}
{{cs_start_name_space_grace x.namespace_with_top_module}}
{{~if x.comment != '' ~}}
/// <summary>
/// {{x.escape_comment}}
/// </summary>
{{~end~}}
public sealed partial class {{name}}
{
{{~if x.is_map_table ~}}
private readonly Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> _dataMap;
private readonly List<{{cs_define_type value_type}}> _dataList;
public {{name}}(JsonElement _json)
{
_dataMap = new Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}>();
_dataList = new List<{{cs_define_type value_type}}>();
foreach(JsonElement _row in _json.EnumerateArray())
{
var _v = {{cs_define_type value_type}}.Deserialize{{value_type.bean.name}}(_row);
_dataList.Add(_v);
_dataMap.Add(_v.{{x.index_field.convention_name}}, _v);
}
PostInit();
}
public Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> DataMap => _dataMap;
public List<{{cs_define_type value_type}}> DataList => _dataList;
{{~if value_type.is_dynamic~}}
public T GetOrDefaultAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => _dataMap.TryGetValue(key, out var v) ? (T)v : null;
public T GetAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => (T)_dataMap[key];
{{~end~}}
public {{cs_define_type value_type}} GetOrDefault({{cs_define_type key_type}} key) => _dataMap.TryGetValue(key, out var v) ? v : null;
public {{cs_define_type value_type}} Get({{cs_define_type key_type}} key) => _dataMap[key];
public {{cs_define_type value_type}} this[{{cs_define_type key_type}} key] => _dataMap[key];
public void Resolve(Dictionary<string, object> _tables)
{
foreach(var v in _dataList)
{
v.Resolve(_tables);
}
PostResolve();
}
public void TranslateText(System.Func<string, string, string> translator)
{
foreach(var v in _dataList)
{
v.TranslateText(translator);
}
}
{{~else if x.is_list_table ~}}
private readonly List<{{cs_define_type value_type}}> _dataList;
{{~if x.is_union_index~}}
private {{cs_table_union_map_type_name x}} _dataMapUnion;
{{~else if !x.index_list.empty?~}}
{{~for idx in x.index_list~}}
private Dictionary<{{cs_define_type idx.type}}, {{cs_define_type value_type}}> _dataMap_{{idx.index_field.name}};
{{~end~}}
{{~end~}}
public {{name}}(JsonElement _json)
{
_dataList = new List<{{cs_define_type value_type}}>();
foreach(JsonElement _row in _json.EnumerateArray())
{
var _v = {{cs_define_type value_type}}.Deserialize{{value_type.bean.name}}(_row);
_dataList.Add(_v);
}
{{~if x.is_union_index~}}
_dataMapUnion = new {{cs_table_union_map_type_name x}}();
foreach(var _v in _dataList)
{
_dataMapUnion.Add(({{cs_table_key_list x "_v"}}), _v);
}
{{~else if !x.index_list.empty?~}}
{{~for idx in x.index_list~}}
_dataMap_{{idx.index_field.name}} = new Dictionary<{{cs_define_type idx.type}}, {{cs_define_type value_type}}>();
{{~end~}}
foreach(var _v in _dataList)
{
{{~for idx in x.index_list~}}
_dataMap_{{idx.index_field.name}}.Add(_v.{{idx.index_field.convention_name}}, _v);
{{~end~}}
}
{{~end~}}
PostInit();
}
public List<{{cs_define_type value_type}}> DataList => _dataList;
{{~if x.is_union_index~}}
public {{cs_define_type value_type}} Get({{cs_table_get_param_def_list x}}) => _dataMapUnion.TryGetValue(({{cs_table_get_param_name_list x}}), out {{cs_define_type value_type}} __v) ? __v : null;
{{~else if !x.index_list.empty? ~}}
{{~for idx in x.index_list~}}
public {{cs_define_type value_type}} GetBy{{idx.index_field.convention_name}}({{cs_define_type idx.type}} key) => _dataMap_{{idx.index_field.name}}.TryGetValue(key, out {{cs_define_type value_type}} __v) ? __v : null;
{{~end~}}
{{~end~}}
public void Resolve(Dictionary<string, object> _tables)
{
foreach(var v in _dataList)
{
v.Resolve(_tables);
}
PostResolve();
}
public void TranslateText(System.Func<string, string, string> translator)
{
foreach(var v in _dataList)
{
v.TranslateText(translator);
}
}
{{~else~}}
private readonly {{cs_define_type value_type}} _data;
public {{name}}(JsonElement _json)
{
int n = _json.GetArrayLength();
if (n != 1) throw new SerializationException("table mode=one, but size != 1");
_data = {{cs_define_type value_type}}.Deserialize{{value_type.bean.name}}(_json[0]);
PostInit();
}
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
{{~if field.comment != '' ~}}
/// <summary>
/// {{field.escape_comment}}
/// </summary>
{{~end~}}
public {{cs_define_type field.ctype}} {{field.convention_name}} => _data.{{field.convention_name}};
{{~end~}}
public void Resolve(Dictionary<string, object> _tables)
{
_data.Resolve(_tables);
PostResolve();
}
public void TranslateText(System.Func<string, string, string> translator)
{
_data.TranslateText(translator);
}
{{~end~}}
partial void PostInit();
partial void PostResolve();
}
{{cs_end_name_space_grace x.namespace_with_top_module}}

View File

@@ -0,0 +1,48 @@
using Bright.Serialization;
using System.Text.Json;
{{
name = x.name
namespace = x.namespace
tables = x.tables
}}
{{cs_start_name_space_grace x.namespace}}
public sealed partial class {{name}}
{
{{~for table in tables ~}}
{{~if table.comment != '' ~}}
/// <summary>
/// {{table.escape_comment}}
/// </summary>
{{~end~}}
public {{table.full_name}} {{table.name}} {get; }
{{~end~}}
public {{name}}(System.Func<string, JsonElement> loader)
{
var tables = new System.Collections.Generic.Dictionary<string, object>();
{{~for table in tables ~}}
{{table.name}} = new {{table.full_name}}(loader("{{table.output_data_file}}"));
tables.Add("{{table.full_name}}", {{table.name}});
{{~end~}}
PostInit();
{{~for table in tables ~}}
{{table.name}}.Resolve(tables);
{{~end~}}
PostResolve();
}
public void TranslateText(System.Func<string, string, string> translator)
{
{{~for table in tables ~}}
{{table.name}}.TranslateText(translator);
{{~end~}}
}
partial void PostInit();
partial void PostResolve();
}
{{cs_end_name_space_grace x.namespace}}

View File

@@ -0,0 +1,110 @@
using Bright.Serialization;
using System.Collections.Generic;
using SimpleJSON;
{{
name = x.name
parent_def_type = x.parent_def_type
parent = x.parent
hierarchy_fields = x.hierarchy_fields
fields = x.fields
}}
{{cs_start_name_space_grace x.namespace_with_editor_top_module}}
{{~if x.comment != '' ~}}
/// <summary>
/// {{x.escape_comment}}
/// </summary>
{{~end~}}
public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {{parent}} {{else}} Bright.Config.EditorBeanBase {{end}}
{
public {{name}}()
{
{{~ for field in fields ~}}
{{~if (cs_editor_need_init field.ctype) && !field.ctype.is_nullable ~}}
{{field.convention_name}} = {{cs_editor_init_value field.ctype}};
{{~end~}}
{{~end~}}
}
{{~if !x.is_abstract_type~}}
public override void LoadJson(SimpleJSON.JSONObject _json)
{
{{~ for field in hierarchy_fields ~}}
{
var _fieldJson = _json["{{field.name}}"];
if (_fieldJson != null)
{
{{cs_unity_editor_json_load '_fieldJson' field.convention_name field.ctype}}
}
}
{{~end~}}
}
public override void SaveJson(SimpleJSON.JSONObject _json)
{
{{~if parent~}}
_json["{{x.json_type_name_key}}"] = "{{x.full_name}}";
{{~end~}}
{{~ for field in hierarchy_fields ~}}
{{~if field.ctype.is_nullable}}
if ({{field.convention_name}} != null)
{
{{cs_unity_editor_json_save '_json' field.name field.convention_name field.ctype}}
}
{{~else~}}
{
{{~if (cs_is_editor_raw_nullable field.ctype)}}
if ({{field.convention_name}} == null) { throw new System.ArgumentNullException(); }
{{~end~}}
{{cs_unity_editor_json_save '_json' field.name field.convention_name field.ctype}}
}
{{~end~}}
{{~end~}}
}
{{~end~}}
public static {{name}} LoadJson{{name}}(SimpleJSON.JSONNode _json)
{
{{~if x.is_abstract_type~}}
string type = _json["{{x.json_type_name_key}}"];
{{name}} obj;
switch (type)
{
{{~for child in x.hierarchy_not_abstract_children~}}
{{~if child.namespace == x.namespace && x.namespace != '' ~}}
case "{{child.full_name}}":
{{~end~}}
case "{{cs_impl_data_type child x}}":obj = new {{child.full_name}}(); break;
{{~end~}}
default: throw new SerializationException();
}
{{~else~}}
{{name}} obj = new {{x.full_name}}();
{{~end~}}
obj.LoadJson((SimpleJSON.JSONObject)_json);
return obj;
}
public static void SaveJson{{name}}({{name}} _obj, SimpleJSON.JSONNode _json)
{
{{~if x.is_abstract_type~}}
_json["{{x.json_type_name_key}}"] = _obj.GetType().Name;
{{~end~}}
_obj.SaveJson((SimpleJSON.JSONObject)_json);
}
{{~ for field in fields ~}}
{{~if field.comment != '' ~}}
/// <summary>
/// {{field.escape_comment}}
/// </summary>
{{~end~}}
public {{cs_editor_define_type field.ctype}} {{field.convention_name}} { get; set; }
{{~end~}}
}
{{cs_end_name_space_grace x.namespace_with_editor_top_module}}

View File

@@ -0,0 +1,60 @@
{{~
name = x.name
comment = x.comment
items = x.items
itemType = 'Bright.Config.EditorEnumItemInfo'
~}}
{{cs_start_name_space_grace x.namespace_with_editor_top_module}}
{{~if comment != '' ~}}
/// <summary>
/// {{comment | html.escape}}
/// </summary>
{{~end~}}
{{~if x.is_flags~}}
[System.Flags]
{{~end~}}
public enum {{name}}
{
{{~ for item in items ~}}
{{~if item.comment != '' ~}}
/// <summary>
/// {{item.escape_comment}}
/// </summary>
{{~end~}}
{{item.name}} = {{item.value}},
{{~end~}}
}
public static partial class {{name}}_Metadata
{
{{~ for item in items ~}}
public static readonly {{itemType}} {{item.name}} = new {{itemType}}("{{item.name}}", "{{item.alias}}", {{item.int_value}}, "{{item.comment}}");
{{~end~}}
private static readonly System.Collections.Generic.List<{{itemType}}> __items = new System.Collections.Generic.List<{{itemType}}>
{
{{~ for item in items ~}}
{{item.name}},
{{~end~}}
};
public static System.Collections.Generic.List<{{itemType}}> GetItems() => __items;
public static {{itemType}} GetByName(string name)
{
return __items.Find(c => c.Name == name);
}
public static {{itemType}} GetByNameOrAlias(string name)
{
return __items.Find(c => c.Name == name || c.Alias == name);
}
public static {{itemType}} GetByValue(int value)
{
return __items.Find(c => c.Value == value);
}
}
{{cs_end_name_space_grace x.namespace_with_editor_top_module}}

View File

@@ -0,0 +1,127 @@
using Bright.Serialization;
using System.Collections.Generic;
using SimpleJSON;
{{
name = x.name
parent_def_type = x.parent_def_type
parent = x.parent
export_fields = x.export_fields
hierarchy_export_fields = x.hierarchy_export_fields
}}
{{cs_start_name_space_grace x.namespace_with_top_module}}
{{~if x.comment != '' ~}}
/// <summary>
/// {{x.escape_comment}}
/// </summary>
{{~end~}}
public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {{parent}} {{else}} Bright.Config.BeanBase {{end}}
{
public {{name}}(JSONNode _json) {{if parent_def_type}} : base(_json) {{end}}
{
{{~ for field in export_fields ~}}
{{cs_unity_json_deserialize '_json' field.convention_name field.name field.ctype}}
{{~if field.index_field~}}
foreach(var _v in {{field.convention_name}}) { {{field.convention_name}}_Index.Add(_v.{{field.index_field.convention_name}}, _v); }
{{~end~}}
{{~end~}}
PostInit();
}
public {{name}}({{~for field in hierarchy_export_fields }}{{cs_define_type field.ctype}} {{field.name}}{{if !for.last}},{{end}} {{end}}) {{if parent_def_type}} : base({{- for field in parent_def_type.hierarchy_export_fields }}{{field.name}}{{if !for.last}},{{end}}{{end}}) {{end}}
{
{{~ for field in export_fields ~}}
this.{{field.convention_name}} = {{field.name}};
{{~if field.index_field~}}
foreach(var _v in {{field.convention_name}}) { {{field.convention_name}}_Index.Add(_v.{{field.index_field.convention_name}}, _v); }
{{~end~}}
{{~end~}}
PostInit();
}
public static {{name}} Deserialize{{name}}(JSONNode _json)
{
{{~if x.is_abstract_type~}}
string type = _json["{{x.json_type_name_key}}"];
switch (type)
{
{{~for child in x.hierarchy_not_abstract_children~}}
case "{{cs_impl_data_type child x}}": return new {{child.full_name}}(_json);
{{~end~}}
default: throw new SerializationException();
}
{{~else~}}
return new {{x.full_name}}(_json);
{{~end~}}
}
{{~ for field in export_fields ~}}
{{~if field.comment != '' ~}}
/// <summary>
/// {{field.escape_comment}}
/// </summary>
{{~end~}}
public {{cs_define_type field.ctype}} {{field.convention_name}} { get; private set; }
{{~if field.index_field~}}
public readonly Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}> {{field.convention_name}}_Index = new Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}>();
{{~end~}}
{{~if field.gen_ref~}}
public {{field.cs_ref_validator_define}}
{{~end~}}
{{~if (gen_datetime_mills field.ctype) ~}}
public long {{field.convention_name}}_Millis => {{field.convention_name}} * 1000L;
{{~end~}}
{{~if field.gen_text_key~}}
public {{cs_define_text_key_field field}} { get; }
{{~end~}}
{{~end~}}
{{~if !x.is_abstract_type~}}
public const int __ID__ = {{x.id}};
public override int GetTypeId() => __ID__;
{{~end~}}
public {{x.cs_method_modifier}} void Resolve(Dictionary<string, object> _tables)
{
{{~if parent_def_type~}}
base.Resolve(_tables);
{{~end~}}
{{~ for field in export_fields ~}}
{{~if field.gen_ref~}}
{{cs_ref_validator_resolve field}}
{{~else if field.has_recursive_ref~}}
{{cs_recursive_resolve field '_tables'}}
{{~end~}}
{{~end~}}
PostResolve();
}
public {{x.cs_method_modifier}} void TranslateText(System.Func<string, string, string> translator)
{
{{~if parent_def_type~}}
base.TranslateText(translator);
{{~end~}}
{{~ for field in export_fields ~}}
{{~if field.gen_text_key~}}
{{cs_translate_text field 'translator'}}
{{~else if field.has_recursive_text~}}
{{cs_recursive_translate_text field 'translator'}}
{{~end~}}
{{~end~}}
}
public override string ToString()
{
return "{{full_name}}{ "
{{~ for field in hierarchy_export_fields ~}}
+ "{{field.convention_name}}:" + {{cs_to_string field.convention_name field.ctype}} + ","
{{~end~}}
+ "}";
}
partial void PostInit();
partial void PostResolve();
}
{{cs_end_name_space_grace x.namespace_with_top_module}}

View File

@@ -0,0 +1,176 @@
using Bright.Serialization;
using System.Collections.Generic;
using SimpleJSON;
{{
name = x.name
key_type = x.key_ttype
key_type1 = x.key_ttype1
key_type2 = x.key_ttype2
value_type = x.value_ttype
}}
{{cs_start_name_space_grace x.namespace_with_top_module}}
{{~if x.comment != '' ~}}
/// <summary>
/// {{x.escape_comment}}
/// </summary>
{{~end~}}
public sealed partial class {{name}}
{
{{~if x.is_map_table ~}}
private readonly Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> _dataMap;
private readonly List<{{cs_define_type value_type}}> _dataList;
public {{name}}(JSONNode _json)
{
_dataMap = new Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}>();
_dataList = new List<{{cs_define_type value_type}}>();
foreach(JSONNode _row in _json.Children)
{
var _v = {{cs_define_type value_type}}.Deserialize{{value_type.bean.name}}(_row);
_dataList.Add(_v);
_dataMap.Add(_v.{{x.index_field.convention_name}}, _v);
}
PostInit();
}
public Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> DataMap => _dataMap;
public List<{{cs_define_type value_type}}> DataList => _dataList;
{{~if value_type.is_dynamic~}}
public T GetOrDefaultAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => _dataMap.TryGetValue(key, out var v) ? (T)v : null;
public T GetAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => (T)_dataMap[key];
{{~end~}}
public {{cs_define_type value_type}} GetOrDefault({{cs_define_type key_type}} key) => _dataMap.TryGetValue(key, out var v) ? v : null;
public {{cs_define_type value_type}} Get({{cs_define_type key_type}} key) => _dataMap[key];
public {{cs_define_type value_type}} this[{{cs_define_type key_type}} key] => _dataMap[key];
public void Resolve(Dictionary<string, object> _tables)
{
foreach(var v in _dataList)
{
v.Resolve(_tables);
}
PostResolve();
}
public void TranslateText(System.Func<string, string, string> translator)
{
foreach(var v in _dataList)
{
v.TranslateText(translator);
}
}
{{~else if x.is_list_table ~}}
private readonly List<{{cs_define_type value_type}}> _dataList;
{{~if x.is_union_index~}}
private {{cs_table_union_map_type_name x}} _dataMapUnion;
{{~else if !x.index_list.empty?~}}
{{~for idx in x.index_list~}}
private Dictionary<{{cs_define_type idx.type}}, {{cs_define_type value_type}}> _dataMap_{{idx.index_field.name}};
{{~end~}}
{{~end~}}
public {{name}}(JSONNode _json)
{
_dataList = new List<{{cs_define_type value_type}}>();
foreach(JSONNode _row in _json.Children)
{
var _v = {{cs_define_type value_type}}.Deserialize{{value_type.bean.name}}(_row);
_dataList.Add(_v);
}
{{~if x.is_union_index~}}
_dataMapUnion = new {{cs_table_union_map_type_name x}}();
foreach(var _v in _dataList)
{
_dataMapUnion.Add(({{cs_table_key_list x "_v"}}), _v);
}
{{~else if !x.index_list.empty?~}}
{{~for idx in x.index_list~}}
_dataMap_{{idx.index_field.name}} = new Dictionary<{{cs_define_type idx.type}}, {{cs_define_type value_type}}>();
{{~end~}}
foreach(var _v in _dataList)
{
{{~for idx in x.index_list~}}
_dataMap_{{idx.index_field.name}}.Add(_v.{{idx.index_field.convention_name}}, _v);
{{~end~}}
}
{{~end~}}
PostInit();
}
public List<{{cs_define_type value_type}}> DataList => _dataList;
{{~if x.is_union_index~}}
public {{cs_define_type value_type}} Get({{cs_table_get_param_def_list x}}) => _dataMapUnion.TryGetValue(({{cs_table_get_param_name_list x}}), out {{cs_define_type value_type}} __v) ? __v : null;
{{~else if !x.index_list.empty? ~}}
{{~for idx in x.index_list~}}
public {{cs_define_type value_type}} GetBy{{idx.index_field.convention_name}}({{cs_define_type idx.type}} key) => _dataMap_{{idx.index_field.name}}.TryGetValue(key, out {{cs_define_type value_type}} __v) ? __v : null;
{{~end~}}
{{~end~}}
public void Resolve(Dictionary<string, object> _tables)
{
foreach(var v in _dataList)
{
v.Resolve(_tables);
}
PostResolve();
}
public void TranslateText(System.Func<string, string, string> translator)
{
foreach(var v in _dataList)
{
v.TranslateText(translator);
}
}
{{~else~}}
private readonly {{cs_define_type value_type}} _data;
public {{name}}(JSONNode _json)
{
if(!_json.IsArray)
{
throw new SerializationException();
}
if (_json.Count != 1) throw new SerializationException("table mode=one, but size != 1");
_data = {{cs_define_type value_type}}.Deserialize{{value_type.bean.name}}(_json[0]);
PostInit();
}
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
{{~if field.comment != '' ~}}
/// <summary>
/// {{field.escape_comment}}
/// </summary>
{{~end~}}
public {{cs_define_type field.ctype}} {{field.convention_name}} => _data.{{field.convention_name}};
{{~end~}}
public void Resolve(Dictionary<string, object> _tables)
{
_data.Resolve(_tables);
PostResolve();
}
public void TranslateText(System.Func<string, string, string> translator)
{
_data.TranslateText(translator);
}
{{~end~}}
partial void PostInit();
partial void PostResolve();
}
{{cs_end_name_space_grace x.namespace_with_top_module}}

View File

@@ -0,0 +1,48 @@
using Bright.Serialization;
using SimpleJSON;
{{
name = x.name
namespace = x.namespace
tables = x.tables
}}
{{cs_start_name_space_grace x.namespace}}
public sealed partial class {{name}}
{
{{~for table in tables ~}}
{{~if table.comment != '' ~}}
/// <summary>
/// {{table.escape_comment}}
/// </summary>
{{~end~}}
public {{table.full_name}} {{table.name}} {get; }
{{~end~}}
public {{name}}(System.Func<string, JSONNode> loader)
{
var tables = new System.Collections.Generic.Dictionary<string, object>();
{{~for table in tables ~}}
{{table.name}} = new {{table.full_name}}(loader("{{table.output_data_file}}"));
tables.Add("{{table.full_name}}", {{table.name}});
{{~end~}}
PostInit();
{{~for table in tables ~}}
{{table.name}}.Resolve(tables);
{{~end~}}
PostResolve();
}
public void TranslateText(System.Func<string, string, string> translator)
{
{{~for table in tables ~}}
{{table.name}}.TranslateText(translator);
{{~end~}}
}
partial void PostInit();
partial void PostResolve();
}
{{cs_end_name_space_grace x.namespace}}

View File

@@ -0,0 +1,41 @@
namespace {{x.namespace}};
// luban internal types begin
struct Vector2 {
x:float;
y:float;
}
struct Vector3 {
x:float;
y:float;
z:float;
}
struct Vector4 {
x:float;
y:float;
z:float;
w:float;
}
// luban internal types end
{{~for enum in x.enums ~}}
{{enum}}
{{~end~}}
{{~for bean in x.beans~}}
{{bean}}
{{~end~}}
{{~for map in x.maps~}}
table KeyValue_{{flat_buffers_define_type map.key_type}}_{{flat_buffers_define_type map.value_type}} {
key: {{flat_buffers_define_type map.key_type}}{{flat_buffers_type_metadata map.key_type}};
value: {{flat_buffers_define_type map.value_type}}{{flat_buffers_type_metadata map.value_type}};
}
{{~end~}}
{{~for table in x.tables~}}
{{table}}
{{~end~}}

View File

@@ -0,0 +1,20 @@
{{~
name = x.name
parent_def_type = x.parent_def_type
export_fields = x.export_fields
hierarchy_export_fields = x.hierarchy_export_fields
~}}
{{~if x.is_abstract_type ~}}
union {{x.flat_buffers_full_name}} {
{{~for c in x.hierarchy_not_abstract_children~}}
{{c.flat_buffers_full_name}},
{{~end~}}
}
{{~else~}}
table {{x.flat_buffers_full_name}} {
{{~for f in hierarchy_export_fields ~}}
{{f.name}}:{{flat_buffers_define_type f.ctype}}{{flat_buffers_type_metadata f.ctype}};
{{~end~}}
}
{{~end~}}

View File

@@ -0,0 +1,16 @@
{{~
name = x.name
namespace = x.namespace
tables = x.tables
~}}
echo off
set FLATC=%1
set SCHEMA_FILE=%2
set DATA_DIR=%3
set OUTPUT_DIR=%4
{{~for table in tables~}}
%FLATC% -o %OUTPUT_DIR% -b %SCHEMA_FILE% --root-type {{if namespace != ''}}{{namespace}}.{{end}}{{table.flat_buffers_full_name}} %DATA_DIR%\{{table.output_data_file}}.json
{{~end~}}

View File

@@ -0,0 +1,16 @@
{{~
name = x.name
namespace = x.namespace
tables = x.tables
~}}
@echo off
FLATC=$1
SCHEMA_FILE=$2
DATA_DIR=$3
OUTPUT_DIR=$4
{{~for table in tables~}}
$FLATC -o $OUTPUT_DIR -b $SCHEMA_FILE --root-type {{if namespace != ''}}{{namespace}}.{{end}}{{table.flat_buffers_full_name}} $DATA_DIR/{{table.output_data_file}}.json
{{~end~}}

View File

@@ -0,0 +1,12 @@
{{~
name = x.name
key_type = x.key_ttype
value_type = x.value_ttype
~}}
table {{x.flat_buffers_full_name}} {
// WARN! The name 'data_list' is used by FlatBuffersJsonExporter. don't modify it!
data_list:[{{flat_buffers_define_type value_type}}](required);
}
root_type {{x.flat_buffers_full_name}};

View File

@@ -0,0 +1,5 @@
{{~
name = x.name
namespace = x.namespace
tables = x.tables
~}}

View File

@@ -0,0 +1,39 @@
{{
name = x.gdscript_full_name
is_abstract_type = x.is_abstract_type
parent_def_type = x.parent_def_type
export_fields = x.export_fields
hierarchy_export_fields = x.hierarchy_export_fields
}}
class {{name}}:
{{if parent_def_type}}
extends {{parent_def_type.gdscript_full_name}}
{{end}}
{{~if x.is_abstract_type~}}
static func from_json(_json_):
var type = _json_['{{x.json_type_name_key}}']
match type:
{{~ for child in x.hierarchy_not_abstract_children~}}
"{{cs_impl_data_type child x}}":
return {{child.gdscript_full_name}}.new(_json_)
{{~end~}}
_:
assert(false)
{{~end~}}
{{~ for field in export_fields ~}}
var {{field.convention_name}}
{{~end~}}
{{~if parent_def_type~}}
func _init(_json_).(_json_) -> void:
{{~else~}}
func _init(_json_) -> void:
{{~end~}}
{{~if export_fields~}}
{{~ for field in export_fields ~}}
{{gdscript_deserialize_field ('self.' + field.convention_name) '_json_' field.name field.ctype}}
{{~end~}}
{{~end~}}
{{~if export_fields.empty?}}
pass
{{~end~}}

View File

@@ -0,0 +1 @@
class_name Types

View File

@@ -0,0 +1,92 @@
{{
name = x.gdscript_full_name
key_type = x.key_ttype
key_type1 = x.key_ttype1
key_type2 = x.key_ttype2
value_type = x.value_ttype
}}
class {{name}}:
{{~if x.is_map_table ~}}
var _data_map = {}
var _data_list = []
func _init(_json_) -> void:
self._data_map = {}
self._data_list = []
for _json2_ in _json_:
var _v
{{gdscript_deserialize_value '_v' '_json2_' value_type}}
self._data_list.append(_v)
self._data_map[_v.{{x.index_field.convention_name}}] = _v
func get_data_map() -> Dictionary:
return self._data_map
func get_data_list() -> Array:
return self._data_list
func get(key):
return self._data_map.get(key)
{{~else if x.multi_key ~}}
{{~ for INDEX in x.index_list ~}}
var _data_{{INDEX.index_field.convention_name}}_map = {}
{{~ end ~}}
var _data_list = []
func _init(_json_) -> void:
{{~ for INDEX in x.index_list ~}}
self._data_{{INDEX.index_field.convention_name}}_map = {}
{{~ end ~}}
self._data_list = []
for _json2_ in _json_:
var _v
{{gdscript_deserialize_value '_v' '_json2_' value_type}}
self._data_list.append(_v)
{{~ for INDEX in x.index_list ~}}
self._data_{{INDEX.index_field.convention_name}}_map[_v.{{INDEX.index_field.convention_name}}] = _v
{{~ end ~}}
func get_data_map() -> Dictionary:
return self._data_{{x.index_field.convention_name }}_map
func get_data_list() -> Array:
return self._data_list
{{~ for INDEX in x.index_list ~}}
func get_by_{{INDEX.index_field.convention_name}}({{INDEX.index_field.convention_name}}):
return self._data_{{INDEX.index_field.name}}_map.get({{INDEX.index_field.convention_name}})
{{~ end ~}}
func get(key):
return self._data_{{x.index_field.convention_name }}_map.get(key)
{{~else if x.is_list_table ~}}
var _data_list
func _init(_json_) -> void:
self._data_list = []
for _json2_ in _json_:
var _v
{{gdscript_deserialize_value '_v' '_json2_' value_type}}
self._data_list.append(_v)
func get_data_list():
return self._data_list
func get(index):
return self._data_list[index]
{{~else~}}
var _data: Dictionary
func _init(_json_) -> void:
assert(len(_json_) == 1, 'table mode=one, but size != 1')
self._data = _json_[0]
func get_data() -> Dictionary:
return self._data
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
{{~if field.comment != '' ~}}
# {{field.escape_comment}}
{{~end~}}
func {{field.convention_name}}():
return self._data.{{field.convention_name}}
{{~end~}}
{{~end~}}

Some files were not shown because too many files have changed in this diff Show More