Start TEngine3.0

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

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

View File

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

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

View File

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

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

View File

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

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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~}}

View 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~}}

View 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~}}

View 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
}

View 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~}}

View 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~}}

View 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
}

View 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~}}
+ "}";
}
}

View 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~}}
}

View File

@@ -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~}}
}
}

View 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~}}
+ "}";
}
}

View File

@@ -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~}}
}

View File

@@ -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~}}
}
}

View 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 }

View 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

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