【优化】将tpl文件中__type__改为 {{x.json_type_name_key}},方便统一调整。

main
walon 2022-02-10 18:06:29 +08:00
parent 6b1669e050
commit e6203df5b3
12 changed files with 17 additions and 93 deletions

View File

@ -36,7 +36,7 @@ namespace Luban.Job.Cfg.DataConverts
{ {
title.AddSubTitle(new Title() title.AddSubTitle(new Title()
{ {
Name = "__type__", Name = DefBean.TYPE_NAME_KEY,
FromIndex = lastColumn + 1, FromIndex = lastColumn + 1,
ToIndex = lastColumn + 1, ToIndex = lastColumn + 1,
Tags = new Dictionary<string, string>(), Tags = new Dictionary<string, string>(),
@ -164,85 +164,6 @@ namespace Luban.Job.Cfg.DataConverts
title.Tags.Add("sep", "|"); title.Tags.Add("sep", "|");
} }
} }
//int lastColumn = column - 1;
//if (type.IsDynamic)
//{
// title.AddSubTitle(new Title()
// {
// Name = "__type__",
// FromIndex = lastColumn + 1,
// ToIndex = lastColumn + 1,
// Tags = new Dictionary<string, string>(),
// });
// ++lastColumn;
//}
//foreach (var f in type.Bean.HierarchyFields)
//{
// int startColumn = lastColumn + 1;
// var subTitle = new Title()
// {
// Name = f.Name,
// FromIndex = startColumn,
// ToIndex = startColumn,
// Tags = new Dictionary<string, string>(),
// };
// if (f.CType.Tags.TryGetValue("sep", out var sep))
// {
// subTitle.Tags.Add("sep", sep);
// }
// if (f.CType.Tags.TryGetValue("multi_rows", out var multiRows))
// {
// subTitle.Tags.Add("multiRows", multiRows);
// }
// f.CType.Apply(this, subTitle, startColumn);
// lastColumn = subTitle.ToIndex;
// title.AddSubTitle(subTitle);
//}
//title.ToIndex = Math.Max(lastColumn, column);
//int maxFieldNum = 20;
//if (type.IsDynamic)
//{
// if (!title.Tags.ContainsKey("sep"))
// {
// title.Tags.Add("sep", "|");
// }
// //var maxFieldCount = type.Bean.HierarchyNotAbstractChildren.Max(c => c.HierarchyFields.Count);
// //var fields = type.Bean.HierarchyNotAbstractChildren.SelectMany(c => c.HierarchyFields).Select(f => f.Name).ToHashSet();
// title.ToIndex = column;
//}
//else
//{
// int lastColumn = column - 1;
// foreach (var f in type.Bean.HierarchyFields)
// {
// int startColumn = lastColumn + 1;
// var subTitle = new Title()
// {
// Name = f.Name,
// FromIndex = startColumn,
// ToIndex = startColumn,
// Tags = new Dictionary<string, string>(),
// };
// if (f.CType.Tags.TryGetValue("sep", out var sep))
// {
// subTitle.Tags.Add("sep", sep);
// }
// if (f.CType.Tags.TryGetValue("multi_rows", out var multiRows))
// {
// subTitle.Tags.Add("multiRows", multiRows);
// }
// f.CType.Apply(this, subTitle, startColumn);
// lastColumn = subTitle.ToIndex;
// title.AddSubTitle(subTitle);
// }
// title.ToIndex = Math.Max(lastColumn, column);
//}
} }
public void Accept(TArray type, Title title, int column) public void Accept(TArray type, Title title, int column)

View File

