fix GetDiff: repair marking dirty fields for removed ids

This commit is contained in:
Pavel Merzlyakov 2023-11-03 15:22:02 +03:00
parent be6af575c3
commit 9499eae42b
2 changed files with 36 additions and 3 deletions

View File

@ -82,6 +82,26 @@ function _add_twig_support(\Twig\Environment $twig)
return $v;
}
));
$twig->addFunction(new \Twig\TwigFunction('field_index',
function(\mtgMetaStruct $s, string $f): int
{
$idx = get_field_index($s, $f);
if($idx == -1)
{
throw new Exception("field `$f` not found in `{$s->getName()}`");
}
return $idx;
}
));
$twig->addFunction(new \Twig\TwigFunction('find_struct',
function(string $name) use ($twig): \mtgMetaStruct
{
$meta = $twig->getGlobals()['meta'];
$unit = $meta->findUnit($name);
return $unit->object;
}
));
$twig->addFilter(new \Twig\TwigFilter('cs_type',
function($type)
{
@ -619,3 +639,16 @@ function get_all_declarable_accessor_interfaces(\mtgMetaInfo $info)
return $all;
}
function get_field_index(\mtgMetaStruct $struct, string $field_name): int
{
$idx = -1;
foreach($struct->getFields() as $field)
{
$idx++;
if($field->getName() == $field_name)
{
return $idx;
}
}
return -1;
}

View File

@ -395,7 +395,7 @@ public class {{o.name}} : IRpc
{% set field_idx = field_idx + 1 %}
{%- if not has_token(f, 'nodiff') -%}
{{_self.field_diff(f, field_idx)}}
{{_self.field_diff(f, field_idx, o)}}
{%- endif -%}
{% endfor %}
@ -561,7 +561,7 @@ public class {{o.name}} : IRpc
{% endmacro %}
{%- macro field_diff(f, field_idx) -%}
{%- macro field_diff(f, field_idx, o) -%}
{% if f.type is instanceof('\\mtgMetaStruct') %}
{%- if not has_token(f.type, 'POD') -%}
@ -594,7 +594,7 @@ public class {{o.name}} : IRpc
if(diff != null)
MetaIO.SetFieldDirty(ref diff.fields_mask, {{field_idx}});
if(removed != null && removed.{{f.name}}.Count > 0)
MetaIO.SetFieldDirty(ref removed.fields_mask, {{field_idx}});
MetaIO.SetFieldDirty(ref removed.fields_mask, {{ field_index(find_struct(o.name ~ 'RemovedIds'), f.name) }});
}
{% elseif f.type is instanceof('\\mtgBuiltinType') %}
if(diff != null)