From d72e5e226dde7004d9532f564aa83333bc5d875a Mon Sep 17 00:00:00 2001 From: Lukas Rieger Date: Thu, 7 Nov 2024 02:50:14 +0100 Subject: [PATCH] (try to) fix setter --- .../src/class/data_models/field_var.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/godot-macros/src/class/data_models/field_var.rs b/godot-macros/src/class/data_models/field_var.rs index 74918a500..14d4f2728 100644 --- a/godot-macros/src/class/data_models/field_var.rs +++ b/godot-macros/src/class/data_models/field_var.rs @@ -212,22 +212,21 @@ impl GetterSetterImpl { fn #function_name(&mut self, #field_name: <#field_type as ::godot::meta::GodotConvert>::Via) }; - let notify_block = match notify { + let function_body_set = quote! { + <#field_type as ::godot::register::property::Var>::set_property(&mut self.#field_name, #field_name); + }; + + function_body = match notify { Some(ident) => { quote! { - if self.#field_name != #field_name { + let prev_value = self.#field_name; + #function_body_set + if prev_value != self.#field_name { self.#ident(); } } }, - None => { - quote! { } - } - }; - - function_body = quote! { - <#field_type as ::godot::register::property::Var>::set_property(&mut self.#field_name, #field_name); - #notify_block + None => function_body_set }; } }