From 8a1fb3126e11e0cb5aedcae3c9d21a55fa6048f3 Mon Sep 17 00:00:00 2001 From: "n.pankin" Date: Mon, 12 Aug 2024 12:05:16 +0300 Subject: [PATCH] added implementation of flt_i18n getter setter generation --- tpl/macro.twig | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/tpl/macro.twig b/tpl/macro.twig index e8bba25..d99b178 100644 --- a/tpl/macro.twig +++ b/tpl/macro.twig @@ -160,12 +160,23 @@ public FieldsMask fields_mask; {%- macro decl_struct_field(o, f) -%} {{_self.attributes(f)}} -public {{f.type|cs_type|obscure_type(f)}} {{f.name}} {% if not has_token(o, 'POD') -%} {{_self.decl_init_value(f)}} {%- endif -%}; +{% if has_token(f, 'flt_i18n') -%} +{{f.type}} _{{f.name}} = ""; +List<{{f.type}}> __{{f.name}} = new List<{{f.type}}>(); +{%- endif ~%} +public {{f.type|cs_type|obscure_type(f)}} {{f.name}} {% if not has_token(o, 'POD') -%} {{_self.decl_init_value(f)}} {%- endif -%} {% if not has_token(f, 'flt_i18n') -%};{%- endif -%} {%- endmacro -%} {% macro decl_init_value(f) %} {%- if f.type is instanceof('\\mtgBuiltinType') -%} -{%- if f.type.isstring -%} = ""{%- endif -%} +{%- if f.type.isstring -%} +{% if has_token(f, 'flt_i18n') -%} +{get{return plural_{{f.name}}(double.NaN);}set{_{{f.name}}=value;}} +{{f.type}} plural_{{f.name}}(double force_n){return MetaI18N.I18NPick(_{{f.name}},__{{f.name}},"#",force_n);} +{%- else -%} += "" +{%- endif ~%} +{%- endif -%} {%- else -%} {%- if has_token(f, 'default') and token(f, 'default') == 'null' -%} /*null*/ @@ -180,7 +191,12 @@ public {{f.type|cs_type|obscure_type(f)}} {{f.name}} {% if not has_token(o, 'POD base.Reset(); {%- endif -%} {%- for f in o.fields ~%} -{{var_reset(f.name, f.type, token_or(f, 'default', null))}} +{% set fname = f.name %} +{% if has_token(f, 'flt_i18n') -%} +{% set fname = '_' ~ f.name %} +if(_{{fname}} == null) _{{fname}} = new(); else _{{fname}}.Clear(); +{%- endif ~%} +{{var_reset(fname, f.type, token_or(f, 'default', null))}} {%- endfor -%} {%- if has_token(o, 'bitfields') ~%} ResetFieldMask(); @@ -279,7 +295,11 @@ bitctx.SyncMaskHeader(); base.SyncFields(ctx); {%- endif -%} {%- for f in o.fields ~%} -{{var_sync(f.name, f.type, 'ctx', f.tokens, get_sync_opts(o, 'bitctx'))}} +{% set fname = f.name %} +{% if has_token(f, 'flt_i18n') -%} +{% set fname = '_' ~ f.name %} +{%- endif -%} +{{var_sync(fname, f.type, 'ctx', f.tokens, get_sync_opts(o, 'bitctx'))}} {%- endfor -%} {%- endmacro -%}