nested structs within table structs supported

This commit is contained in:
Pavel Merzlyakov 2023-11-09 16:31:55 +03:00
parent 6e6c9820d3
commit 9027e248b5
2 changed files with 78 additions and 5 deletions

View File

@ -155,7 +155,7 @@ function _add_twig_support(\Twig\Environment $twig)
$twig->addFunction(new \Twig\TwigFunction('get_diff_related_units',
function($o)
{
return get_diff_related_units($o);
return get_all_related_structs($o);
}
));
$twig->addFunction(new \Twig\TwigFunction('get_all_declarable_accessor_interfaces',
@ -520,6 +520,36 @@ function get_diff_related_units(\mtgMetaStruct $struct)
return $result;
}
function get_all_related_structs(\mtgMetaStruct $struct): array
{
$result = array_reduce($struct->getFields(), function(array $structs, \mtgMetaField $field) {
if($field->hasToken('nodiff'))
{
return $structs;
}
$type = $field->getType();
if($type instanceof \mtgArrType)
{
$type = $type->getValue();
}
if($type instanceof \mtgMetaStruct)
{
$structs[] = $type;
}
return $structs;
}, []);
foreach($result as $s)
{
$result = array_merge(get_all_related_structs($s), $result);
}
return $result;
}
class AccessorInterfaceField
{
public $field;

View File

@ -421,6 +421,7 @@ public class {{o.name}} : IRpc
{% endmacro %}
{%- macro diff_methods_for(u) -%}
{% if has_token(u, 'table') %}
static public bool DiffOne(ref {{u.name}} curr, {{u.name}} old)
{
return !{{_self.compare_func_name(u)}}(ref curr, old);
@ -496,6 +497,7 @@ public class {{o.name}} : IRpc
return has_diff;
}
{% endif %}
public static bool {{_self.compare_func_name(u)}}(ref {{u.name}} a, {{u.name}} b)
{
@ -526,24 +528,65 @@ public class {{o.name}} : IRpc
{%- macro field_compare(o, f, field_idx) -%}
{% if f.type is instanceof('\\mtgArrType') ~%}
{% if has_token(o, 'bitfields') ~%}
if(a.{{f.name}} == null ||
b.{{f.name}} == null ||
a.{{f.name}}.Count != b.{{f.name}}.Count)
{
MetaIO.SetFieldDirty(ref a.fields_mask, {{field_idx}});
is_equal = false;
}
else
{
for(int i=0;i<a.{{f.name}}.Count;++i)
{
{%- if f.type.value is instanceof('\\mtgMetaStruct') ~%}
var tmp_{{f.name}} = a.{{f.name}}[i];
if(!IsEqual(ref tmp_{{f.name}}, b.{{f.name}}[i]))
{
MetaIO.SetFieldDirty(ref a.fields_mask, {{field_idx}});
is_equal = false;
break;
}
{%- else -%}
if(a.{{f.name}}[i] != b.{{f.name}}[i])
{
MetaIO.SetFieldDirty(ref a.fields_mask, {{field_idx}});
is_equal = false;
break;
}
{%- endif -%}
}
}
{% else ~%}
if(a.{{f.name}} == null ||
b.{{f.name}} == null ||
a.{{f.name}}.Count != b.{{f.name}}.Count)
return false;
for(int i=0;i<a.{{f.name}}.Count;++i)
{
{%- if f.type.value is instanceof('\\mtgMetaStruct') ~%}
if(!IsEqual(ref a.{{f.name}}[i], b.{{f.name}}[i]))
var tmp_{{f.name}} = a.{{f.name}}[i];
if(!IsEqual(ref tmp_{{f.name}}, b.{{f.name}}[i]))
return false;
{%- else -%}
if(a.{{f.name}}[i] != b.{{f.name}}[i])
if(a.{{f.name}}[i] != b.{{f.name}}[i])
return false;
{%- endif -%}
}
{% endif ~%}
{% elseif f.type is instanceof('\\mtgMetaStruct') ~%}
if(!IsEqual(ref a.{{f.name}}, b.{{f.name}}))
var tmp_{{f.name}} = a.{{f.name}}[i];
if(!IsEqual(ref tmp_{{f.name}}, b.{{f.name}}))
{% if has_token(o, 'bitfields') ~%}
{
MetaIO.SetFieldDirty(ref a.fields_mask, {{field_idx}});
is_equal = false;
}
{% else ~%}
return false;
{% endif ~%}
{% elseif f.type is instanceof('\\mtgBuiltinType') and f.type.isstring ~%}
if((a.{{f.name}} == null ? "" : a.{{f.name}})
!= (b.{{f.name}} == null ? "" : b.{{f.name}}))