@ -12,11 +12,14 @@ namespace Luban.Job.Cfg.Defs
{ {
public const string TYPE_NAME_KEY = "__type__"; public const string TYPE_NAME_KEY = "__type__";
public const string BEAN_NULL_STR = "null"; public const string BEAN_NULL_STR = "null";
public const string BEAN_NOT_NULL_STR = "{}"; public const string BEAN_NOT_NULL_STR = "{}";
public string JsonTypeNameKey => TYPE_NAME_KEY;
public string Alias { get; } public string Alias { get; }
public bool IsMultiRow { get; set; } public bool IsMultiRow { get; set; }

View File

@ -170,7 +170,7 @@ namespace editor
bool {{type.ue_fname}}::Create(FJsonObject* _json, {{type.ue_fname}}*& result) bool {{type.ue_fname}}::Create(FJsonObject* _json, {{type.ue_fname}}*& result)
{ {
FString type; FString type;
if (_json->TryGetStringField(FString(""__type__""), type)) if (_json->TryGetStringField(FString(""{{type.json_type_name_key}}""), type))
{ {
{{~for child in type.hierarchy_not_abstract_children~}} {{~for child in type.hierarchy_not_abstract_children~}}
if (type == ""{{cs_impl_data_type child x}}"") if (type == ""{{cs_impl_data_type child x}}"")
@ -211,7 +211,7 @@ namespace editor
bool {{type.ue_fname}}::Save(FJsonObject*& result) bool {{type.ue_fname}}::Save(FJsonObject*& result)
{ {
auto _json = new FJsonObject(); auto _json = new FJsonObject();
_json->SetStringField(""__type__"", ""{{type.name}}""); _json->SetStringField(""{{type.json_type_name_key}}"", ""{{type.name}}"");
{{~for field in type.hierarchy_fields~}} {{~for field in type.hierarchy_fields~}}
{{field.editor_ue_cpp_save}} {{field.editor_ue_cpp_save}}

View File

@ -45,7 +45,7 @@ public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {
public static {{name}} Deserialize{{name}}(JsonElement _json) public static {{name}} Deserialize{{name}}(JsonElement _json)
{ {
{{~if x.is_abstract_type~}} {{~if x.is_abstract_type~}}
switch (_json.GetProperty("__type__").GetString()) switch (_json.GetProperty("{{x.json_type_name_key}}").GetString())
{ {
{{~for child in x.hierarchy_not_abstract_children~}} {{~for child in x.hierarchy_not_abstract_children~}}
case "{{cs_impl_data_type child x}}": return new {{child.full_name}}(_json); case "{{cs_impl_data_type child x}}": return new {{child.full_name}}(_json);

View File

@ -70,7 +70,7 @@ public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {
public static {{name}} LoadJson{{name}}(SimpleJSON.JSONNode _json) public static {{name}} LoadJson{{name}}(SimpleJSON.JSONNode _json)
{ {
{{~if x.is_abstract_type~}} {{~if x.is_abstract_type~}}
string type = _json["__type__"]; string type = _json["{{x.json_type_name_key}}"];
{{name}} obj; {{name}} obj;
switch (type) switch (type)
{ {
@ -89,7 +89,7 @@ public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {
public static void SaveJson{{name}}({{name}} _obj, SimpleJSON.JSONNode _json) public static void SaveJson{{name}}({{name}} _obj, SimpleJSON.JSONNode _json)
{ {
{{~if x.is_abstract_type~}} {{~if x.is_abstract_type~}}
_json["__type__"] = _obj.GetType().Name; _json["{{x.json_type_name_key}}"] = _obj.GetType().Name;
{{~end~}} {{~end~}}
_obj.SaveJson((SimpleJSON.JSONObject)_json); _obj.SaveJson((SimpleJSON.JSONObject)_json);
} }

View File

@ -45,7 +45,7 @@ public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {
public static {{name}} Deserialize{{name}}(JSONNode _json) public static {{name}} Deserialize{{name}}(JSONNode _json)
{ {
{{~if x.is_abstract_type~}} {{~if x.is_abstract_type~}}
string type = _json["__type__"]; string type = _json["{{x.json_type_name_key}}"];
switch (type) switch (type)
{ {
{{~for child in x.hierarchy_not_abstract_children~}} {{~for child in x.hierarchy_not_abstract_children~}}

View File

@ -33,7 +33,7 @@ func (_v *{{go_full_name}})Deserialize(_buf map[string]interface{}) (err error)
func Deserialize{{go_full_name}}(_buf map[string]interface{}) (interface{}, error) { func Deserialize{{go_full_name}}(_buf map[string]interface{}) (interface{}, error) {
var id string var id string
var _ok_ bool var _ok_ bool
if id, _ok_ = _buf["__type__"].(string) ; !_ok_ { if id, _ok_ = _buf["{{x.json_type_name_key}}"].(string) ; !_ok_ {
return nil, errors.New("type id missing") return nil, errors.New("type id missing")
} }
switch id { switch id {

View File

@ -46,7 +46,7 @@ public {{x.java_class_modifier}} class {{name}}{{if parent_def_type}} extends {{
public static {{name}} deserialize{{name}}(JsonObject __json__) { public static {{name}} deserialize{{name}}(JsonObject __json__) {
{{~if x.is_abstract_type~}} {{~if x.is_abstract_type~}}
switch (__json__.get("__type__").getAsString()) { switch (__json__.get("{{x.json_type_name_key}}").getAsString()) {
{{~for child in x.hierarchy_not_abstract_children~}} {{~for child in x.hierarchy_not_abstract_children~}}
case "{{cs_impl_data_type child x}}": return new {{child.full_name_with_top_module}}(__json__); case "{{cs_impl_data_type child x}}": return new {{child.full_name_with_top_module}}(__json__);
{{~end~}} {{~end~}}

View File

@ -20,7 +20,7 @@ class {{name}} {{if parent_def_type}}({{parent_def_type.py_full_name}}){{end}}:
'{{cs_impl_data_type child x}}': {{child.py_full_name}}, '{{cs_impl_data_type child x}}': {{child.py_full_name}},
{{~end~}} {{~end~}}
} }
type = _json_['__type__'] type = _json_['{{x.json_type_name_key}}']
child = {{name}}._childrenTypes.get(type) child = {{name}}._childrenTypes.get(type)
if child != None: if child != None:
return child(_json_) return child(_json_)

View File

@ -20,7 +20,7 @@ class {{name}} {{if parent_def_type}}({{parent_def_type.py_full_name}}){{else if
'{{cs_impl_data_type child x}}': {{child.py_full_name}}, '{{cs_impl_data_type child x}}': {{child.py_full_name}},
{{~end~}} {{~end~}}
} }
type = _json_['__type__'] type = _json_['{{x.json_type_name_key}}']
child = {{name}}._childrenTypes.get(type) child = {{name}}._childrenTypes.get(type)
if child != None: if child != None:
return child(_json_) return child(_json_)

View File

@ -41,7 +41,7 @@ pub enum {{name}} {
impl {{name}} { impl {{name}} {
#[allow(dead_code)] #[allow(dead_code)]
pub fn new(__js: &json::JsonValue) -> Result<{{name}}, LoadError> { pub fn new(__js: &json::JsonValue) -> Result<{{name}}, LoadError> {
let __b = match __js["__type__"].as_str() { let __b = match __js["{{x.json_type_name_key}}"].as_str() {
Some(type_name) => match type_name { Some(type_name) => match type_name {
{{~for child in x.hierarchy_not_abstract_children~}} {{~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)?'}})), "{{cs_impl_data_type child x}}" => {{name}}::{{child.name}}(Box::new({{child.rust_full_name + '::new(&__js)?'}})),

View File

@ -15,7 +15,7 @@
export {{if x.is_abstract_type}}abstract {{end}}class {{name}}{{if parent_def_type}} extends {{x.parent}}{{end}} { export {{if x.is_abstract_type}}abstract {{end}}class {{name}}{{if parent_def_type}} extends {{x.parent}}{{end}} {
{{~if x.is_abstract_type~}} {{~if x.is_abstract_type~}}
static constructorFrom(_json_: any): {{name}}{ static constructorFrom(_json_: any): {{name}}{
switch (_json_.__type__) { switch (_json_["{{x.json_type_name_key}}"]) {
{{~ for child in x.hierarchy_not_abstract_children~}} {{~ for child in x.hierarchy_not_abstract_children~}}
case '{{cs_impl_data_type child x}}': return new {{child.full_name}}(_json_) case '{{cs_impl_data_type child x}}': return new {{child.full_name}}(_json_)
{{~end~}} {{~end~}}