mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Start TEngine3.0
Start TEngine3.0
This commit is contained in:
25
Luban/Luban.ClientServer/Templates/common/cpp/enum.tpl
Normal file
25
Luban/Luban.ClientServer/Templates/common/cpp/enum.tpl
Normal 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}}
|
30
Luban/Luban.ClientServer/Templates/common/cs/enum.tpl
Normal file
30
Luban/Luban.ClientServer/Templates/common/cs/enum.tpl
Normal 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}}
|
@@ -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~}}
|
||||
}
|
20
Luban/Luban.ClientServer/Templates/common/gdscript/enum.tpl
Normal file
20
Luban/Luban.ClientServer/Templates/common/gdscript/enum.tpl
Normal 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~}}
|
||||
}
|
14
Luban/Luban.ClientServer/Templates/common/go/enum.tpl
Normal file
14
Luban/Luban.ClientServer/Templates/common/go/enum.tpl
Normal 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~}}
|
||||
)
|
23
Luban/Luban.ClientServer/Templates/common/java/enum.tpl
Normal file
23
Luban/Luban.ClientServer/Templates/common/java/enum.tpl
Normal 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~}}
|
||||
}
|
30
Luban/Luban.ClientServer/Templates/common/lua/base.tpl
Normal file
30
Luban/Luban.ClientServer/Templates/common/lua/base.tpl
Normal 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
|
15
Luban/Luban.ClientServer/Templates/common/protobuf2/enum.tpl
Normal file
15
Luban/Luban.ClientServer/Templates/common/protobuf2/enum.tpl
Normal 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~}}
|
||||
}
|
15
Luban/Luban.ClientServer/Templates/common/protobuf3/enum.tpl
Normal file
15
Luban/Luban.ClientServer/Templates/common/protobuf3/enum.tpl
Normal 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~}}
|
||||
}
|
24
Luban/Luban.ClientServer/Templates/common/python/enum.tpl
Normal file
24
Luban/Luban.ClientServer/Templates/common/python/enum.tpl
Normal 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~}}
|
25
Luban/Luban.ClientServer/Templates/common/rust/enum.tpl
Normal file
25
Luban/Luban.ClientServer/Templates/common/rust/enum.tpl
Normal 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~}}
|
||||
}
|
||||
|
@@ -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}}
|
@@ -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}}
|
||||
|
||||
}
|
66
Luban/Luban.ClientServer/Templates/config/cpp_bin/bean.tpl
Normal file
66
Luban/Luban.ClientServer/Templates/config/cpp_bin/bean.tpl
Normal 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}}
|
72
Luban/Luban.ClientServer/Templates/config/cpp_bin/stub.tpl
Normal file
72
Luban/Luban.ClientServer/Templates/config/cpp_bin/stub.tpl
Normal 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~}}
|
||||
}
|
215
Luban/Luban.ClientServer/Templates/config/cpp_bin/table.tpl
Normal file
215
Luban/Luban.ClientServer/Templates/config/cpp_bin/table.tpl
Normal 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}}
|
33
Luban/Luban.ClientServer/Templates/config/cpp_bin/tables.tpl
Normal file
33
Luban/Luban.ClientServer/Templates/config/cpp_bin/tables.tpl
Normal 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;
|
||||
}
|
||||
};
|
22
Luban/Luban.ClientServer/Templates/config/cpp_ue_bp/bean.tpl
Normal file
22
Luban/Luban.ClientServer/Templates/config/cpp_ue_bp/bean.tpl
Normal 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~}}
|
||||
};
|
19
Luban/Luban.ClientServer/Templates/config/cpp_ue_bp/enum.tpl
Normal file
19
Luban/Luban.ClientServer/Templates/config/cpp_ue_bp/enum.tpl
Normal 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~}}
|
||||
};
|
@@ -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}}
|
@@ -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}}
|
||||
|
||||
}
|
@@ -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~}}
|
||||
}
|
115
Luban/Luban.ClientServer/Templates/config/cs_bin/bean.tpl
Normal file
115
Luban/Luban.ClientServer/Templates/config/cs_bin/bean.tpl
Normal 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}}
|
173
Luban/Luban.ClientServer/Templates/config/cs_bin/table.tpl
Normal file
173
Luban/Luban.ClientServer/Templates/config/cs_bin/table.tpl
Normal 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}}
|
48
Luban/Luban.ClientServer/Templates/config/cs_bin/tables.tpl
Normal file
48
Luban/Luban.ClientServer/Templates/config/cs_bin/tables.tpl
Normal 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}}
|
@@ -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}}
|
@@ -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}}
|
@@ -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}}
|
@@ -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}}
|
@@ -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}}
|
127
Luban/Luban.ClientServer/Templates/config/cs_unity_json/bean.tpl
Normal file
127
Luban/Luban.ClientServer/Templates/config/cs_unity_json/bean.tpl
Normal 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}}
|
@@ -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}}
|
@@ -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}}
|
@@ -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~}}
|
||||
|
@@ -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~}}
|
@@ -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~}}
|
@@ -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~}}
|
@@ -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}};
|
@@ -0,0 +1,5 @@
|
||||
{{~
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
~}}
|
@@ -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~}}
|
@@ -0,0 +1 @@
|
||||
class_name Types
|
@@ -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~}}
|
@@ -0,0 +1,13 @@
|
||||
{{
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
}}
|
||||
{{~ for table in tables ~}}
|
||||
var {{table.name}}: {{table.gdscript_full_name}}
|
||||
{{~end~}}
|
||||
|
||||
func _init(loader) -> void:
|
||||
{{~for table in tables ~}}
|
||||
self.{{table.name}} = {{table.gdscript_full_name}}.new(loader.call('{{table.output_data_file}}'))
|
||||
{{~end~}}
|
64
Luban/Luban.ClientServer/Templates/config/go_bin/bean.tpl
Normal file
64
Luban/Luban.ClientServer/Templates/config/go_bin/bean.tpl
Normal file
@@ -0,0 +1,64 @@
|
||||
{{~
|
||||
go_full_name = x.go_full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
is_abstract_type = x.is_abstract_type
|
||||
hierarchy_fields = x.hierarchy_export_fields
|
||||
hierarchy_not_abstract_children = x.hierarchy_not_abstract_children
|
||||
~}}
|
||||
|
||||
package {{x.top_module}}
|
||||
|
||||
import (
|
||||
"{{assembly.args.go_bright_module_name}}/serialization"
|
||||
)
|
||||
|
||||
{{x.go_bin_import}}
|
||||
|
||||
type {{go_full_name}} struct {
|
||||
{{~for field in hierarchy_fields ~}}
|
||||
{{field.convention_name}} {{go_define_type field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
const TypeId_{{go_full_name}} = {{x.id}}
|
||||
|
||||
func (*{{go_full_name}}) GetTypeId() int32 {
|
||||
return {{x.id}}
|
||||
}
|
||||
|
||||
func (_v *{{go_full_name}})Serialize(_buf *serialization.ByteBuf) {
|
||||
// not support
|
||||
}
|
||||
|
||||
func (_v *{{go_full_name}})Deserialize(_buf *serialization.ByteBuf) (err error) {
|
||||
{{~for field in hierarchy_fields ~}}
|
||||
{{go_deserialize_field field.ctype ("_v." + field.convention_name) '_buf' 'err'}}
|
||||
{{~end~}}
|
||||
return
|
||||
}
|
||||
|
||||
{{~if is_abstract_type~}}
|
||||
func Deserialize{{go_full_name}}(_buf *serialization.ByteBuf) (interface{}, error) {
|
||||
var id int32
|
||||
var err error
|
||||
if id, err = _buf.ReadInt() ; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch id {
|
||||
{{~for child in hierarchy_not_abstract_children~}}
|
||||
case {{child.id}}: _v := &{{child.go_full_name}}{}; if err = _v.Deserialize(_buf); err != nil { return nil, errors.New("{{child.full_name}}") } else { return _v, nil }
|
||||
{{~end~}}
|
||||
default: return nil, errors.New("unknown type id")
|
||||
}
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
func Deserialize{{go_full_name}}(_buf *serialization.ByteBuf) (*{{go_full_name}}, error) {
|
||||
v := &{{go_full_name}}{}
|
||||
if err := v.Deserialize(_buf); err == nil {
|
||||
return v, nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
{{~end~}}
|
118
Luban/Luban.ClientServer/Templates/config/go_bin/table.tpl
Normal file
118
Luban/Luban.ClientServer/Templates/config/go_bin/table.tpl
Normal file
@@ -0,0 +1,118 @@
|
||||
{{~
|
||||
go_full_name = x.go_full_name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
index_field = x.index_field
|
||||
index_field1 = x.index_field1
|
||||
index_field2 = x.index_field2
|
||||
~}}
|
||||
|
||||
package {{x.top_module}}
|
||||
|
||||
import "{{assembly.args.go_bright_module_name}}/serialization"
|
||||
|
||||
{{~if x.is_map_table~}}
|
||||
type {{go_full_name}} struct {
|
||||
_dataMap map[{{go_define_type key_type}}]{{go_define_type value_type}}
|
||||
_dataList []{{go_define_type value_type}}
|
||||
}
|
||||
|
||||
func New{{go_full_name}}(_buf *serialization.ByteBuf) (*{{go_full_name}}, error) {
|
||||
if size, err := _buf.ReadSize() ; err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
_dataList := make([]{{go_define_type value_type}}, 0, size)
|
||||
dataMap := make(map[{{go_define_type key_type}}]{{go_define_type value_type}})
|
||||
|
||||
for i := 0 ; i < size ; i++ {
|
||||
if _v, err2 := {{go_deserialize_type value_type '_buf'}}; err2 != nil {
|
||||
return nil, err2
|
||||
} else {
|
||||
_dataList = append(_dataList, _v)
|
||||
{{~if value_type.is_dynamic ~}}
|
||||
{{~for child in value_type.bean.hierarchy_not_abstract_children~}}
|
||||
if __v, __is := _v.(*{{child.go_full_name}}) ; __is {
|
||||
dataMap[__v.{{index_field.convention_name}}] = _v
|
||||
continue
|
||||
}
|
||||
{{~end~}}
|
||||
{{~else~}}
|
||||
dataMap[_v.{{index_field.convention_name}}] = _v
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
return &{{go_full_name}}{_dataList:_dataList, _dataMap:dataMap}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) GetDataMap() map[{{go_define_type key_type}}]{{go_define_type value_type}} {
|
||||
return table._dataMap
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) GetDataList() []{{go_define_type value_type}} {
|
||||
return table._dataList
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) Get(key {{go_define_type key_type}}) {{go_define_type value_type}} {
|
||||
return table._dataMap[key]
|
||||
}
|
||||
|
||||
{{~else if x.is_list_table~}}
|
||||
type {{go_full_name}} struct {
|
||||
_dataList []{{go_define_type value_type}}
|
||||
}
|
||||
|
||||
func New{{go_full_name}}(_buf *serialization.ByteBuf) (*{{go_full_name}}, error) {
|
||||
if size, err := _buf.ReadSize() ; err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
_dataList := make([]{{go_define_type value_type}}, 0, size)
|
||||
|
||||
for i := 0 ; i < size ; i++ {
|
||||
if _v, err2 := {{go_deserialize_type value_type '_buf'}}; err2 != nil {
|
||||
return nil, err2
|
||||
} else {
|
||||
_dataList = append(_dataList, _v)
|
||||
}
|
||||
}
|
||||
return &{{go_full_name}}{_dataList:_dataList}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) GetDataList() []{{go_define_type value_type}} {
|
||||
return table._dataList
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) Get(index int) {{go_define_type value_type}} {
|
||||
return table._dataList[index]
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
|
||||
import "errors"
|
||||
|
||||
type {{go_full_name}} struct {
|
||||
_data {{go_define_type value_type}}
|
||||
}
|
||||
|
||||
func New{{go_full_name}}(_buf *serialization.ByteBuf) (*{{go_full_name}}, error) {
|
||||
if size, err := _buf.ReadSize() ; err != nil {
|
||||
return nil, err
|
||||
} else if size != 1 {
|
||||
return nil, errors.New(" size != 1 ")
|
||||
} else {
|
||||
if _v, err2 := {{go_deserialize_type value_type '_buf'}}; err2 != nil {
|
||||
return nil, err2
|
||||
} else {
|
||||
return &{{go_full_name}}{_data:_v}, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) Get() {{go_define_type value_type}} {
|
||||
return table._data
|
||||
}
|
||||
|
||||
{{~end~}}
|
33
Luban/Luban.ClientServer/Templates/config/go_bin/tables.tpl
Normal file
33
Luban/Luban.ClientServer/Templates/config/go_bin/tables.tpl
Normal file
@@ -0,0 +1,33 @@
|
||||
{{~
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
~}}
|
||||
|
||||
package {{namespace}}
|
||||
|
||||
import "{{assembly.args.go_bright_module_name}}/serialization"
|
||||
|
||||
type ByteBufLoader func(string) (*serialization.ByteBuf, error)
|
||||
|
||||
type {{name}} struct {
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}} *{{table.go_full_name}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
func NewTables(loader ByteBufLoader) (*{{name}}, error) {
|
||||
var err error
|
||||
var buf *serialization.ByteBuf
|
||||
|
||||
tables := &{{name}}{}
|
||||
{{~for table in tables ~}}
|
||||
if buf, err = loader("{{table.output_data_file}}") ; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tables.{{table.name}}, err = New{{table.go_full_name}}(buf) ; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
{{~end~}}
|
||||
return tables, nil
|
||||
}
|
55
Luban/Luban.ClientServer/Templates/config/go_json/bean.tpl
Normal file
55
Luban/Luban.ClientServer/Templates/config/go_json/bean.tpl
Normal file
@@ -0,0 +1,55 @@
|
||||
{{~
|
||||
go_full_name = x.go_full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
is_abstract_type = x.is_abstract_type
|
||||
hierarchy_fields = x.hierarchy_export_fields
|
||||
hierarchy_not_abstract_children = x.hierarchy_not_abstract_children
|
||||
~}}
|
||||
|
||||
package {{x.top_module}}
|
||||
|
||||
{{x.go_json_import}}
|
||||
|
||||
type {{go_full_name}} struct {
|
||||
{{~for field in hierarchy_fields ~}}
|
||||
{{field.convention_name}} {{go_define_type field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
const TypeId_{{go_full_name}} = {{x.id}}
|
||||
|
||||
func (*{{go_full_name}}) GetTypeId() int32 {
|
||||
return {{x.id}}
|
||||
}
|
||||
|
||||
func (_v *{{go_full_name}})Deserialize(_buf map[string]interface{}) (err error) {
|
||||
{{~for field in hierarchy_fields ~}}
|
||||
{{go_deserialize_json_field field.ctype ("_v." + field.convention_name) field.name '_buf'}}
|
||||
{{~end~}}
|
||||
return
|
||||
}
|
||||
|
||||
{{~if is_abstract_type~}}
|
||||
func Deserialize{{go_full_name}}(_buf map[string]interface{}) (interface{}, error) {
|
||||
var id string
|
||||
var _ok_ bool
|
||||
if id, _ok_ = _buf["{{x.json_type_name_key}}"].(string) ; !_ok_ {
|
||||
return nil, errors.New("type id missing")
|
||||
}
|
||||
switch id {
|
||||
{{~for child in hierarchy_not_abstract_children~}}
|
||||
case "{{cs_impl_data_type child x}}": _v := &{{child.go_full_name}}{}; if err := _v.Deserialize(_buf); err != nil { return nil, errors.New("{{child.full_name}}") } else { return _v, nil }
|
||||
{{~end~}}
|
||||
default: return nil, errors.New("unknown type id")
|
||||
}
|
||||
}
|
||||
{{~else~}}
|
||||
func Deserialize{{go_full_name}}(_buf map[string]interface{}) (*{{go_full_name}}, error) {
|
||||
v := &{{go_full_name}}{}
|
||||
if err := v.Deserialize(_buf); err == nil {
|
||||
return v, nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
{{~end~}}
|
105
Luban/Luban.ClientServer/Templates/config/go_json/table.tpl
Normal file
105
Luban/Luban.ClientServer/Templates/config/go_json/table.tpl
Normal file
@@ -0,0 +1,105 @@
|
||||
{{~
|
||||
go_full_name = x.go_full_name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
index_field = x.index_field
|
||||
index_field1 = x.index_field1
|
||||
index_field2 = x.index_field2
|
||||
~}}
|
||||
|
||||
package {{x.top_module}}
|
||||
|
||||
{{~if x.is_map_table~}}
|
||||
type {{go_full_name}} struct {
|
||||
_dataMap map[{{go_define_type key_type}}]{{go_define_type value_type}}
|
||||
_dataList []{{go_define_type value_type}}
|
||||
}
|
||||
|
||||
func New{{go_full_name}}(_buf []map[string]interface{}) (*{{go_full_name}}, error) {
|
||||
_dataList := make([]{{go_define_type value_type}}, 0, len(_buf))
|
||||
dataMap := make(map[{{go_define_type key_type}}]{{go_define_type value_type}})
|
||||
for _, _ele_ := range _buf {
|
||||
if _v, err2 := {{go_deserialize_type value_type '_ele_'}}; err2 != nil {
|
||||
return nil, err2
|
||||
} else {
|
||||
_dataList = append(_dataList, _v)
|
||||
{{~if value_type.is_dynamic ~}}
|
||||
{{~for child in value_type.bean.hierarchy_not_abstract_children~}}
|
||||
if __v, __is := _v.(*{{child.go_full_name}}) ; __is {
|
||||
dataMap[__v.{{index_field.convention_name}}] = _v
|
||||
continue
|
||||
}
|
||||
{{~end~}}
|
||||
{{~else~}}
|
||||
dataMap[_v.{{index_field.convention_name}}] = _v
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
return &{{go_full_name}}{_dataList:_dataList, _dataMap:dataMap}, nil
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) GetDataMap() map[{{go_define_type key_type}}]{{go_define_type value_type}} {
|
||||
return table._dataMap
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) GetDataList() []{{go_define_type value_type}} {
|
||||
return table._dataList
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) Get(key {{go_define_type key_type}}) {{go_define_type value_type}} {
|
||||
return table._dataMap[key]
|
||||
}
|
||||
|
||||
|
||||
{{~else if x.is_list_table~}}
|
||||
type {{go_full_name}} struct {
|
||||
_dataList []{{go_define_type value_type}}
|
||||
}
|
||||
|
||||
func New{{go_full_name}}(_buf []map[string]interface{}) (*{{go_full_name}}, error) {
|
||||
_dataList := make([]{{go_define_type value_type}}, 0, len(_buf))
|
||||
for _, _ele_ := range _buf {
|
||||
if _v, err2 := {{go_deserialize_type value_type '_ele_'}}; err2 != nil {
|
||||
return nil, err2
|
||||
} else {
|
||||
_dataList = append(_dataList, _v)
|
||||
}
|
||||
}
|
||||
return &{{go_full_name}}{_dataList:_dataList}, nil
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) GetDataList() []{{go_define_type value_type}} {
|
||||
return table._dataList
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) Get(index int) {{go_define_type value_type}} {
|
||||
return table._dataList[index]
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
|
||||
import "errors"
|
||||
|
||||
type {{go_full_name}} struct {
|
||||
_data {{go_define_type value_type}}
|
||||
}
|
||||
|
||||
func New{{go_full_name}}(_buf []map[string]interface{}) (*{{go_full_name}}, error) {
|
||||
if len(_buf) != 1 {
|
||||
return nil, errors.New(" size != 1 ")
|
||||
} else {
|
||||
if _v, err2 := {{go_deserialize_type value_type '_buf[0]'}}; err2 != nil {
|
||||
return nil, err2
|
||||
} else {
|
||||
return &{{go_full_name}}{_data:_v}, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (table *{{go_full_name}}) Get() {{go_define_type value_type}} {
|
||||
return table._data
|
||||
}
|
||||
|
||||
{{~end~}}
|
31
Luban/Luban.ClientServer/Templates/config/go_json/tables.tpl
Normal file
31
Luban/Luban.ClientServer/Templates/config/go_json/tables.tpl
Normal file
@@ -0,0 +1,31 @@
|
||||
{{~
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
~}}
|
||||
|
||||
package {{namespace}}
|
||||
|
||||
type JsonLoader func(string) ([]map[string]interface{}, error)
|
||||
|
||||
type {{name}} struct {
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}} *{{table.go_full_name}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
func NewTables(loader JsonLoader) (*{{name}}, error) {
|
||||
var err error
|
||||
var buf []map[string]interface{}
|
||||
|
||||
tables := &{{name}}{}
|
||||
{{~for table in tables ~}}
|
||||
if buf, err = loader("{{table.output_data_file}}") ; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tables.{{table.name}}, err = New{{table.go_full_name}}(buf) ; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
{{~end~}}
|
||||
return tables, nil
|
||||
}
|
105
Luban/Luban.ClientServer/Templates/config/java_bin/bean.tpl
Normal file
105
Luban/Luban.ClientServer/Templates/config/java_bin/bean.tpl
Normal file
@@ -0,0 +1,105 @@
|
||||
package {{x.namespace_with_top_module}};
|
||||
|
||||
import bright.serialization.*;
|
||||
|
||||
{{
|
||||
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~}}
|
||||
public {{x.java_class_modifier}} class {{name}}{{if parent_def_type}} extends {{x.parent_def_type.full_name_with_top_module}}{{end}} {
|
||||
public {{name}}(ByteBuf _buf) {
|
||||
{{~if parent_def_type~}}
|
||||
super(_buf);
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{java_deserialize '_buf' field.convention_name field.ctype}}
|
||||
{{~if field.index_field~}}
|
||||
for({{java_box_define_type field.ctype.element_type}} _v : {{field.convention_name}}) {
|
||||
{{field.convention_name}}_Index.put(_v.{{field.index_field.convention_name}}, _v);
|
||||
}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public {{name}}({{- for field in hierarchy_export_fields }}{{java_define_type field.ctype}} {{field.name}}{{if !for.last}},{{end}} {{end}}) {
|
||||
{{~if parent_def_type~}}
|
||||
super({{ 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~}}
|
||||
for({{java_box_define_type field.ctype.element_type}} _v : {{field.convention_name}}) {
|
||||
{{field.convention_name}}_Index.put(_v.{{field.index_field.convention_name}}, _v);
|
||||
}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~if x.is_abstract_type~}}
|
||||
public static {{name}} deserialize{{name}}(ByteBuf _buf) {
|
||||
switch (_buf.readInt()) {
|
||||
{{~for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name_with_top_module}}.__ID__: return new {{child.full_name_with_top_module}}(_buf);
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
public final {{java_define_type field.ctype}} {{field.convention_name}};
|
||||
{{~if field.index_field~}}
|
||||
public final java.util.HashMap<{{java_box_define_type field.index_field.ctype}}, {{java_box_define_type field.ctype.element_type}}> {{field.convention_name}}_Index = new java.util.HashMap<>();
|
||||
{{~end~}}
|
||||
{{~if field.gen_ref~}}
|
||||
public {{field.java_ref_validator_define}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if !x.is_abstract_type && x.parent_def_type~}}
|
||||
public static final int __ID__ = {{x.id}};
|
||||
|
||||
@Override
|
||||
public int getTypeId() { return __ID__; }
|
||||
{{~else if x.is_abstract_type && !x.parent_def_type~}}
|
||||
public abstract int getTypeId();
|
||||
{{~end~}}
|
||||
|
||||
{{~if parent_def_type~}}
|
||||
@Override
|
||||
{{~end~}}
|
||||
public void resolve(java.util.HashMap<String, Object> _tables) {
|
||||
{{~if parent_def_type~}}
|
||||
super.resolve(_tables);
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{java_ref_validator_resolve field}}
|
||||
{{~else if field.has_recursive_ref~}}
|
||||
{{java_recursive_resolve field '_tables'}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{{full_name}}{ "
|
||||
{{~for field in hierarchy_export_fields ~}}
|
||||
+ "{{field.convention_name}}:" + {{java_to_string field.convention_name field.ctype}} + ","
|
||||
{{~end~}}
|
||||
+ "}";
|
||||
}
|
||||
}
|
97
Luban/Luban.ClientServer/Templates/config/java_bin/table.tpl
Normal file
97
Luban/Luban.ClientServer/Templates/config/java_bin/table.tpl
Normal file
@@ -0,0 +1,97 @@
|
||||
package {{x.namespace_with_top_module}};
|
||||
|
||||
import bright.serialization.*;
|
||||
|
||||
{{~
|
||||
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~}}
|
||||
public final class {{name}} {
|
||||
{{~if x.is_map_table ~}}
|
||||
private final java.util.HashMap<{{java_box_define_type key_type}}, {{java_box_define_type value_type}}> _dataMap;
|
||||
private final java.util.ArrayList<{{java_box_define_type value_type}}> _dataList;
|
||||
|
||||
public {{name}}(ByteBuf _buf) {
|
||||
_dataMap = new java.util.HashMap<{{java_box_define_type key_type}}, {{java_box_define_type value_type}}>();
|
||||
_dataList = new java.util.ArrayList<{{java_box_define_type value_type}}>();
|
||||
|
||||
for(int n = _buf.readSize() ; n > 0 ; --n) {
|
||||
{{java_box_define_type value_type}} _v;
|
||||
{{java_deserialize '_buf' '_v' value_type}}
|
||||
_dataList.add(_v);
|
||||
_dataMap.put(_v.{{x.index_field.convention_name}}, _v);
|
||||
}
|
||||
}
|
||||
|
||||
public java.util.HashMap<{{java_box_define_type key_type}}, {{java_box_define_type value_type}}> getDataMap() { return _dataMap; }
|
||||
public java.util.ArrayList<{{java_box_define_type value_type}}> getDataList() { return _dataList; }
|
||||
|
||||
{{~if value_type.is_dynamic~}}
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends {{java_box_define_type value_type}}> T getAs({{java_define_type key_type}} key) { return (T)_dataMap.get(key); }
|
||||
{{~end~}}
|
||||
public {{java_box_define_type value_type}} get({{java_define_type key_type}} key) { return _dataMap.get(key); }
|
||||
|
||||
public void resolve(java.util.HashMap<String, Object> _tables) {
|
||||
for({{java_box_define_type value_type}} v : _dataList) {
|
||||
v.resolve(_tables);
|
||||
}
|
||||
}
|
||||
{{~else if x.is_list_table ~}}
|
||||
private final java.util.ArrayList<{{java_box_define_type value_type}}> _dataList;
|
||||
|
||||
public {{name}}(ByteBuf _buf) {
|
||||
_dataList = new java.util.ArrayList<{{java_box_define_type value_type}}>();
|
||||
|
||||
for(int n = _buf.readSize() ; n > 0 ; --n) {
|
||||
{{java_box_define_type value_type}} _v;
|
||||
{{java_deserialize '_buf' '_v' value_type}}
|
||||
_dataList.add(_v);
|
||||
}
|
||||
}
|
||||
|
||||
public java.util.ArrayList<{{java_box_define_type value_type}}> getDataList() { return _dataList; }
|
||||
|
||||
public {{java_box_define_type value_type}} get(int index) { return _dataList.get(index); }
|
||||
|
||||
public void resolve(java.util.HashMap<String, Object> _tables) {
|
||||
for({{java_box_define_type value_type}} v : _dataList) {
|
||||
v.resolve(_tables);
|
||||
}
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
private final {{java_define_type value_type}} _data;
|
||||
|
||||
public final {{java_define_type value_type}} data() { return _data; }
|
||||
|
||||
public {{name}}(ByteBuf _buf) {
|
||||
int n = _buf.readSize();
|
||||
if (n != 1) throw new SerializationException("table mode=one, but size != 1");
|
||||
{{java_deserialize '_buf' '_data' value_type}}
|
||||
}
|
||||
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
public {{java_define_type field.ctype}} {{field.convention_getter_name}}() { return _data.{{field.convention_name}}; }
|
||||
{{~end~}}
|
||||
|
||||
public void resolve(java.util.HashMap<String, Object> _tables) {
|
||||
_data.resolve(_tables);
|
||||
}
|
||||
{{~end~}}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
{{~
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
~}}
|
||||
package {{namespace}};
|
||||
|
||||
import bright.serialization.*;
|
||||
|
||||
public final class {{name}}
|
||||
{
|
||||
public static interface IByteBufLoader {
|
||||
ByteBuf load(String file) throws java.io.IOException;
|
||||
}
|
||||
|
||||
{{~for table in tables ~}}
|
||||
{{~if table.comment != '' ~}}
|
||||
/**
|
||||
* {{table.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
private final {{table.full_name_with_top_module}} {{table.inner_name}};
|
||||
public {{table.full_name_with_top_module}} get{{table.name}}() { return {{table.inner_name}}; }
|
||||
{{~end~}}
|
||||
|
||||
public {{name}}(IByteBufLoader loader) throws java.io.IOException {
|
||||
java.util.HashMap<String, Object> tables = new java.util.HashMap<>();
|
||||
{{~for table in tables ~}}
|
||||
{{table.inner_name}} = new {{table.full_name_with_top_module}}(loader.load("{{table.output_data_file}}"));
|
||||
tables.put("{{table.full_name}}", {{table.inner_name}});
|
||||
{{~end~}}
|
||||
|
||||
{{~ for table in tables ~}}
|
||||
{{table.inner_name}}.resolve(tables);
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
108
Luban/Luban.ClientServer/Templates/config/java_json/bean.tpl
Normal file
108
Luban/Luban.ClientServer/Templates/config/java_json/bean.tpl
Normal file
@@ -0,0 +1,108 @@
|
||||
package {{x.namespace_with_top_module}};
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
{{
|
||||
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~}}
|
||||
public {{x.java_class_modifier}} class {{name}}{{if parent_def_type}} extends {{x.parent_def_type.full_name_with_top_module}}{{end}} {
|
||||
public {{name}}(JsonObject __json__) {
|
||||
{{~if parent_def_type~}}
|
||||
super(__json__);
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{java_json_deserialize '__json__' field.convention_name field.name field.ctype}}
|
||||
{{~if field.index_field~}}
|
||||
for({{java_box_define_type field.ctype.element_type}} _v : {{field.convention_name}}) {
|
||||
{{field.convention_name}}_Index.put(_v.{{field.index_field.convention_name}}, _v);
|
||||
}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public {{name}}({{- for field in hierarchy_export_fields }}{{java_define_type field.ctype}} {{field.name}}{{if !for.last}},{{end}} {{end}}) {
|
||||
{{~if parent_def_type~}}
|
||||
super({{ 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~}}
|
||||
for({{java_box_define_type field.ctype.element_type}} _v : {{field.convention_name}}) {
|
||||
{{field.convention_name}}_Index.put(_v.{{field.index_field.convention_name}}, _v);
|
||||
}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public static {{name}} deserialize{{name}}(JsonObject __json__) {
|
||||
{{~if x.is_abstract_type~}}
|
||||
switch (__json__.get("{{x.json_type_name_key}}").getAsString()) {
|
||||
{{~for child in x.hierarchy_not_abstract_children~}}
|
||||
case "{{cs_impl_data_type child x}}": return new {{child.full_name_with_top_module}}(__json__);
|
||||
{{~end~}}
|
||||
default: throw new bright.serialization.SerializationException();
|
||||
}
|
||||
{{~else~}}
|
||||
return new {{name}}(__json__);
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
public final {{java_define_type field.ctype}} {{field.convention_name}};
|
||||
{{~if field.index_field~}}
|
||||
public final java.util.HashMap<{{java_box_define_type field.index_field.ctype}}, {{java_box_define_type field.ctype.element_type}}> {{field.convention_name}}_Index = new java.util.HashMap<>();
|
||||
{{~end~}}
|
||||
{{~if field.gen_ref~}}
|
||||
public {{field.java_ref_validator_define}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if !x.is_abstract_type && x.parent_def_type~}}
|
||||
public static final int __ID__ = {{x.id}};
|
||||
|
||||
@Override
|
||||
public int getTypeId() { return __ID__; }
|
||||
{{~else if x.is_abstract_type && !x.parent_def_type~}}
|
||||
public abstract int getTypeId();
|
||||
{{~end~}}
|
||||
|
||||
{{~if parent_def_type~}}
|
||||
@Override
|
||||
{{~end~}}
|
||||
public void resolve(java.util.HashMap<String, Object> _tables) {
|
||||
{{~if parent_def_type~}}
|
||||
super.resolve(_tables);
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{java_ref_validator_resolve field}}
|
||||
{{~else if field.has_recursive_ref~}}
|
||||
{{java_recursive_resolve field '_tables'}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{{full_name}}{ "
|
||||
{{~for field in hierarchy_export_fields ~}}
|
||||
+ "{{field.convention_name}}:" + {{java_to_string field.convention_name field.ctype}} + ","
|
||||
{{~end~}}
|
||||
+ "}";
|
||||
}
|
||||
}
|
@@ -0,0 +1,99 @@
|
||||
package {{x.namespace_with_top_module}};
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
{{~
|
||||
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~}}
|
||||
public final class {{name}} {
|
||||
{{~if x.is_map_table ~}}
|
||||
private final java.util.HashMap<{{java_box_define_type key_type}}, {{java_box_define_type value_type}}> _dataMap;
|
||||
private final java.util.ArrayList<{{java_box_define_type value_type}}> _dataList;
|
||||
|
||||
public {{name}}(JsonElement __json__) {
|
||||
_dataMap = new java.util.HashMap<{{java_box_define_type key_type}}, {{java_box_define_type value_type}}>();
|
||||
_dataList = new java.util.ArrayList<{{java_box_define_type value_type}}>();
|
||||
|
||||
for(com.google.gson.JsonElement _e_ : __json__.getAsJsonArray()) {
|
||||
{{java_box_define_type value_type}} _v;
|
||||
{{java_deserialize '_e_.getAsJsonObject()' '_v' value_type}}
|
||||
_dataList.add(_v);
|
||||
_dataMap.put(_v.{{x.index_field.convention_name}}, _v);
|
||||
}
|
||||
}
|
||||
|
||||
public java.util.HashMap<{{java_box_define_type key_type}}, {{java_box_define_type value_type}}> getDataMap() { return _dataMap; }
|
||||
public java.util.ArrayList<{{java_box_define_type value_type}}> getDataList() { return _dataList; }
|
||||
|
||||
{{~if value_type.is_dynamic~}}
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends {{java_box_define_type value_type}}> T getAs({{java_define_type key_type}} key) { return (T)_dataMap.get(key); }
|
||||
{{~end~}}
|
||||
public {{java_box_define_type value_type}} get({{java_define_type key_type}} key) { return _dataMap.get(key); }
|
||||
|
||||
public void resolve(java.util.HashMap<String, Object> _tables) {
|
||||
for({{java_box_define_type value_type}} v : _dataList) {
|
||||
v.resolve(_tables);
|
||||
}
|
||||
}
|
||||
|
||||
{{~else if x.is_list_table ~}}
|
||||
private final java.util.ArrayList<{{java_box_define_type value_type}}> _dataList;
|
||||
|
||||
public {{name}}(JsonElement __json__) {
|
||||
_dataList = new java.util.ArrayList<{{java_box_define_type value_type}}>();
|
||||
|
||||
for(com.google.gson.JsonElement _e_ : __json__.getAsJsonArray()) {
|
||||
{{java_box_define_type value_type}} _v;
|
||||
{{java_deserialize '_e_.getAsJsonObject()' '_v' value_type}}
|
||||
_dataList.add(_v);
|
||||
}
|
||||
}
|
||||
|
||||
public java.util.ArrayList<{{java_box_define_type value_type}}> getDataList() { return _dataList; }
|
||||
|
||||
public {{java_box_define_type value_type}} get(int index) { return _dataList.get(index); }
|
||||
|
||||
public void resolve(java.util.HashMap<String, Object> _tables) {
|
||||
for({{java_box_define_type value_type}} v : _dataList) {
|
||||
v.resolve(_tables);
|
||||
}
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
private final {{java_define_type value_type}} _data;
|
||||
|
||||
public final {{java_define_type value_type}} data() { return _data; }
|
||||
|
||||
public {{name}}(JsonElement __json__) {
|
||||
int n = __json__.getAsJsonArray().size();
|
||||
if (n != 1) throw new bright.serialization.SerializationException("table mode=one, but size != 1");
|
||||
{{java_deserialize '__json__.getAsJsonArray().get(0).getAsJsonObject()' '_data' value_type}}
|
||||
}
|
||||
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
public {{java_define_type field.ctype}} {{field.convention_getter_name}}() { return _data.{{field.convention_name}}; }
|
||||
{{~end~}}
|
||||
|
||||
public void resolve(java.util.HashMap<String, Object> _tables) {
|
||||
_data.resolve(_tables);
|
||||
}
|
||||
|
||||
{{~end~}}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
{{~
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
~}}
|
||||
package {{namespace}};
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
public final class {{name}}
|
||||
{
|
||||
public interface IJsonLoader {
|
||||
JsonElement load(String file) throws java.io.IOException;
|
||||
}
|
||||
|
||||
{{~for table in tables ~}}
|
||||
{{~if table.comment != '' ~}}
|
||||
/**
|
||||
* {{table.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
private final {{table.full_name_with_top_module}} {{table.inner_name}};
|
||||
public {{table.full_name_with_top_module}} get{{table.name}}() { return {{table.inner_name}}; }
|
||||
{{~end~}}
|
||||
|
||||
public {{name}}(IJsonLoader loader) throws java.io.IOException {
|
||||
java.util.HashMap<String, Object> tables = new java.util.HashMap<>();
|
||||
{{~for table in tables ~}}
|
||||
{{table.inner_name}} = new {{table.full_name_with_top_module}}(loader.load("{{table.output_data_file}}"));
|
||||
tables.put("{{table.full_name}}", {{table.inner_name}});
|
||||
{{~end~}}
|
||||
|
||||
{{~ for table in tables ~}}
|
||||
{{table.inner_name}}.resolve(tables);
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
128
Luban/Luban.ClientServer/Templates/config/lua_bin/all.tpl
Normal file
128
Luban/Luban.ClientServer/Templates/config/lua_bin/all.tpl
Normal file
@@ -0,0 +1,128 @@
|
||||
|
||||
local enums =
|
||||
{
|
||||
{{~ for c in enums ~}}
|
||||
---@class {{c.full_name}}
|
||||
{{~ for item in c.items ~}}
|
||||
---@field public {{item.name}} integer
|
||||
{{~end~}}
|
||||
['{{c.full_name}}'] = { {{ for item in c.items }} {{item.name}}={{item.int_value}}, {{end}} };
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
|
||||
local function InitTypes(methods)
|
||||
local readBool = methods.readBool
|
||||
local readByte = methods.readByte
|
||||
local readShort = methods.readShort
|
||||
local readFshort = methods.readFshort
|
||||
local readInt = methods.readInt
|
||||
local readFint = methods.readFint
|
||||
local readLong = methods.readLong
|
||||
local readFlong = methods.readFlong
|
||||
local readFloat = methods.readFloat
|
||||
local readDouble = methods.readDouble
|
||||
local readSize = methods.readSize
|
||||
|
||||
local readString = methods.readString
|
||||
|
||||
local function readVector2(bs)
|
||||
return { x = readFloat(bs), y = readFloat(bs) }
|
||||
end
|
||||
|
||||
local function readVector3(bs)
|
||||
return { x = readFloat(bs), y = readFloat(bs), z = readFloat(bs) }
|
||||
end
|
||||
|
||||
local function readVector4(bs)
|
||||
return { x = readFloat(bs), y = readFloat(bs), z = readFloat(bs), w = readFloat(bs) }
|
||||
end
|
||||
|
||||
local function readList(bs, keyFun)
|
||||
local list = {}
|
||||
local v
|
||||
for i = 1, readSize(bs) do
|
||||
tinsert(list, keyFun(bs))
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
local readArray = readList
|
||||
|
||||
local function readSet(bs, keyFun)
|
||||
local set = {}
|
||||
local v
|
||||
for i = 1, readSize(bs) do
|
||||
tinsert(set, keyFun(bs))
|
||||
end
|
||||
return set
|
||||
end
|
||||
|
||||
local function readMap(bs, keyFun, valueFun)
|
||||
local map = {}
|
||||
for i = 1, readSize(bs) do
|
||||
local k = keyFun(bs)
|
||||
local v = valueFun(bs)
|
||||
map[k] = v
|
||||
end
|
||||
return map
|
||||
end
|
||||
|
||||
local function readNullableBool(bs)
|
||||
if readBool(bs) then
|
||||
return readBool(bs)
|
||||
end
|
||||
end
|
||||
|
||||
local beans = {}
|
||||
{{~ for bean in beans ~}}
|
||||
do
|
||||
---@class {{bean.full_name}} {{if bean.parent_def_type}}:{{bean.parent}} {{end}}
|
||||
{{~ for field in bean.export_fields~}}
|
||||
---@field public {{field.name}} {{lua_comment_type field.ctype}}
|
||||
{{~end~}}
|
||||
local class = SimpleClass()
|
||||
class._id = {{bean.id}}
|
||||
class['{{bean.lua_type_name_key}}'] = '{{bean.full_name}}'
|
||||
local id2name = { {{for c in bean.hierarchy_not_abstract_children}} [{{c.id}}] = '{{c.full_name}}', {{end}} }
|
||||
{{~if bean.is_abstract_type~}}
|
||||
class._deserialize = function(bs)
|
||||
local id = readInt(bs)
|
||||
return beans[id2name[id]]._deserialize(bs)
|
||||
end
|
||||
{{~else~}}
|
||||
class._deserialize = function(bs)
|
||||
local o = {
|
||||
{{~ for field in bean.hierarchy_export_fields ~}}
|
||||
{{~if !(need_marshal_bool_prefix field.ctype)~}}
|
||||
{{field.convention_name}} = {{lua_undering_deserialize 'bs' field.ctype}},
|
||||
{{~else~}}
|
||||
{{field.convention_name}} = {{if !field.ctype.is_bool}}readBool(bs) and {{lua_undering_deserialize 'bs' field.ctype}} or nil {{-else-}} readNullableBool(bs) {{-end-}},
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
setmetatable(o, class)
|
||||
return o
|
||||
end
|
||||
{{~end~}}
|
||||
beans[class['{{bean.lua_type_name_key}}']] = class
|
||||
end
|
||||
{{~end~}}
|
||||
|
||||
local tables =
|
||||
{
|
||||
{{~for table in tables ~}}
|
||||
{{~if table.is_map_table ~}}
|
||||
{ name='{{table.name}}', file='{{table.output_data_file}}', mode='map', index='{{table.index}}', value_type='{{table.value_ttype.bean.full_name}}' },
|
||||
{{~else if table.is_list_table ~}}
|
||||
{ name='{{table.name}}', file='{{table.output_data_file}}', mode='list', index='{{table.index}}', value_type='{{table.value_ttype.bean.full_name}}' },
|
||||
{{~else~}}
|
||||
{ name='{{table.name}}', file='{{table.output_data_file}}', mode='one', value_type='{{table.value_ttype.bean.full_name}}'},
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
return { enums = enums, beans = beans, tables = tables }
|
||||
end
|
||||
|
||||
return { InitTypes = InitTypes }
|
||||
|
62
Luban/Luban.ClientServer/Templates/config/lua_bin/method.tpl
Normal file
62
Luban/Luban.ClientServer/Templates/config/lua_bin/method.tpl
Normal file
@@ -0,0 +1,62 @@
|
||||
local function InitTypes(methods)
|
||||
local readBool = methods.readBool
|
||||
local readByte = methods.readByte
|
||||
local readShort = methods.readShort
|
||||
local readFshort = methods.readFshort
|
||||
local readInt = methods.readInt
|
||||
local readFint = methods.readFint
|
||||
local readLong = methods.readLong
|
||||
local readFlong = methods.readFlong
|
||||
local readFloat = methods.readFloat
|
||||
local readDouble = methods.readDouble
|
||||
local readSize = methods.readSize
|
||||
|
||||
local readString = methods.readString
|
||||
|
||||
local function readVector2(bs)
|
||||
return { x = readFloat(bs), y = readFloat(bs) }
|
||||
end
|
||||
|
||||
local function readVector3(bs)
|
||||
return { x = readFloat(bs), y = readFloat(bs), z = readFloat(bs) }
|
||||
end
|
||||
|
||||
local function readVector4(bs)
|
||||
return { x = readFloat(bs), y = readFloat(bs), z = readFloat(bs), w = readFloat(bs) }
|
||||
end
|
||||
|
||||
local function readList(bs, keyFun)
|
||||
local list = {}
|
||||
local v
|
||||
for i = 1, readSize(bs) do
|
||||
tinsert(list, keyFun(bs))
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
local readArray = readList
|
||||
|
||||
local function readSet(bs, keyFun)
|
||||
local set = {}
|
||||
local v
|
||||
for i = 1, readSize(bs) do
|
||||
tinsert(set, keyFun(bs))
|
||||
end
|
||||
return set
|
||||
end
|
||||
|
||||
local function readMap(bs, keyFun, valueFun)
|
||||
local map = {}
|
||||
for i = 1, readSize(bs) do
|
||||
local k = keyFun(bs)
|
||||
local v = valueFun(bs)
|
||||
map[k] = v
|
||||
end
|
||||
return map
|
||||
end
|
||||
|
||||
local function readNullableBool(bs)
|
||||
if readBool(bs) then
|
||||
return readBool(bs)
|
||||
end
|
||||
end
|
25
Luban/Luban.ClientServer/Templates/config/lua_lua/all.tpl
Normal file
25
Luban/Luban.ClientServer/Templates/config/lua_lua/all.tpl
Normal file
@@ -0,0 +1,25 @@
|
||||
local enums =
|
||||
{
|
||||
{{~ for c in enums ~}}
|
||||
---@class {{c.full_name}}
|
||||
{{~ for item in c.items ~}}
|
||||
---@field public {{item.name}} integer
|
||||
{{~end~}}
|
||||
['{{c.full_name}}'] = { {{ for item in c.items }} {{item.name}}={{item.int_value}}, {{end}} };
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
local tables =
|
||||
{
|
||||
{{~for table in tables ~}}
|
||||
{{~if table.is_map_table ~}}
|
||||
{ name='{{table.name}}', file='{{table.output_data_file}}', mode='map', index='{{table.index}}', value_type='{{table.value_ttype.bean.full_name}}' },
|
||||
{{~else if table.is_list_table ~}}
|
||||
{ name='{{table.name}}', file='{{table.output_data_file}}', mode='list', index='{{table.index}}', value_type='{{table.value_ttype.bean.full_name}}' },
|
||||
{{~else~}}
|
||||
{ name='{{table.name}}', file='{{table.output_data_file}}', mode='one', value_type='{{table.value_ttype.bean.full_name}}'},
|
||||
{{end}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
return { enums = enums, tables = tables }
|
36
Luban/Luban.ClientServer/Templates/config/protobuf2/all.tpl
Normal file
36
Luban/Luban.ClientServer/Templates/config/protobuf2/all.tpl
Normal file
@@ -0,0 +1,36 @@
|
||||
syntax = "proto2";
|
||||
|
||||
package {{x.namespace}};
|
||||
|
||||
// luban internal types begin
|
||||
message Vector2 {
|
||||
required float x = 1;
|
||||
required float y = 2;
|
||||
}
|
||||
|
||||
message Vector3 {
|
||||
required float x = 1;
|
||||
required float y = 2;
|
||||
required float z = 3;
|
||||
}
|
||||
|
||||
message Vector4 {
|
||||
required float x = 1;
|
||||
required float y = 2;
|
||||
required float z = 3;
|
||||
required float w = 4;
|
||||
}
|
||||
// luban internal types end
|
||||
|
||||
{{~for enum in x.enums ~}}
|
||||
{{enum}}
|
||||
{{~end~}}
|
||||
|
||||
{{~for bean in x.beans~}}
|
||||
{{bean}}
|
||||
{{~end~}}
|
||||
|
||||
{{~for table in x.tables~}}
|
||||
{{table}}
|
||||
{{~end~}}
|
||||
|
20
Luban/Luban.ClientServer/Templates/config/protobuf2/bean.tpl
Normal file
20
Luban/Luban.ClientServer/Templates/config/protobuf2/bean.tpl
Normal 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
|
||||
~}}
|
||||
|
||||
message {{x.pb_full_name}} {
|
||||
{{~if x.is_abstract_type ~}}
|
||||
oneof value {
|
||||
{{~for c in x.hierarchy_not_abstract_children~}}
|
||||
{{c.pb_full_name}} {{c.name}} = {{c.auto_id}};
|
||||
{{~end~}}
|
||||
}
|
||||
{{~else~}}
|
||||
{{~for f in hierarchy_export_fields ~}}
|
||||
{{protobuf_pre_decorator f.ctype}} {{protobuf_define_type f.ctype}} {{f.name}} = {{f.auto_id}} {{protobuf_suffix_options f.ctype}};
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
{{~
|
||||
name = x.name
|
||||
key_type = x.key_ttype
|
||||
value_type = x.value_ttype
|
||||
~}}
|
||||
|
||||
message {{x.pb_full_name}} {
|
||||
repeated {{protobuf_define_type value_type}} data_list = 1 [packed = false];
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
{{~
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
~}}
|
36
Luban/Luban.ClientServer/Templates/config/protobuf3/all.tpl
Normal file
36
Luban/Luban.ClientServer/Templates/config/protobuf3/all.tpl
Normal file
@@ -0,0 +1,36 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package {{x.namespace}};
|
||||
|
||||
// luban internal types begin
|
||||
message Vector2 {
|
||||
float x = 1;
|
||||
float y = 2;
|
||||
}
|
||||
|
||||
message Vector3 {
|
||||
float x = 1;
|
||||
float y = 2;
|
||||
float z = 3;
|
||||
}
|
||||
|
||||
message Vector4 {
|
||||
float x = 1;
|
||||
float y = 2;
|
||||
float z = 3;
|
||||
float w = 4;
|
||||
}
|
||||
// luban internal types end
|
||||
|
||||
{{~for enum in x.enums ~}}
|
||||
{{enum}}
|
||||
{{~end~}}
|
||||
|
||||
{{~for bean in x.beans~}}
|
||||
{{bean}}
|
||||
{{~end~}}
|
||||
|
||||
{{~for table in x.tables~}}
|
||||
{{table}}
|
||||
{{~end~}}
|
||||
|
20
Luban/Luban.ClientServer/Templates/config/protobuf3/bean.tpl
Normal file
20
Luban/Luban.ClientServer/Templates/config/protobuf3/bean.tpl
Normal 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
|
||||
~}}
|
||||
|
||||
message {{x.pb_full_name}} {
|
||||
{{~if x.is_abstract_type ~}}
|
||||
oneof value {
|
||||
{{~for c in x.hierarchy_not_abstract_children~}}
|
||||
{{c.pb_full_name}} {{c.name}} = {{c.auto_id}};
|
||||
{{~end~}}
|
||||
}
|
||||
{{~else~}}
|
||||
{{~for f in hierarchy_export_fields ~}}
|
||||
{{protobuf3_pre_decorator f.ctype}} {{protobuf_define_type f.ctype}} {{f.name}} = {{f.auto_id}} {{protobuf_suffix_options f.ctype}};
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
{{~
|
||||
name = x.name
|
||||
key_type = x.key_ttype
|
||||
value_type = x.value_ttype
|
||||
~}}
|
||||
|
||||
message {{x.pb_full_name}} {
|
||||
repeated {{protobuf_define_type value_type}} data_list = 1 [packed = false];
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
{{~
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
~}}
|
@@ -0,0 +1,40 @@
|
||||
|
||||
{{
|
||||
name = x.py_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}}({{parent_def_type.py_full_name}}){{end}}:
|
||||
{{~if x.is_abstract_type~}}
|
||||
_childrenTypes = None
|
||||
|
||||
@staticmethod
|
||||
def fromJson(_json_):
|
||||
childrenTypes = {{name}}._childrenTypes
|
||||
if not childrenTypes:
|
||||
childrenTypes = {{name}}._childrenTypes = {
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
'{{cs_impl_data_type child x}}': {{child.py_full_name}},
|
||||
{{~end~}}
|
||||
}
|
||||
type = _json_['{{x.json_type_name_key}}']
|
||||
child = {{name}}._childrenTypes.get(type)
|
||||
if child != None:
|
||||
return child(_json_)
|
||||
else:
|
||||
raise Exception()
|
||||
{{~end~}}
|
||||
|
||||
def __init__(self, _json_):
|
||||
{{~if parent_def_type~}}
|
||||
{{parent_def_type.py_full_name}}.__init__(self, _json_)
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{py3_deserialize_field ('self.' + field.convention_name) '_json_' field.name field.ctype}}
|
||||
{{~end~}}
|
||||
{{~if export_fields.empty?}}
|
||||
pass
|
||||
{{~end~}}
|
@@ -0,0 +1,54 @@
|
||||
from enum import Enum
|
||||
import abc
|
||||
|
||||
class Vector2:
|
||||
def __init__(self, x, y):
|
||||
self.x = x
|
||||
self.y = y
|
||||
def __str__(self):
|
||||
return '{%g,%g}' % (self.x, self.y)
|
||||
|
||||
@staticmethod
|
||||
def fromJson(_json_):
|
||||
x = _json_['x']
|
||||
y = _json_['y']
|
||||
if (x == None or y == None):
|
||||
raise Exception()
|
||||
return Vector2(x, y)
|
||||
|
||||
|
||||
class Vector3:
|
||||
def __init__(self, x, y, z):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.z = z
|
||||
def __str__(self):
|
||||
return '{%f,%f,%f}' % (self.x, self.y, self.z)
|
||||
@staticmethod
|
||||
def fromJson(_json_):
|
||||
x = _json_['x']
|
||||
y = _json_['y']
|
||||
z = _json_['z']
|
||||
if (x == None or y == None or z == None):
|
||||
raise Exception()
|
||||
return Vector3(x, y, z)
|
||||
|
||||
class Vector4:
|
||||
def __init__(self, x, y, z, w):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.z = z
|
||||
self.w = w
|
||||
def __str__(self):
|
||||
return '{%g,%g,%g,%g}' % (self.x, self.y, self.z, self.w)
|
||||
|
||||
@staticmethod
|
||||
def fromJson(_json_):
|
||||
x = _json_['x']
|
||||
y = _json_['y']
|
||||
z = _json_['z']
|
||||
w = _json_['w']
|
||||
if (x == None or y == None or z == None or w == None):
|
||||
raise Exception()
|
||||
return Vector4(x, y, z, w)
|
||||
|
@@ -0,0 +1,54 @@
|
||||
{{
|
||||
name = x.py_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 ~}}
|
||||
|
||||
def __init__(self, _json_ ):
|
||||
self._dataMap = {}
|
||||
self._dataList = []
|
||||
|
||||
for _json2_ in _json_:
|
||||
{{py3_deserialize_value '_v' '_json2_' value_type}}
|
||||
self._dataList.append(_v)
|
||||
self._dataMap[_v.{{x.index_field.convention_name}}] = _v
|
||||
|
||||
def getDataMap(self) : return self._dataMap
|
||||
def getDataList(self) : return self._dataList
|
||||
|
||||
def get(self, key) : return self._dataMap.get(key)
|
||||
{{~else if x.is_list_table ~}}
|
||||
|
||||
def __init__(self, _json_ ):
|
||||
self._dataList = []
|
||||
|
||||
for _json2_ in _json_:
|
||||
{{py3_deserialize_value '_v' '_json2_' value_type}}
|
||||
self._dataList.append(_v)
|
||||
|
||||
def getDataList(self) : return self._dataList
|
||||
|
||||
def get(self, index) : return self._dataList[index]
|
||||
|
||||
{{~else~}}
|
||||
|
||||
def __init__(self, _json_):
|
||||
if (len(_json_) != 1): raise Exception('table mode=one, but size != 1')
|
||||
{{py3_deserialize_value 'self._data' '_json_[0]' value_type}}
|
||||
|
||||
def getData(self) : return self._data
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
'''
|
||||
{{field.escape_comment}}
|
||||
'''
|
||||
{{~end~}}
|
||||
def {{field.convention_name}}(self) : return self._data.{{field.convention_name}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
@@ -0,0 +1,15 @@
|
||||
{{
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
}}
|
||||
|
||||
class {{name}}:
|
||||
{{~ for table in tables ~}}
|
||||
#def {{table.name}} : return self._{{table.name}}
|
||||
{{~end~}}
|
||||
|
||||
def __init__(self, loader):
|
||||
{{~for table in tables ~}}
|
||||
self.{{table.name}} = {{table.py_full_name}}(loader('{{table.output_data_file}}'));
|
||||
{{~end~}}
|
@@ -0,0 +1,40 @@
|
||||
|
||||
{{
|
||||
name = x.py_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}}({{parent_def_type.py_full_name}}){{else if is_abstract_type}}(metaclass=abc.ABCMeta){{end}}:
|
||||
{{~if x.is_abstract_type~}}
|
||||
_childrenTypes = None
|
||||
|
||||
@staticmethod
|
||||
def fromJson(_json_):
|
||||
childrenTypes = {{name}}._childrenTypes
|
||||
if not childrenTypes:
|
||||
childrenTypes = {{name}}._childrenTypes = {
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
'{{cs_impl_data_type child x}}': {{child.py_full_name}},
|
||||
{{~end~}}
|
||||
}
|
||||
type = _json_['{{x.json_type_name_key}}']
|
||||
child = {{name}}._childrenTypes.get(type)
|
||||
if child != None:
|
||||
return child(_json_)
|
||||
else:
|
||||
raise Exception()
|
||||
{{~end~}}
|
||||
|
||||
def __init__(self, _json_):
|
||||
{{~if parent_def_type~}}
|
||||
{{parent_def_type.py_full_name}}.__init__(self, _json_)
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{py3_deserialize_field ('self.' + field.convention_name) '_json_' field.name field.ctype}}
|
||||
{{~end~}}
|
||||
{{~if export_fields.empty?}}
|
||||
pass
|
||||
{{~end~}}
|
@@ -0,0 +1,54 @@
|
||||
from enum import Enum
|
||||
import abc
|
||||
|
||||
class Vector2:
|
||||
def __init__(self, x, y):
|
||||
self.x = x
|
||||
self.y = y
|
||||
def __str__(self):
|
||||
return '{%g,%g}' % (self.x, self.y)
|
||||
|
||||
@staticmethod
|
||||
def fromJson(_json_):
|
||||
x = _json_['x']
|
||||
y = _json_['y']
|
||||
if (x == None or y == None):
|
||||
raise Exception()
|
||||
return Vector2(x, y)
|
||||
|
||||
|
||||
class Vector3:
|
||||
def __init__(self, x, y, z):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.z = z
|
||||
def __str__(self):
|
||||
return '{%f,%f,%f}' % (self.x, self.y, self.z)
|
||||
@staticmethod
|
||||
def fromJson(_json_):
|
||||
x = _json_['x']
|
||||
y = _json_['y']
|
||||
z = _json_['z']
|
||||
if (x == None or y == None or z == None):
|
||||
raise Exception()
|
||||
return Vector3(x, y, z)
|
||||
|
||||
class Vector4:
|
||||
def __init__(self, x, y, z, w):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.z = z
|
||||
self.w = w
|
||||
def __str__(self):
|
||||
return '{%g,%g,%g,%g}' % (self.x, self.y, self.z, self.w)
|
||||
|
||||
@staticmethod
|
||||
def fromJson(_json_):
|
||||
x = _json_['x']
|
||||
y = _json_['y']
|
||||
z = _json_['z']
|
||||
w = _json_['w']
|
||||
if (x == None or y == None or z == None or w == None):
|
||||
raise Exception()
|
||||
return Vector4(x, y, z, w)
|
||||
|
@@ -0,0 +1,54 @@
|
||||
{{
|
||||
name = x.py_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 ~}}
|
||||
|
||||
def __init__(self, _json_ ):
|
||||
self._dataMap = {}
|
||||
self._dataList = []
|
||||
|
||||
for _json2_ in _json_:
|
||||
{{py3_deserialize_value '_v' '_json2_' value_type}}
|
||||
self._dataList.append(_v)
|
||||
self._dataMap[_v.{{x.index_field.convention_name}}] = _v
|
||||
|
||||
def getDataMap(self) : return self._dataMap
|
||||
def getDataList(self) : return self._dataList
|
||||
|
||||
def get(self, key) : return self._dataMap.get(key)
|
||||
{{~else if x.is_list_table ~}}
|
||||
|
||||
def __init__(self, _json_ ):
|
||||
self._dataList = []
|
||||
|
||||
for _json2_ in _json_:
|
||||
{{py3_deserialize_value '_v' '_json2_' value_type}}
|
||||
self._dataList.append(_v)
|
||||
|
||||
def getDataList(self) : return self._dataList
|
||||
|
||||
def get(self, index) : return self._dataList[index]
|
||||
|
||||
{{~else~}}
|
||||
|
||||
def __init__(self, _json_):
|
||||
if (len(_json_) != 1): raise Exception('table mode=one, but size != 1')
|
||||
{{py3_deserialize_value 'self._data' '_json_[0]' value_type}}
|
||||
|
||||
def getData(self) : return self._data
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
'''
|
||||
{{field.escape_comment}}
|
||||
'''
|
||||
{{~end~}}
|
||||
def {{field.convention_name}}(self) : return self._data.{{field.convention_name}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
@@ -0,0 +1,15 @@
|
||||
{{
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
}}
|
||||
|
||||
class {{name}}:
|
||||
{{~ for table in tables ~}}
|
||||
#def {{table.name}} : return self._{{table.name}}
|
||||
{{~end~}}
|
||||
|
||||
def __init__(self, loader):
|
||||
{{~for table in tables ~}}
|
||||
self.{{table.name}} = {{table.py_full_name}}(loader('{{table.output_data_file}}'));
|
||||
{{~end~}}
|
56
Luban/Luban.ClientServer/Templates/config/rust_json/bean.tpl
Normal file
56
Luban/Luban.ClientServer/Templates/config/rust_json/bean.tpl
Normal file
@@ -0,0 +1,56 @@
|
||||
|
||||
{{
|
||||
name = x.rust_full_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~}}
|
||||
{{~if !x.is_abstract_type~}}
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct {{name}} {
|
||||
{{~for field in hierarchy_export_fields~}}
|
||||
pub {{field.convention_name}}: {{rust_define_type field.ctype}},
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
impl {{name}} {
|
||||
#[allow(dead_code)]
|
||||
pub fn new(__js: &json::JsonValue) -> Result<{{name}}, LoadError> {
|
||||
let __b = {{name}} {
|
||||
{{~for field in hierarchy_export_fields~}}
|
||||
{{field.convention_name}}: {{rust_json_constructor ('__js["' + field.name + '"]') field.ctype}},
|
||||
{{~end~}}
|
||||
};
|
||||
Ok(__b)
|
||||
}
|
||||
}
|
||||
{{~else~}}
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum {{name}} {
|
||||
{{~for child in x.hierarchy_not_abstract_children~}}
|
||||
{{child.name}}(Box<{{child.rust_full_name}}>),
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
impl {{name}} {
|
||||
#[allow(dead_code)]
|
||||
pub fn new(__js: &json::JsonValue) -> Result<{{name}}, LoadError> {
|
||||
let __b = match __js["{{x.json_type_name_key}}"].as_str() {
|
||||
Some(type_name) => match type_name {
|
||||
{{~for child in x.hierarchy_not_abstract_children~}}
|
||||
"{{cs_impl_data_type child x}}" => {{name}}::{{child.name}}(Box::new({{child.rust_full_name + '::new(&__js)?'}})),
|
||||
{{~end~}}
|
||||
_ => return Err(LoadError{})
|
||||
},
|
||||
None => return Err(LoadError{})
|
||||
};
|
||||
Ok(__b)
|
||||
}
|
||||
}
|
||||
{{~end~}}
|
@@ -0,0 +1,59 @@
|
||||
pub struct LoadError {
|
||||
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for LoadError {
|
||||
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> { Ok(()) }
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct Vector2 {
|
||||
pub x:f32,
|
||||
pub y:f32,
|
||||
}
|
||||
|
||||
impl Vector2 {
|
||||
pub fn new(__js:&json::JsonValue) -> Result<Vector2, LoadError> {
|
||||
Ok(Vector2{
|
||||
x: match __js["x"].as_f32() { Some(__x__) => __x__, None => return Err(LoadError{})},
|
||||
y: match __js["y"].as_f32() { Some(__x__) => __x__, None => return Err(LoadError{})},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct Vector3 {
|
||||
pub x:f32,
|
||||
pub y:f32,
|
||||
pub z:f32,
|
||||
}
|
||||
|
||||
impl Vector3 {
|
||||
pub fn new(__js:&json::JsonValue) -> Result<Vector3, LoadError> {
|
||||
Ok(Vector3{
|
||||
x: match __js["x"].as_f32() { Some(__x__) => __x__, None => return Err(LoadError{})},
|
||||
y: match __js["y"].as_f32() { Some(__x__) => __x__, None => return Err(LoadError{})},
|
||||
z: match __js["z"].as_f32() { Some(__x__) => __x__, None => return Err(LoadError{})},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct Vector4 {
|
||||
pub x:f32,
|
||||
pub y:f32,
|
||||
pub z:f32,
|
||||
pub w:f32,
|
||||
}
|
||||
|
||||
|
||||
impl Vector4 {
|
||||
pub fn new(__js:&json::JsonValue) -> Result<Vector4, LoadError> {
|
||||
Ok(Vector4{
|
||||
x: match __js["x"].as_f32() { Some(__x__) => __x__, None => return Err(LoadError{})},
|
||||
y: match __js["y"].as_f32() { Some(__x__) => __x__, None => return Err(LoadError{})},
|
||||
z: match __js["z"].as_f32() { Some(__x__) => __x__, None => return Err(LoadError{})},
|
||||
w: match __js["w"].as_f32() { Some(__x__) => __x__, None => return Err(LoadError{})},
|
||||
})
|
||||
}
|
||||
}
|
@@ -0,0 +1,99 @@
|
||||
{{
|
||||
name = x.rust_full_name
|
||||
key_type = x.key_ttype
|
||||
value_type = x.value_ttype
|
||||
}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct {{name}} {
|
||||
{{~if x.is_map_table ~}}
|
||||
data_list: Vec<std::rc::Rc<{{rust_define_type value_type}}>>,
|
||||
data_map: std::collections::HashMap<{{rust_define_type key_type}}, std::rc::Rc<{{rust_define_type value_type}}>>,
|
||||
{{~else if x.is_list_table ~}}
|
||||
data_list: Vec<std::rc::Rc<{{rust_define_type value_type}}>>,
|
||||
{{~else~}}
|
||||
data: {{rust_class_name value_type}},
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
impl {{name}}{
|
||||
pub fn new(__js: &json::JsonValue) -> Result<{{name}}, LoadError> {
|
||||
{{~if x.is_map_table ~}}
|
||||
if !__js.is_array() {
|
||||
return Err(LoadError{});
|
||||
}
|
||||
let mut t = {{name}} {
|
||||
data_list : Vec::new(),
|
||||
data_map: std::collections::HashMap::new(),
|
||||
};
|
||||
|
||||
for __e in __js.members() {
|
||||
let __v = std::rc::Rc::new(match {{rust_class_name value_type}}::new(__e) {
|
||||
Ok(x) => x,
|
||||
Err(err) => return Err(err),
|
||||
});
|
||||
let __v2 = std::rc::Rc::clone(&__v);
|
||||
t.data_list.push(__v);
|
||||
{{~if !value_type.bean.is_abstract_type~}}
|
||||
t.data_map.insert(__v2.{{x.index_field.convention_name}}.clone(), __v2);
|
||||
{{~else~}}
|
||||
match &*__v2 {
|
||||
{{~for child in value_type.bean.hierarchy_not_abstract_children~}}
|
||||
{{rust_class_name value_type}}::{{child.name}}(__w__) => t.data_map.insert(__w__.{{x.index_field.convention_name}}.clone(), __v2),
|
||||
{{~end~}}
|
||||
};
|
||||
{{~end~}}
|
||||
}
|
||||
Ok(t)
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
pub fn get_data_map(self:&{{name}}) -> &std::collections::HashMap<{{rust_define_type key_type}}, std::rc::Rc<{{rust_define_type value_type}}>> { &self.data_map }
|
||||
#[allow(dead_code)]
|
||||
pub fn get_data_list(self:&{{name}}) -> &Vec<std::rc::Rc<{{rust_define_type value_type}}>> { &self.data_list }
|
||||
#[allow(dead_code)]
|
||||
pub fn get(self:&{{name}}, key: &{{rust_define_type key_type}}) -> std::option::Option<&std::rc::Rc<{{rust_define_type value_type}}>> { self.data_map.get(key) }
|
||||
|
||||
{{~else if x.is_list_table ~}}
|
||||
if !__js.is_array() {
|
||||
return Err(LoadError{});
|
||||
}
|
||||
let mut t = {{name}} {
|
||||
data_list : Vec::new(),
|
||||
};
|
||||
|
||||
for __e in __js.members() {
|
||||
let __v = std::rc::Rc::new(match {{rust_class_name value_type}}::new(__e) {
|
||||
Ok(x) => x,
|
||||
Err(err) => return Err(err),
|
||||
});
|
||||
let __v2 = std::rc::Rc::clone(&__v);
|
||||
t.data_list.push(__v);
|
||||
}
|
||||
Ok(t)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn get_data_list(self:&{{name}}) -> &Vec<std::rc::Rc<{{rust_define_type value_type}}>> { &self.data_list }
|
||||
#[allow(dead_code)]
|
||||
pub fn get(self:&{{name}}, index: usize) -> &std::rc::Rc<{{rust_define_type value_type}}> { &self.data_list[index] }
|
||||
{{~else~}}
|
||||
if !__js.is_array() || __js.len() != 1 {
|
||||
return Err(LoadError{});
|
||||
}
|
||||
let __v = match {{rust_class_name value_type}}::new(&__js[0]) {
|
||||
Ok(x) => x,
|
||||
Err(err) => return Err(err),
|
||||
};
|
||||
let t = {{name}} {
|
||||
data: __v,
|
||||
};
|
||||
Ok(t)
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
pub fn get_data(self:&{{name}}) -> &{{rust_define_type value_type}} { &self.data }
|
||||
{{~end~}}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
{{
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
}}
|
||||
|
||||
type JsonLoader = fn(&str) -> Result<json::JsonValue, LoadError>;
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct {{name}} {
|
||||
{{~ for table in tables ~}}
|
||||
|
||||
{{~if table.comment != '' ~}}
|
||||
/**
|
||||
* {{table.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
pub {{string.downcase table.name}}: {{table.rust_full_name}},
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
impl {{name}} {
|
||||
#[allow(dead_code)]
|
||||
pub fn new(loader: JsonLoader) -> std::result::Result<Tables, LoadError> {
|
||||
let tables = Tables {
|
||||
{{~for table in tables ~}}
|
||||
{{string.downcase table.name}}: {{table.rust_full_name}}::new(&loader("{{table.output_data_file}}")?)?,
|
||||
{{~end~}}
|
||||
};
|
||||
return Ok(tables);
|
||||
}
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
|
||||
{{
|
||||
name = x.name
|
||||
parent_def_type = x.parent_def_type
|
||||
export_fields = x.export_fields
|
||||
hierarchy_export_fields = x.hierarchy_export_fields
|
||||
}}
|
||||
|
||||
{{x.typescript_namespace_begin}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export {{if x.is_abstract_type}} abstract {{end}} class {{name}} {{if parent_def_type}} extends {{x.parent}}{{end}} {
|
||||
{{~if x.is_abstract_type~}}
|
||||
static constructorFrom(_buf_: ByteBuf): {{name}} {
|
||||
switch (_buf_.ReadInt()) {
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.id}}: return new {{child.full_name}}(_buf_)
|
||||
{{~end~}}
|
||||
default: throw new Error()
|
||||
}
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
constructor(_buf_: ByteBuf) {
|
||||
{{~if parent_def_type~}}
|
||||
super(_buf_)
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{ts_bin_constructor ('this.' + field.convention_name) '_buf_' field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
readonly {{field.convention_name}}: {{ts_define_type field.ctype}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{field.ts_ref_validator_define}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
resolve(_tables: Map<string, any>) {
|
||||
{{~if parent_def_type~}}
|
||||
super.resolve(_tables)
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{ts_ref_validator_resolve field}}
|
||||
{{~else if field.has_recursive_ref~}}
|
||||
{{ts_recursive_resolve field '_tables'}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
||||
{{x.typescript_namespace_end}}
|
@@ -0,0 +1,90 @@
|
||||
{{
|
||||
name = x.name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
}}
|
||||
{{x.typescript_namespace_begin}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export class {{name}} {
|
||||
{{~if x.is_map_table ~}}
|
||||
private _dataMap: Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>
|
||||
private _dataList: {{ts_define_type value_type}}[]
|
||||
|
||||
constructor(_buf_: ByteBuf) {
|
||||
this._dataMap = new Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>()
|
||||
this._dataList = []
|
||||
|
||||
for(let n = _buf_.ReadInt() ; n > 0 ; n--) {
|
||||
let _v: {{ts_define_type value_type}}
|
||||
{{ts_bin_constructor '_v' '_buf_' value_type}}
|
||||
this._dataList.push(_v)
|
||||
this._dataMap.set(_v.{{x.index_field.convention_name}}, _v)
|
||||
}
|
||||
}
|
||||
|
||||
getDataMap(): Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}> { return this._dataMap }
|
||||
getDataList(): {{ts_define_type value_type}}[] { return this._dataList }
|
||||
|
||||
get(key: {{ts_define_type key_type}}): {{ts_define_type value_type}} | undefined { return this._dataMap.get(key) }
|
||||
|
||||
resolve(_tables: Map<string, any>) {
|
||||
for(var v of this._dataList) {
|
||||
v.resolve(_tables)
|
||||
}
|
||||
}
|
||||
{{~else if x.is_list_table ~}}
|
||||
private _dataList: {{ts_define_type value_type}}[]
|
||||
|
||||
constructor(_buf_: ByteBuf) {
|
||||
this._dataList = []
|
||||
|
||||
for(let n = _buf_.ReadInt() ; n > 0 ; n--) {
|
||||
let _v: {{ts_define_type value_type}}
|
||||
{{ts_bin_constructor '_v' '_buf_' value_type}}
|
||||
this._dataList.push(_v)
|
||||
}
|
||||
}
|
||||
|
||||
getDataList(): {{ts_define_type value_type}}[] { return this._dataList }
|
||||
|
||||
get(index: number): {{ts_define_type value_type}} | undefined { return this._dataList[index] }
|
||||
|
||||
resolve(_tables: Map<string, any>) {
|
||||
for(var v of this._dataList) {
|
||||
v.resolve(_tables)
|
||||
}
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
|
||||
private _data: {{ts_define_type value_type}}
|
||||
|
||||
constructor(_buf_: ByteBuf) {
|
||||
if (_buf_.ReadInt() != 1) throw new Error('table mode=one, but size != 1')
|
||||
{{ts_bin_constructor 'this._data' '_buf_' value_type}}
|
||||
}
|
||||
|
||||
getData(): {{ts_define_type value_type}} { return this._data }
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
get {{field.convention_name}}(): {{ts_define_type field.ctype}} { return this._data.{{field.convention_name}} }
|
||||
{{~end~}}
|
||||
|
||||
resolve(_tables: Map<string, any>) {
|
||||
this._data.resolve(_tables)
|
||||
}
|
||||
|
||||
{{end}}
|
||||
}
|
||||
{{x.typescript_namespace_end}}
|
@@ -0,0 +1,32 @@
|
||||
{{
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
|
||||
}}
|
||||
|
||||
type ByteBufLoader = (file: string) => ByteBuf
|
||||
|
||||
export class {{name}} {
|
||||
{{~ for table in tables ~}}
|
||||
private _{{table.name}}: {{table.full_name}}
|
||||
{{~if table.comment != '' ~}}
|
||||
/**
|
||||
* {{table.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
get {{table.name}}(): {{table.full_name}} { return this._{{table.name}}}
|
||||
{{~end~}}
|
||||
|
||||
constructor(loader: ByteBufLoader) {
|
||||
let tables = new Map<string, any>()
|
||||
{{~for table in tables ~}}
|
||||
this._{{table.name}} = new {{table.full_name}}(loader('{{table.output_data_file}}'))
|
||||
tables.set('{{table.full_name}}', this._{{table.name}})
|
||||
{{~end~}}
|
||||
|
||||
{{~ for table in tables ~}}
|
||||
this._{{table.name}}.resolve(tables)
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
@@ -0,0 +1,90 @@
|
||||
|
||||
export class Vector2 implements ISerializable {
|
||||
|
||||
static deserializeFrom(buf: ByteBuf): Vector2 {
|
||||
var v = new Vector2()
|
||||
v.deserialize(buf)
|
||||
return v
|
||||
}
|
||||
|
||||
x: number
|
||||
y: number
|
||||
constructor(x: number = 0, y: number = 0) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
}
|
||||
|
||||
serialize(_buf_: ByteBuf) {
|
||||
_buf_.WriteFloat(this.x)
|
||||
_buf_.WriteFloat(this.y)
|
||||
}
|
||||
|
||||
deserialize(buf: ByteBuf) {
|
||||
this.x = buf.ReadFloat()
|
||||
this.y = buf.ReadFloat()
|
||||
}
|
||||
}
|
||||
|
||||
export class Vector3 implements ISerializable{
|
||||
static deserializeFrom(buf: ByteBuf): Vector3 {
|
||||
var v = new Vector3()
|
||||
v.deserialize(buf)
|
||||
return v
|
||||
}
|
||||
|
||||
x: number
|
||||
y: number
|
||||
z: number
|
||||
|
||||
constructor(x: number = 0, y: number = 0, z: number = 0) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
this.z = z
|
||||
}
|
||||
|
||||
serialize(_buf_: ByteBuf) {
|
||||
_buf_.WriteFloat(this.x)
|
||||
_buf_.WriteFloat(this.y)
|
||||
_buf_.WriteFloat(this.z)
|
||||
}
|
||||
|
||||
deserialize(buf: ByteBuf) {
|
||||
this.x = buf.ReadFloat()
|
||||
this.y = buf.ReadFloat()
|
||||
this.z = buf.ReadFloat()
|
||||
}
|
||||
}
|
||||
|
||||
export class Vector4 implements ISerializable {
|
||||
static deserializeFrom(buf: ByteBuf): Vector4 {
|
||||
var v = new Vector4()
|
||||
v.deserialize(buf)
|
||||
return v
|
||||
}
|
||||
|
||||
x: number
|
||||
y: number
|
||||
z: number
|
||||
w: number
|
||||
|
||||
constructor(x: number = 0, y: number = 0, z: number = 0, w: number = 0) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
this.z = z
|
||||
this.w = w
|
||||
}
|
||||
|
||||
serialize(_buf_: ByteBuf) {
|
||||
_buf_.WriteFloat(this.x)
|
||||
_buf_.WriteFloat(this.y)
|
||||
_buf_.WriteFloat(this.z)
|
||||
_buf_.WriteFloat(this.w)
|
||||
}
|
||||
|
||||
deserialize(buf: ByteBuf) {
|
||||
this.x = buf.ReadFloat()
|
||||
this.y = buf.ReadFloat()
|
||||
this.z = buf.ReadFloat()
|
||||
this.z = buf.ReadFloat()
|
||||
}
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
|
||||
{{
|
||||
name = x.name
|
||||
parent_def_type = x.parent_def_type
|
||||
export_fields = x.export_fields
|
||||
hierarchy_export_fields = x.hierarchy_export_fields
|
||||
}}
|
||||
|
||||
{{x.typescript_namespace_begin}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export {{if x.is_abstract_type}}abstract {{end}}class {{name}}{{if parent_def_type}} extends {{x.parent}}{{end}} {
|
||||
{{~if x.is_abstract_type~}}
|
||||
static constructorFrom(_json_: any): {{name}}{
|
||||
switch (_json_["{{x.json_type_name_key}}"]) {
|
||||
{{~ 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 Error()
|
||||
}
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
constructor(_json_: any) {
|
||||
{{~if parent_def_type~}}
|
||||
super(_json_)
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if !field.ctype.is_nullable~}}
|
||||
if (_json_.{{field.name}} === undefined) { throw new Error() }
|
||||
{{~end~}}
|
||||
{{ts_json_constructor ('this.' + field.convention_name) ( '_json_.' + field.name) field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
readonly {{field.convention_name}}: {{ts_define_type field.ctype}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{field.ts_ref_validator_define}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
resolve(_tables: Map<string, any>) {
|
||||
{{~if parent_def_type~}}
|
||||
super.resolve(_tables)
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{ts_ref_validator_resolve field}}
|
||||
{{~else if field.has_recursive_ref~}}
|
||||
{{ts_recursive_resolve field '_tables'}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
||||
{{x.typescript_namespace_end}}
|
@@ -0,0 +1,86 @@
|
||||
{{
|
||||
name = x.name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
}}
|
||||
{{x.typescript_namespace_begin}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export class {{name}}{
|
||||
{{~if x.is_map_table ~}}
|
||||
private _dataMap: Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>
|
||||
private _dataList: {{ts_define_type value_type}}[]
|
||||
constructor(_json_: any) {
|
||||
this._dataMap = new Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>()
|
||||
this._dataList = []
|
||||
for(var _json2_ of _json_) {
|
||||
let _v: {{ts_define_type value_type}}
|
||||
{{ts_json_constructor '_v' '_json2_' value_type}}
|
||||
this._dataList.push(_v)
|
||||
this._dataMap.set(_v.{{x.index_field.convention_name}}, _v)
|
||||
}
|
||||
}
|
||||
|
||||
getDataMap(): Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}> { return this._dataMap; }
|
||||
getDataList(): {{ts_define_type value_type}}[] { return this._dataList; }
|
||||
|
||||
get(key: {{ts_define_type key_type}}): {{ts_define_type value_type}} | undefined { return this._dataMap.get(key); }
|
||||
|
||||
resolve(_tables: Map<string, any>) {
|
||||
for(var v of this._dataList) {
|
||||
v.resolve(_tables)
|
||||
}
|
||||
}
|
||||
{{~else if x.is_list_table ~}}
|
||||
private _dataList: {{ts_define_type value_type}}[]
|
||||
|
||||
constructor(_json_: any) {
|
||||
this._dataList = []
|
||||
for(var _json2_ of _json_) {
|
||||
let _v: {{ts_define_type value_type}}
|
||||
{{ts_json_constructor '_v' '_json2_' value_type}}
|
||||
this._dataList.push(_v)
|
||||
}
|
||||
}
|
||||
|
||||
getDataList(): {{ts_define_type value_type}}[] { return this._dataList }
|
||||
|
||||
get(index: number): {{ts_define_type value_type}} | undefined { return this._dataList[index] }
|
||||
|
||||
resolve(_tables: Map<string, any>) {
|
||||
for(var v of this._dataList) {
|
||||
v.resolve(_tables)
|
||||
}
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
|
||||
private _data: {{ts_define_type value_type}}
|
||||
constructor(_json_: any) {
|
||||
if (_json_.length != 1) throw new Error('table mode=one, but size != 1')
|
||||
{{ts_json_constructor 'this._data' '_json_[0]' value_type}}
|
||||
}
|
||||
|
||||
getData(): {{ts_define_type value_type}} { return this._data; }
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
get {{field.convention_name}}(): {{ts_define_type field.ctype}} { return this._data.{{field.convention_name}}; }
|
||||
{{~end~}}
|
||||
|
||||
resolve(_tables: Map<string, any>) {
|
||||
this._data.resolve(_tables)
|
||||
}
|
||||
|
||||
{{end}}
|
||||
}
|
||||
{{x.typescript_namespace_end}}
|
@@ -0,0 +1,32 @@
|
||||
{{
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
|
||||
}}
|
||||
|
||||
type JsonLoader = (file: string) => any
|
||||
|
||||
export class {{name}} {
|
||||
{{~ for table in tables ~}}
|
||||
private _{{table.name}}: {{table.full_name}}
|
||||
{{~if table.comment != '' ~}}
|
||||
/**
|
||||
* {{table.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
get {{table.name}}(): {{table.full_name}} { return this._{{table.name}};}
|
||||
{{~end~}}
|
||||
|
||||
constructor(loader: JsonLoader) {
|
||||
let tables = new Map<string, any>()
|
||||
{{~for table in tables ~}}
|
||||
this._{{table.name}} = new {{table.full_name}}(loader('{{table.output_data_file}}'))
|
||||
tables.set('{{table.full_name}}', this._{{table.name}})
|
||||
{{~end~}}
|
||||
|
||||
{{~ for table in tables ~}}
|
||||
this._{{table.name}}.resolve(tables)
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
|
||||
export class Vector2 {
|
||||
static deserializeFromJson(json: any): Vector2 {
|
||||
let x = json.x
|
||||
let y = json.y
|
||||
if (x == null || y == null) {
|
||||
throw new Error()
|
||||
}
|
||||
return new Vector2(x, y)
|
||||
}
|
||||
|
||||
x: number
|
||||
y: number
|
||||
constructor(x: number = 0, y: number = 0) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
}
|
||||
}
|
||||
|
||||
export class Vector3 {
|
||||
static deserializeFromJson(json: any): Vector3 {
|
||||
let x = json.x
|
||||
let y = json.y
|
||||
let z = json.z
|
||||
if (x == null || y == null || z == null) {
|
||||
throw new Error()
|
||||
}
|
||||
return new Vector3(x, y, z)
|
||||
}
|
||||
|
||||
x: number
|
||||
y: number
|
||||
z: number
|
||||
|
||||
constructor(x: number = 0, y: number = 0, z: number = 0) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
this.z = z
|
||||
}
|
||||
}
|
||||
|
||||
export class Vector4 {
|
||||
static deserializeFromJson(json: any): Vector4 {
|
||||
let x = json.x
|
||||
let y = json.y
|
||||
let z = json.z
|
||||
let w = json.w
|
||||
if (x == null || y == null || z == null || w == null) {
|
||||
throw new Error()
|
||||
}
|
||||
return new Vector4(x, y, z, w)
|
||||
}
|
||||
|
||||
x: number
|
||||
y: number
|
||||
z: number
|
||||
w: number
|
||||
|
||||
constructor(x: number = 0, y: number = 0, z: number = 0, w: number = 0) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
this.z = z
|
||||
this.w = w
|
||||
}
|
||||
}
|
202
Luban/Luban.ClientServer/Templates/db/cs_async/bean.tpl
Normal file
202
Luban/Luban.ClientServer/Templates/db/cs_async/bean.tpl
Normal file
@@ -0,0 +1,202 @@
|
||||
{{
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
fields = x.fields
|
||||
hierarchy_fields = x.hierarchy_fields
|
||||
is_abstract_type = x.is_abstract_type
|
||||
readonly_name = "IReadOnly" + name
|
||||
}}
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public interface {{readonly_name}} {{if parent_def_type}}: IReadOnly{{x.parent_def_type.name}} {{end}}
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{db_cs_readonly_define_type field.ctype}} {{field.convention_name}} { get; }
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{x.cs_class_modifier}} class {{name}} : {{if parent_def_type}} {{x.parent}} {{else}} BrightDB.Transaction.TxnBeanBase {{end}}, {{readonly_name}}
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{if is_abstract_type}}protected{{else}}private{{end}} {{db_cs_define_type field.ctype}} {{field.internal_name}};
|
||||
{{~end}}
|
||||
|
||||
public {{name}}()
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{if cs_need_init field.ctype}}{{db_cs_init_field field.internal_name field.ctype}} {{end}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in fields~}}
|
||||
{{ctype = field.ctype}}
|
||||
{{~if has_setter ctype~}}
|
||||
|
||||
private sealed class {{field.log_type}} : BrightDB.Transaction.FieldLogger<{{name}}, {{db_cs_define_type ctype}}>
|
||||
{
|
||||
public {{field.log_type}}({{name}} self, {{db_cs_define_type ctype}} value) : base(self, value) { }
|
||||
|
||||
public override long FieldId => this._host.GetObjectId() + {{field.id}};
|
||||
|
||||
public override int TagId => FieldTag.{{tag_name ctype}};
|
||||
|
||||
public override void Commit() { this._host.{{field.internal_name}} = this.Value; }
|
||||
|
||||
|
||||
public override void WriteBlob(ByteBuf _buf)
|
||||
{
|
||||
{{cs_write_blob '_buf' 'this.Value' ctype}}
|
||||
}
|
||||
}
|
||||
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{db_cs_define_type ctype}} {{field.convention_name}}
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.IsManaged)
|
||||
{
|
||||
var txn = BrightDB.Transaction.TransactionContext.ThreadStaticCtx;
|
||||
if (txn == null) return {{field.internal_name}};
|
||||
var log = ({{field.log_type}})txn.GetField(this.GetObjectId() + {{field.id}});
|
||||
return log != null ? log.Value : {{field.internal_name}};
|
||||
}
|
||||
else
|
||||
{
|
||||
return {{field.internal_name}};
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
{{~if db_field_cannot_null~}}
|
||||
if (value == null) throw new ArgumentNullException();
|
||||
{{~end~}}
|
||||
if (this.IsManaged)
|
||||
{
|
||||
var txn = BrightDB.Transaction.TransactionContext.ThreadStaticCtx;
|
||||
txn.PutField(this.GetObjectId() + {{field.id}}, new {{field.log_type}}(this, value));
|
||||
{{~if ctype.need_set_children_root}}
|
||||
value?.InitRoot(GetRoot());
|
||||
{{end}}
|
||||
}
|
||||
else
|
||||
{
|
||||
{{field.internal_name}} = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
{{~else~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{db_cs_define_type ctype}} {{field.convention_name}} => {{field.internal_name}};
|
||||
{{~end~}}
|
||||
|
||||
{{~if ctype.bean || ctype.element_type ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
{{db_cs_readonly_define_type ctype}} {{readonly_name}}.{{field.convention_name}} => {{field.internal_name}};
|
||||
{{~else if ctype.is_map~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
{{db_cs_readonly_define_type ctype}} {{readonly_name}}.{{field.convention_name}} => new BrightDB.Transaction.Collections.PReadOnlyMap<{{db_cs_readonly_define_type ctype.key_type}}, {{db_cs_readonly_define_type ctype.value_type}}, {{db_cs_define_type ctype.value_type}}>({{field.internal_name}});
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if is_abstract_type~}}
|
||||
public static void Serialize{{name}}(ByteBuf _buf, {{name}} x)
|
||||
{
|
||||
if (x == null) { _buf.WriteInt(0); return; }
|
||||
_buf.WriteInt(x.GetTypeId());
|
||||
x.Serialize(_buf);
|
||||
}
|
||||
|
||||
public static {{name}} Deserialize{{name}}(ByteBuf _buf)
|
||||
{
|
||||
{{name}} x;
|
||||
switch (_buf.ReadInt())
|
||||
{
|
||||
case 0 : return null;
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name}}.__ID__: x = new {{child.full_name}}(); break;
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
x.Deserialize(_buf);
|
||||
return x;
|
||||
}
|
||||
{{~else~}}
|
||||
public override void Serialize(ByteBuf _buf)
|
||||
{
|
||||
_buf.WriteLong(this.GetObjectId());
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{ _buf.WriteInt(FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT)); {{db_cs_compatible_serialize '_buf' field.internal_name field.ctype}} }
|
||||
{{~end}}
|
||||
}
|
||||
|
||||
public override void Deserialize(ByteBuf _buf)
|
||||
{
|
||||
this.SetObjectId(_buf.ReadLong());
|
||||
while(_buf.NotEmpty)
|
||||
{
|
||||
int _tag_ = _buf.ReadInt();
|
||||
switch (_tag_)
|
||||
{
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
case FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT) : { {{db_cs_compatible_deserialize '_buf' field.internal_name field.ctype}} break; }
|
||||
{{~end~}}
|
||||
default: { _buf.SkipUnknownField(_tag_); break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public const int __ID__ = {{x.id}};
|
||||
public override int GetTypeId() => __ID__;
|
||||
{{~end~}}
|
||||
|
||||
protected override void InitChildrenRoot(BrightDB.Storage.TKey root)
|
||||
{
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{{~if need_set_children_root field.ctype~}}
|
||||
UnsafeUtil.InitRoot({{field.internal_name}}, root);
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{{full_name}}{ "
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
+ "{{field.convention_name}}:" + {{cs_to_string field.convention_name field.ctype}} + ","
|
||||
{{~end~}}
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
61
Luban/Luban.ClientServer/Templates/db/cs_async/table.tpl
Normal file
61
Luban/Luban.ClientServer/Templates/db/cs_async/table.tpl
Normal file
@@ -0,0 +1,61 @@
|
||||
{{
|
||||
name = x.name
|
||||
key_ttype = x.key_ttype
|
||||
value_ttype = x.value_ttype
|
||||
base_table_type = x.base_table_type
|
||||
internal_table_type = x.internal_table_type
|
||||
}}
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public sealed class {{name}}
|
||||
{
|
||||
public static {{base_table_type}} Table { get; } = new {{internal_table_type}}();
|
||||
|
||||
private class {{internal_table_type}} : {{base_table_type}}
|
||||
{
|
||||
public {{internal_table_type}}() : base({{x.table_uid}}, "{{x.full_name}}")
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
public static ValueTask<{{db_cs_define_type value_ttype}}> GetAsync({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.GetAsync(key);
|
||||
}
|
||||
|
||||
public static ValueTask<{{db_cs_define_type value_ttype}}> CreateIfNotExistAsync({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.CreateIfNotExistAsync(key);
|
||||
}
|
||||
|
||||
public static Task InsertAsync({{db_cs_define_type key_ttype}} key, {{db_cs_define_type value_ttype}} value)
|
||||
{
|
||||
return Table.InsertAsync(key, value);
|
||||
}
|
||||
|
||||
public static Task RemoveAsync({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.RemoveAsync(key);
|
||||
}
|
||||
|
||||
public static Task PutAsync({{db_cs_define_type key_ttype}} key, {{db_cs_define_type value_ttype}} value)
|
||||
{
|
||||
return Table.PutAsync(key, value);
|
||||
}
|
||||
|
||||
public static ValueTask<{{db_cs_readonly_define_type value_ttype}}> SelectAsync({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.SelectAsync<{{db_cs_readonly_define_type value_ttype}}>(key);
|
||||
}
|
||||
}
|
||||
}
|
16
Luban/Luban.ClientServer/Templates/db/cs_async/tables.tpl
Normal file
16
Luban/Luban.ClientServer/Templates/db/cs_async/tables.tpl
Normal file
@@ -0,0 +1,16 @@
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{namespace}}
|
||||
{
|
||||
|
||||
public static class {{name}}
|
||||
{
|
||||
public static System.Collections.Generic.List<BrightDB.Transaction.TxnTable> TableList { get; } = new System.Collections.Generic.List<BrightDB.Transaction.TxnTable>
|
||||
{
|
||||
{{~ for table in tables~}}
|
||||
{{table.full_name}}.Table,
|
||||
{{~end}}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
202
Luban/Luban.ClientServer/Templates/db/cs_sync/bean.tpl
Normal file
202
Luban/Luban.ClientServer/Templates/db/cs_sync/bean.tpl
Normal file
@@ -0,0 +1,202 @@
|
||||
{{
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
fields = x.fields
|
||||
hierarchy_fields = x.hierarchy_fields
|
||||
is_abstract_type = x.is_abstract_type
|
||||
readonly_name = "IReadOnly" + name
|
||||
}}
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public interface {{readonly_name}} {{if parent_def_type}}: IReadOnly{{x.parent_def_type.name}} {{end}}
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{db_cs_readonly_define_type field.ctype}} {{field.convention_name}} { get; }
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{x.cs_class_modifier}} class {{name}} : {{if parent_def_type}} {{x.parent}} {{else}} BrightDB.Transaction.TxnBeanBase {{end}}, {{readonly_name}}
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{if is_abstract_type}}protected{{else}}private{{end}} {{db_cs_define_type field.ctype}} {{field.internal_name}};
|
||||
{{~end}}
|
||||
|
||||
public {{name}}()
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{if cs_need_init field.ctype}}{{db_cs_init_field field.internal_name field.ctype}} {{end}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in fields~}}
|
||||
{{ctype = field.ctype}}
|
||||
{{~if has_setter ctype~}}
|
||||
|
||||
private sealed class {{field.log_type}} : BrightDB.Transaction.FieldLogger<{{name}}, {{db_cs_define_type ctype}}>
|
||||
{
|
||||
public {{field.log_type}}({{name}} self, {{db_cs_define_type ctype}} value) : base(self, value) { }
|
||||
|
||||
public override long FieldId => this._host.GetObjectId() + {{field.id}};
|
||||
|
||||
public override int TagId => FieldTag.{{tag_name ctype}};
|
||||
|
||||
public override void Commit() { this._host.{{field.internal_name}} = this.Value; }
|
||||
|
||||
|
||||
public override void WriteBlob(ByteBuf _buf)
|
||||
{
|
||||
{{cs_write_blob '_buf' 'this.Value' ctype}}
|
||||
}
|
||||
}
|
||||
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{db_cs_define_type ctype}} {{field.convention_name}}
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.IsManaged)
|
||||
{
|
||||
var txn = BrightDB.Transaction.TransactionContext.ThreadStaticCtx;
|
||||
if (txn == null) return {{field.internal_name}};
|
||||
var log = ({{field.log_type}})txn.GetField(this.GetObjectId() + {{field.id}});
|
||||
return log != null ? log.Value : {{field.internal_name}};
|
||||
}
|
||||
else
|
||||
{
|
||||
return {{field.internal_name}};
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
{{~if db_field_cannot_null~}}
|
||||
if (value == null) throw new ArgumentNullException();
|
||||
{{~end~}}
|
||||
if (this.IsManaged)
|
||||
{
|
||||
var txn = BrightDB.Transaction.TransactionContext.ThreadStaticCtx;
|
||||
txn.PutField(this.GetObjectId() + {{field.id}}, new {{field.log_type}}(this, value));
|
||||
{{~if ctype.need_set_children_root}}
|
||||
value?.InitRoot(GetRoot());
|
||||
{{end}}
|
||||
}
|
||||
else
|
||||
{
|
||||
{{field.internal_name}} = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
{{~else~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{db_cs_define_type ctype}} {{field.convention_name}} => {{field.internal_name}};
|
||||
{{~end~}}
|
||||
|
||||
{{~if ctype.bean || ctype.element_type ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
{{db_cs_readonly_define_type ctype}} {{readonly_name}}.{{field.convention_name}} => {{field.internal_name}};
|
||||
{{~else if ctype.is_map~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
{{db_cs_readonly_define_type ctype}} {{readonly_name}}.{{field.convention_name}} => new BrightDB.Transaction.Collections.PReadOnlyMap<{{db_cs_readonly_define_type ctype.key_type}}, {{db_cs_readonly_define_type ctype.value_type}}, {{db_cs_define_type ctype.value_type}}>({{field.internal_name}});
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if is_abstract_type~}}
|
||||
public static void Serialize{{name}}(ByteBuf _buf, {{name}} x)
|
||||
{
|
||||
if (x == null) { _buf.WriteInt(0); return; }
|
||||
_buf.WriteInt(x.GetTypeId());
|
||||
x.Serialize(_buf);
|
||||
}
|
||||
|
||||
public static {{name}} Deserialize{{name}}(ByteBuf _buf)
|
||||
{
|
||||
{{name}} x;
|
||||
switch (_buf.ReadInt())
|
||||
{
|
||||
case 0 : return null;
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name}}.__ID__: x = new {{child.full_name}}(); break;
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
x.Deserialize(_buf);
|
||||
return x;
|
||||
}
|
||||
{{~else~}}
|
||||
public override void Serialize(ByteBuf _buf)
|
||||
{
|
||||
_buf.WriteLong(this.GetObjectId());
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{ _buf.WriteInt(FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT)); {{db_cs_compatible_serialize '_buf' field.internal_name field.ctype}} }
|
||||
{{~end}}
|
||||
}
|
||||
|
||||
public override void Deserialize(ByteBuf _buf)
|
||||
{
|
||||
this.SetObjectId(_buf.ReadLong());
|
||||
while(_buf.NotEmpty)
|
||||
{
|
||||
int _tag_ = _buf.ReadInt();
|
||||
switch (_tag_)
|
||||
{
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
case FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT) : { {{db_cs_compatible_deserialize '_buf' field.internal_name field.ctype}} break; }
|
||||
{{~end~}}
|
||||
default: { _buf.SkipUnknownField(_tag_); break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public const int __ID__ = {{x.id}};
|
||||
public override int GetTypeId() => __ID__;
|
||||
{{~end~}}
|
||||
|
||||
protected override void InitChildrenRoot(Bright.Storage.TKey root)
|
||||
{
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{{~if need_set_children_root field.ctype~}}
|
||||
UnsafeUtil.InitRoot({{field.internal_name}}, root);
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{{full_name}}{ "
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
+ "{{field.convention_name}}:" + {{cs_to_string field.convention_name field.ctype}} + ","
|
||||
{{~end~}}
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
66
Luban/Luban.ClientServer/Templates/db/cs_sync/table.tpl
Normal file
66
Luban/Luban.ClientServer/Templates/db/cs_sync/table.tpl
Normal file
@@ -0,0 +1,66 @@
|
||||
{{
|
||||
name = x.name
|
||||
key_ttype = x.key_ttype
|
||||
value_ttype = x.value_ttype
|
||||
base_table_type = x.base_table_type
|
||||
internal_table_type = x.internal_table_type
|
||||
}}
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public sealed class {{name}}
|
||||
{
|
||||
public static {{base_table_type}} Table { get; } = new {{internal_table_type}}();
|
||||
|
||||
private class {{internal_table_type}} : {{base_table_type}}
|
||||
{
|
||||
public {{internal_table_type}}() : base({{x.table_uid}}, "{{x.full_name}}")
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
public static {{db_cs_define_type value_ttype}} Get({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.Get(key);
|
||||
}
|
||||
|
||||
public static {{db_cs_define_type value_ttype}} CreateIfNotExist({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.CreateIfNotExist(key);
|
||||
}
|
||||
|
||||
public static void Insert({{db_cs_define_type key_ttype}} key, {{db_cs_define_type value_ttype}} value)
|
||||
{
|
||||
Table.Insert(key, value);
|
||||
}
|
||||
|
||||
public static void Remove({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
Table.Remove(key);
|
||||
}
|
||||
|
||||
public static void Put({{db_cs_define_type key_ttype}} key, {{db_cs_define_type value_ttype}} value)
|
||||
{
|
||||
Table.Put(key, value);
|
||||
}
|
||||
|
||||
public static {{db_cs_readonly_define_type value_ttype}} Select({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.Select(key);
|
||||
}
|
||||
|
||||
public static ValueTask<{{db_cs_readonly_define_type value_ttype}}> SelectAsync({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.SelectAsync<{{db_cs_readonly_define_type value_ttype}}>(key);
|
||||
}
|
||||
}
|
||||
}
|
16
Luban/Luban.ClientServer/Templates/db/cs_sync/tables.tpl
Normal file
16
Luban/Luban.ClientServer/Templates/db/cs_sync/tables.tpl
Normal file
@@ -0,0 +1,16 @@
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{namespace}}
|
||||
{
|
||||
|
||||
public static class {{name}}
|
||||
{
|
||||
public static System.Collections.Generic.List<BrightDB.Transaction.TxnTable> TableList { get; } = new System.Collections.Generic.List<BrightDB.Transaction.TxnTable>
|
||||
{
|
||||
{{~ for table in tables~}}
|
||||
{{table.full_name}}.Table,
|
||||
{{~end}}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
157
Luban/Luban.ClientServer/Templates/db/typescript/bean.tpl
Normal file
157
Luban/Luban.ClientServer/Templates/db/typescript/bean.tpl
Normal file
@@ -0,0 +1,157 @@
|
||||
{{
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
fields = x.fields
|
||||
hierarchy_fields = x.hierarchy_fields
|
||||
is_abstract_type = x.is_abstract_type
|
||||
readonly_name = 'IReadOnly' + name
|
||||
}}
|
||||
|
||||
{{x.typescript_namespace_begin}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export {{x.ts_class_modifier}} class {{name}} extends {{if parent_def_type}} {{x.parent}} {{else}} TxnBeanBase {{end}}{
|
||||
{{~ for field in fields~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{if is_abstract_type}}protected{{else}}private{{end}} {{field.internal_name}}: {{db_ts_define_type field.ctype}}
|
||||
{{~end}}
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
{{~ for field in fields~}}
|
||||
{{db_ts_init_field field.internal_name_with_this field.log_type field.ctype }}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in fields~}}
|
||||
{{~ctype = field.ctype~}}
|
||||
{{~if has_setter ctype~}}
|
||||
private static {{field.log_type}} = class extends FieldLoggerGeneric2<{{name}}, {{db_ts_define_type ctype}}> {
|
||||
constructor(self:{{name}}, value: {{db_ts_define_type ctype}}) { super(self, value) }
|
||||
|
||||
get fieldId(): number { return this.host.getObjectId() + {{field.id}} }
|
||||
|
||||
get tagId(): number { return FieldTag.{{tag_name ctype}} }
|
||||
|
||||
commit() { this.host.{{field.internal_name}} = this.value }
|
||||
|
||||
writeBlob(_buf: ByteBuf) {
|
||||
{{ts_write_blob '_buf' 'this.value' ctype}}
|
||||
}
|
||||
}
|
||||
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
get {{field.convention_name}}(): {{db_ts_define_type ctype}} {
|
||||
if (this.isManaged) {
|
||||
var txn = TransactionContext.current
|
||||
if (txn == null) return {{field.internal_name_with_this}}
|
||||
let log: any = txn.getField(this.getObjectId() + {{field.id}})
|
||||
return log != null ? log.value : {{field.internal_name_with_this}}
|
||||
} else {
|
||||
return {{field.internal_name_with_this}};
|
||||
}
|
||||
}
|
||||
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
set {{field.convention_name}}(value: {{db_ts_define_type ctype}}) {
|
||||
{{~if db_field_cannot_null~}}
|
||||
if (value == null) throw new Error()
|
||||
{{~end~}}
|
||||
if (this.isManaged) {
|
||||
let txn = TransactionContext.current!
|
||||
txn.putFieldLong(this.getObjectId() + {{field.id}}, new {{name}}.{{field.log_type}}(this, value))
|
||||
{{~if ctype.need_set_children_root~}}
|
||||
value?.initRoot(this.getRoot())
|
||||
{{~end~}}
|
||||
} else {
|
||||
{{field.internal_name_with_this}} = value
|
||||
}
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
get {{field.convention_name}}(): {{db_ts_define_type ctype}} { return {{field.internal_name_with_this}} }
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if is_abstract_type~}}
|
||||
static serialize{{name}}Any(_buf: ByteBuf, x: {{name}}) {
|
||||
if (x == null) { _buf.WriteInt(0); return }
|
||||
_buf.WriteInt(x.getTypeId())
|
||||
x.serialize(_buf)
|
||||
}
|
||||
|
||||
deserialize{{name}}Any(_buf: ByteBuf): {{name}}{
|
||||
let x: {{name}}
|
||||
switch (_buf.ReadInt()) {
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name}}.__ID__: x = new {{child.full_name}}(); break
|
||||
{{~end~}}
|
||||
default: throw new Error()
|
||||
}
|
||||
x.deserialize(_buf)
|
||||
return x
|
||||
}
|
||||
{{~else~}}
|
||||
serialize(_buf: ByteBuf) {
|
||||
_buf.WriteNumberAsLong(this.getObjectId())
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{ _buf.WriteInt(FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT)); {{db_ts_compatible_serialize '_buf' field.internal_name_with_this field.ctype}} }
|
||||
{{~end}}
|
||||
}
|
||||
|
||||
deserialize(_buf: ByteBuf) {
|
||||
this.setObjectId(_buf.ReadLongAsNumber())
|
||||
while(_buf.NotEmpty) {
|
||||
let _tag_ = _buf.ReadInt()
|
||||
switch (_tag_) {
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
case FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT) : { {{db_ts_compatible_deserialize '_buf' field.internal_name_with_this field.ctype}}; break; }
|
||||
{{~end~}}
|
||||
default: { _buf.SkipUnknownField(_tag_); break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static readonly __ID__ = {{x.id}}
|
||||
getTypeId(): number { return {{name}}.__ID__ }
|
||||
{{~end~}}
|
||||
|
||||
initChildrenRoot(root: TKey) {
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{{~if need_set_children_root field.ctype~}}
|
||||
{{field.internal_name_with_this}}?.initRoot(root)
|
||||
{{~end~}}
|
||||
{{~end}}
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return '{{full_name}}{ '
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
+ '{{field.convention_name}}:' + {{ts_to_string ('this.' + field.convention_name) field.ctype}} + ','
|
||||
{{~end~}}
|
||||
+ '}'
|
||||
}
|
||||
}
|
||||
|
||||
{{x.typescript_namespace_end}}
|
71
Luban/Luban.ClientServer/Templates/db/typescript/table.tpl
Normal file
71
Luban/Luban.ClientServer/Templates/db/typescript/table.tpl
Normal file
@@ -0,0 +1,71 @@
|
||||
{{
|
||||
name = x.name
|
||||
key_ttype = x.key_ttype
|
||||
value_ttype = x.value_ttype
|
||||
internal_table_type = x.internal_table_type
|
||||
}}
|
||||
|
||||
{{x.typescript_namespace_begin}}
|
||||
class {{internal_table_type}} extends TxnTableGeneric<{{db_ts_define_type key_ttype}},{{db_ts_define_type value_ttype}}> {
|
||||
constructor() {
|
||||
super({{x.table_uid}}, '{{x.full_name}}')
|
||||
}
|
||||
|
||||
newValue(): {{db_ts_define_type value_ttype}} { return new {{db_ts_define_type value_ttype}}() }
|
||||
|
||||
serializeKey(buf: ByteBuf, key: {{db_ts_define_type key_ttype}}) {
|
||||
{{db_ts_compatible_serialize_without_segment 'buf' 'key' key_ttype}}
|
||||
}
|
||||
|
||||
serializeValue(buf: ByteBuf, value: {{db_ts_define_type value_ttype}}) {
|
||||
{{db_ts_compatible_serialize_without_segment 'buf' 'value' value_ttype}}
|
||||
}
|
||||
|
||||
deserializeKey(buf: ByteBuf): {{db_ts_define_type key_ttype}} {
|
||||
let key: {{db_ts_define_type key_ttype}}
|
||||
{{db_ts_compatible_deserialize_without_segment 'buf' 'key' key_ttype}}
|
||||
return key
|
||||
}
|
||||
|
||||
deserializeValue(buf: ByteBuf): {{db_ts_define_type value_ttype}} {
|
||||
let value = new {{db_ts_define_type value_ttype}}()
|
||||
{{db_ts_compatible_deserialize_without_segment 'buf' 'value' value_ttype}}
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export class {{name}} {
|
||||
static readonly _table = new {{internal_table_type}}();
|
||||
static get table(): TxnTableGeneric<{{db_ts_define_type key_ttype}},{{db_ts_define_type value_ttype}}> { return this._table }
|
||||
|
||||
static getAsync(key: {{db_ts_define_type key_ttype}}): Promise<{{db_ts_define_type value_ttype}}> {
|
||||
return {{name}}._table.getAsync(key);
|
||||
}
|
||||
|
||||
static createIfNotExistAsync(key: {{db_ts_define_type key_ttype}}): Promise<{{db_ts_define_type value_ttype}}> {
|
||||
return {{name}}._table.createIfNotExistAsync(key);
|
||||
}
|
||||
|
||||
static insertAsync(key: {{db_ts_define_type key_ttype}}, value: {{db_ts_define_type value_ttype}}): Promise<void> {
|
||||
return {{name}}._table.insertAsync(key, value);
|
||||
}
|
||||
|
||||
static removeAsync(key: {{db_ts_define_type key_ttype}}): Promise<void> {
|
||||
return {{name}}._table.removeAsync(key);
|
||||
}
|
||||
|
||||
static put(key: {{db_ts_define_type key_ttype}}, value: {{db_ts_define_type value_ttype}}): Promise<void> {
|
||||
return {{name}}._table.putAsync(key, value);
|
||||
}
|
||||
|
||||
static selectAsync(key: {{db_ts_define_type key_ttype}}): Promise<{{db_ts_define_type value_ttype}}> {
|
||||
return {{name}}._table.selectAsync(key);
|
||||
}
|
||||
}
|
||||
|
||||
{{x.typescript_namespace_end}}
|
@@ -0,0 +1,8 @@
|
||||
|
||||
export class {{name}} {
|
||||
static readonly tableList: TxnTable[] = [
|
||||
{{~ for table in tables~}}
|
||||
{{table.full_name}}.table,
|
||||
{{~end}}
|
||||
]
|
||||
}
|
108
Luban/Luban.ClientServer/Templates/proto/cs/bean.tpl
Normal file
108
Luban/Luban.ClientServer/Templates/proto/cs/bean.tpl
Normal file
@@ -0,0 +1,108 @@
|
||||
{{
|
||||
is_value_type = x.is_value_type
|
||||
is_abstract_type = x.is_abstract_type
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
parent = x.parent
|
||||
fields = x.fields
|
||||
hierarchy_fields = x.hierarchy_fields
|
||||
}}
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{if is_value_type}}struct{{else}}{{x.cs_class_modifier}} class{{end}} {{name}} : {{if parent_def_type}} {{parent}} {{else}} Bright.Serialization.BeanBase {{end}}
|
||||
{
|
||||
{{~if !is_value_type~}}
|
||||
public {{name}}()
|
||||
{
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
public {{name}}(Bright.Common.NotNullInitialization _) {{if parent_def_type}} : base(_) {{end}}
|
||||
{
|
||||
{{~ for field in fields ~}}
|
||||
{{~if cs_need_init field.ctype~}}
|
||||
{{cs_init_field_ctor_value field.convention_name field.ctype}}
|
||||
{{~else if is_value_type~}}
|
||||
{{field.convention_name}} = default;
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public static void Serialize{{name}}(ByteBuf _buf, {{name}} x)
|
||||
{
|
||||
{{~if is_abstract_type~}}
|
||||
_buf.WriteInt(x.GetTypeId());
|
||||
x.Serialize(_buf);
|
||||
{{~else~}}
|
||||
x.Serialize(_buf);
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public static {{name}} Deserialize{{name}}(ByteBuf _buf)
|
||||
{
|
||||
{{~if is_abstract_type~}}
|
||||
{{full_name}} x;
|
||||
switch (_buf.ReadInt())
|
||||
{
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name}}.__ID__: x = new {{child.full_name}}(); break;
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
x.Deserialize(_buf);
|
||||
{{~else~}}
|
||||
var x = new {{full_name}}();
|
||||
x.Deserialize(_buf);
|
||||
{{~end~}}
|
||||
return x;
|
||||
}
|
||||
|
||||
{{~ for field in fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{cs_define_type field.ctype}} {{field.convention_name}};
|
||||
|
||||
{{~end~}}
|
||||
|
||||
{{~if !is_abstract_type~}}
|
||||
public const int __ID__ = {{x.id}};
|
||||
public override int GetTypeId() => __ID__;
|
||||
|
||||
public override void Serialize(ByteBuf _buf)
|
||||
{
|
||||
{{~ for field in hierarchy_fields ~}}
|
||||
{{cs_serialize '_buf' field.convention_name field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override void Deserialize(ByteBuf _buf)
|
||||
{
|
||||
{{~ for field in hierarchy_fields ~}}
|
||||
{{cs_deserialize '_buf' field.convention_name field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{{full_name}}{ "
|
||||
{{~ for field in hierarchy_fields ~}}
|
||||
+ "{{field.convention_name}}:" + {{cs_to_string field.convention_name field.ctype}} + ","
|
||||
{{~end~}}
|
||||
+ "}";
|
||||
}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
}
|
81
Luban/Luban.ClientServer/Templates/proto/cs/proto.tpl
Normal file
81
Luban/Luban.ClientServer/Templates/proto/cs/proto.tpl
Normal file
@@ -0,0 +1,81 @@
|
||||
{{
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent = x.parent
|
||||
fields = x.fields
|
||||
}}
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public sealed class {{name}} : Bright.Net.Codecs.Protocol
|
||||
{
|
||||
{{~ for field in fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{cs_define_type field.ctype}} {{field.convention_name}};
|
||||
|
||||
{{~end~}}
|
||||
|
||||
public {{name}}()
|
||||
{
|
||||
}
|
||||
|
||||
public {{name}}(Bright.Common.NotNullInitialization _)
|
||||
{
|
||||
{{~ for field in fields ~}}
|
||||
{{~if cs_need_init field.ctype~}}
|
||||
{{cs_init_field_ctor_value field.convention_name field.ctype}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
public const int __ID__ = {{x.id}};
|
||||
|
||||
public override int GetTypeId()
|
||||
{
|
||||
return __ID__;
|
||||
}
|
||||
|
||||
public override void Serialize(ByteBuf _buf)
|
||||
{
|
||||
{{~ for field in fields ~}}
|
||||
{{cs_serialize '_buf' field.convention_name field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override void Deserialize(ByteBuf _buf)
|
||||
{
|
||||
{{~ for field in fields ~}}
|
||||
{{cs_deserialize '_buf' field.convention_name field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public override object Clone()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{{full_name}}{ "
|
||||
{{~ for field in fields ~}}
|
||||
+ "{{field.convention_name}}:" + {{cs_to_string field.convention_name field.ctype}} + ","
|
||||
{{~end~}}
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
47
Luban/Luban.ClientServer/Templates/proto/cs/rpc.tpl
Normal file
47
Luban/Luban.ClientServer/Templates/proto/cs/rpc.tpl
Normal file
@@ -0,0 +1,47 @@
|
||||
{{
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent = x.parent
|
||||
fields = x.fields
|
||||
targ_type = x.targ_type
|
||||
tres_type = x.tres_type
|
||||
}}
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public sealed class {{name}} : Bright.Net.Codecs.Rpc<{{cs_define_type targ_type}}, {{cs_define_type tres_type}}>
|
||||
{
|
||||
public {{name}}()
|
||||
{
|
||||
}
|
||||
|
||||
public const int __ID__ = {{x.id}};
|
||||
|
||||
public override int GetTypeId()
|
||||
{
|
||||
return __ID__;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public override object Clone()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{{full_name}}{%{ {{arg:{Arg},res:{Res} }} }%}";
|
||||
}
|
||||
}
|
||||
}
|
19
Luban/Luban.ClientServer/Templates/proto/cs/stub.tpl
Normal file
19
Luban/Luban.ClientServer/Templates/proto/cs/stub.tpl
Normal file
@@ -0,0 +1,19 @@
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{namespace}}
|
||||
{
|
||||
public static class {{name}}
|
||||
{
|
||||
public static System.Collections.Generic.Dictionary<int, Bright.Net.Codecs.ProtocolCreator> Factories { get; } = new System.Collections.Generic.Dictionary<int, Bright.Net.Codecs.ProtocolCreator>
|
||||
{
|
||||
{{~ for proto in protos ~}}
|
||||
[{{proto.full_name}}.__ID__] = () => new {{proto.full_name}}(),
|
||||
{{~end~}}
|
||||
|
||||
{{~ for rpc in rpcs ~}}
|
||||
[{{rpc.full_name}}.__ID__] = () => new {{rpc.full_name}}(),
|
||||
{{~end~}}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
74
Luban/Luban.ClientServer/Templates/proto/go/bean.tpl
Normal file
74
Luban/Luban.ClientServer/Templates/proto/go/bean.tpl
Normal file
@@ -0,0 +1,74 @@
|
||||
{{-
|
||||
go_full_name = x.go_full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
is_abstract_type = x.is_abstract_type
|
||||
hierarchy_fields = x.hierarchy_fields
|
||||
hierarchy_not_abstract_children = x.hierarchy_not_abstract_children
|
||||
-}}
|
||||
|
||||
package {{x.top_module}}
|
||||
|
||||
import (
|
||||
"bright/serialization"
|
||||
)
|
||||
|
||||
{{x.go_bin_import}}
|
||||
|
||||
type {{go_full_name}} struct {
|
||||
{{~for field in hierarchy_fields ~}}
|
||||
{{field.convention_name}} {{go_define_type field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
const TypeId_{{go_full_name}} = {{x.id}}
|
||||
|
||||
func (*{{go_full_name}}) GetTypeId() int32 {
|
||||
return {{x.id}}
|
||||
}
|
||||
|
||||
func (_v *{{go_full_name}})Serialize(_buf *serialization.ByteBuf) {
|
||||
{{~for field in hierarchy_fields ~}}
|
||||
{{go_serialize_field field.ctype ("_v." + field.convention_name) '_buf'}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
func (_v *{{go_full_name}})Deserialize(_buf *serialization.ByteBuf) (err error) {
|
||||
{{~for field in hierarchy_fields ~}}
|
||||
{{go_deserialize_field field.ctype ("_v." + field.convention_name) '_buf' 'err'}}
|
||||
{{~end~}}
|
||||
return
|
||||
}
|
||||
|
||||
{{~if is_abstract_type~}}
|
||||
func Serialize{{go_full_name}}(_v interface{}, _buf *serialization.ByteBuf) {
|
||||
_b := _v.(serialization.ISerializable)
|
||||
_buf.WriteInt(_b.GetTypeId())
|
||||
_b.Serialize(_buf)
|
||||
}
|
||||
|
||||
func Deserialize{{go_full_name}}(_buf *serialization.ByteBuf) (_v serialization.ISerializable, err error) {
|
||||
var id int32
|
||||
if id, err = _buf.ReadInt() ; err != nil {
|
||||
return
|
||||
}
|
||||
switch id {
|
||||
{{~for child in hierarchy_not_abstract_children~}}
|
||||
case {{child.id}}: _v = &{{child.go_full_name}}{}; if err = _v.Deserialize(_buf); err != nil { return nil, err } else { return }
|
||||
{{~end~}}
|
||||
default: return nil, errors.New("unknown type id")
|
||||
}
|
||||
}
|
||||
{{~else~}}
|
||||
func Serialize{{go_full_name}}(_v serialization.ISerializable, _buf *serialization.ByteBuf) {
|
||||
_v.Serialize(_buf)
|
||||
}
|
||||
|
||||
func Deserialize{{go_full_name}}(_buf *serialization.ByteBuf) (*{{go_full_name}}, error) {
|
||||
v := &{{go_full_name}}{}
|
||||
if err := v.Deserialize(_buf); err == nil {
|
||||
return v, nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
{{~end~}}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user