From 9027e248b54212268545f4d2f645855dae32cade Mon Sep 17 00:00:00 2001 From: Pavel Merzlyakov Date: Thu, 9 Nov 2023 16:31:55 +0300 Subject: [PATCH] nested structs within table structs supported --- src/codegen.inc.php | 32 +++++++++++++++++++++++++++- tpl/macro.twig | 51 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 78 insertions(+), 5 deletions(-) diff --git a/src/codegen.inc.php b/src/codegen.inc.php index fbc89b9..cecdd20 100644 --- a/src/codegen.inc.php +++ b/src/codegen.inc.php @@ -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; diff --git a/tpl/macro.twig b/tpl/macro.twig index ed72a3f..7dc8b55 100644 --- a/tpl/macro.twig +++ b/tpl/macro.twig @@ -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