【特性】cfg cs_unity_json支持动态本地化
parent
c5bd179a82
commit
f5e9eef725
|
|
@ -1,3 +1,4 @@
|
||||||
|
using Luban.Job.Cfg.Datas;
|
||||||
using Luban.Job.Common.Types;
|
using Luban.Job.Common.Types;
|
||||||
using Luban.Job.Common.TypeVisitors;
|
using Luban.Job.Common.TypeVisitors;
|
||||||
using System;
|
using System;
|
||||||
|
|
@ -75,7 +76,7 @@ namespace Luban.Job.Cfg.TypeVisitors
|
||||||
|
|
||||||
public string Accept(TText type, string json, string x)
|
public string Accept(TText type, string json, string x)
|
||||||
{
|
{
|
||||||
return $"{{ if(!{json}.IsString) {{ throw new SerializationException(); }} {x} = {json}; }}";
|
return $"{{ if(!{json}[\"{DText.KEY_NAME}\"].IsString) {{ throw new SerializationException(); }} {x}{TText.L10N_FIELD_SUFFIX} = {json}[\"{DText.KEY_NAME}\"]; if(!{json}[\"{DText.TEXT_NAME}\"].IsString) {{ throw new SerializationException(); }} {x} = {json}[\"{DText.TEXT_NAME}\"]; }}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Accept(TBean type, string json, string x)
|
public string Accept(TBean type, string json, string x)
|
||||||
|
|
|
||||||
|
|
@ -62,13 +62,16 @@ public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {
|
||||||
/// {{field.comment}}
|
/// {{field.comment}}
|
||||||
/// </summary>
|
/// </summary>
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
public readonly {{cs_define_type field.ctype}} {{field.cs_style_name}};
|
public {{cs_define_type field.ctype}} {{field.cs_style_name}} { get; private set; }
|
||||||
{{~if field.index_field~}}
|
{{~if field.index_field~}}
|
||||||
public readonly Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}> {{field.cs_style_name}}_Index = new Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}>();
|
public readonly Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}> {{field.cs_style_name}}_Index = new Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}>();
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
{{~if field.gen_ref~}}
|
{{~if field.gen_ref~}}
|
||||||
public {{field.cs_ref_validator_define}}
|
public {{field.cs_ref_validator_define}}
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
|
{{~if field.gen_text_key~}}
|
||||||
|
public {{cs_define_text_key_field field}} { get; }
|
||||||
|
{{~end~}}
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
|
|
||||||
{{~if !x.is_abstract_type~}}
|
{{~if !x.is_abstract_type~}}
|
||||||
|
|
@ -88,10 +91,21 @@ public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {
|
||||||
{{cs_recursive_resolve field '_tables'}}
|
{{cs_recursive_resolve field '_tables'}}
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
OnResolveFinish(_tables);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
partial void OnResolveFinish(Dictionary<string, object> _tables);
|
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()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ namespace {{x.namespace_with_top_module}}
|
||||||
/// {{x.comment}}
|
/// {{x.comment}}
|
||||||
/// </summary>
|
/// </summary>
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
public sealed partial class {{name}}
|
public sealed class {{name}}
|
||||||
{
|
{
|
||||||
{{~if x.is_map_table ~}}
|
{{~if x.is_map_table ~}}
|
||||||
private readonly Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> _dataMap;
|
private readonly Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> _dataMap;
|
||||||
|
|
@ -54,7 +54,14 @@ public sealed partial class {{name}}
|
||||||
{
|
{
|
||||||
v.Resolve(_tables);
|
v.Resolve(_tables);
|
||||||
}
|
}
|
||||||
OnResolveFinish(_tables);
|
}
|
||||||
|
|
||||||
|
public void TranslateText(System.Func<string, string, string> translator)
|
||||||
|
{
|
||||||
|
foreach(var v in _dataList)
|
||||||
|
{
|
||||||
|
v.TranslateText(translator);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{{~else~}}
|
{{~else~}}
|
||||||
|
|
@ -86,12 +93,14 @@ public sealed partial class {{name}}
|
||||||
public void Resolve(Dictionary<string, object> _tables)
|
public void Resolve(Dictionary<string, object> _tables)
|
||||||
{
|
{
|
||||||
_data.Resolve(_tables);
|
_data.Resolve(_tables);
|
||||||
OnResolveFinish(_tables);
|
}
|
||||||
|
|
||||||
|
public void TranslateText(System.Func<string, string, string> translator)
|
||||||
|
{
|
||||||
|
_data.TranslateText(translator);
|
||||||
}
|
}
|
||||||
|
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
|
|
||||||
partial void OnResolveFinish(Dictionary<string, object> _tables);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -31,6 +31,13 @@ public sealed partial class {{name}}
|
||||||
{{table.name}}.Resolve(tables);
|
{{table.name}}.Resolve(tables);
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void TranslateText(System.Func<string, string, string> translator)
|
||||||
|
{
|
||||||
|
{{~for table in tables ~}}
|
||||||
|
{{table.name}}.TranslateText(translator);
|
||||||
|
{{~end~}}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue