@@ -142,6 +142,7 @@ pub fn transform_trait_impl(original_impl: venial::Impl) -> ParseResult<TokenStr
142
142
}
143
143
144
144
"on_notification" => {
145
+ let inactive_class_early_return = make_inactive_class_check ( TokenStream :: new ( ) ) ;
145
146
on_notification_impl = quote ! {
146
147
#on_notification_impl
147
148
@@ -150,10 +151,7 @@ pub fn transform_trait_impl(original_impl: venial::Impl) -> ParseResult<TokenStr
150
151
fn __godot_notification( & mut self , what: i32 ) {
151
152
use :: godot:: obj:: UserClass as _;
152
153
153
- #[ cfg( before_api = "4.3" ) ]
154
- if :: godot:: private:: is_class_inactive( Self :: __config( ) . is_tool) {
155
- return ;
156
- }
154
+ #inactive_class_early_return
157
155
158
156
<Self as #trait_path>:: on_notification( self , what. into( ) )
159
157
}
@@ -168,16 +166,14 @@ pub fn transform_trait_impl(original_impl: venial::Impl) -> ParseResult<TokenStr
168
166
}
169
167
170
168
"get_property" => {
169
+ let inactive_class_early_return = make_inactive_class_check ( quote ! { None } ) ;
171
170
get_property_impl = quote ! {
172
171
#( #cfg_attrs) *
173
172
impl :: godot:: obj:: cap:: GodotGet for #class_name {
174
173
fn __godot_get_property( & self , property: :: godot:: builtin:: StringName ) -> Option <:: godot:: builtin:: Variant > {
175
174
use :: godot:: obj:: UserClass as _;
176
175
177
- #[ cfg( before_api = "4.3" ) ]
178
- if :: godot:: private:: is_class_inactive( Self :: __config( ) . is_tool) {
179
- return None ;
180
- }
176
+ #inactive_class_early_return
181
177
182
178
<Self as #trait_path>:: get_property( self , property)
183
179
}
@@ -191,16 +187,14 @@ pub fn transform_trait_impl(original_impl: venial::Impl) -> ParseResult<TokenStr
191
187
}
192
188
193
189
"set_property" => {
190
+ let inactive_class_early_return = make_inactive_class_check ( quote ! { false } ) ;
194
191
set_property_impl = quote ! {
195
192
#( #cfg_attrs) *
196
193
impl :: godot:: obj:: cap:: GodotSet for #class_name {
197
194
fn __godot_set_property( & mut self , property: :: godot:: builtin:: StringName , value: :: godot:: builtin:: Variant ) -> bool {
198
195
use :: godot:: obj:: UserClass as _;
199
196
200
- #[ cfg( before_api = "4.3" ) ]
201
- if :: godot:: private:: is_class_inactive( Self :: __config( ) . is_tool) {
202
- return false ;
203
- }
197
+ #inactive_class_early_return
204
198
205
199
<Self as #trait_path>:: set_property( self , property, value)
206
200
}
@@ -227,19 +221,15 @@ pub fn transform_trait_impl(original_impl: venial::Impl) -> ParseResult<TokenStr
227
221
228
222
#[ cfg( since_api = "4.3" ) ]
229
223
"get_property_list" => {
224
+ // `get_property_list` is only supported in Godot API >= 4.3. If we add support for `get_property_list` to earlier
225
+ // versions of Godot then this code is still needed and should be uncommented.
226
+ //
227
+ // let inactive_class_early_return = make_inactive_class_check(false);
230
228
get_property_list_impl = quote ! {
231
229
#( #cfg_attrs) *
232
230
impl :: godot:: obj:: cap:: GodotGetPropertyList for #class_name {
233
231
fn __godot_get_property_list( & mut self ) -> Vec <:: godot:: meta:: PropertyInfo > {
234
- // `get_property_list` is only supported in Godot API >= 4.3. If we add support for `get_property_list` to earlier
235
- // versions of Godot then this code is still needed and should be uncommented.
236
- //
237
- // use ::godot::obj::UserClass as _;
238
- //
239
- // #[cfg(before_api = "4.3")]
240
- // if ::godot::private::is_class_inactive(Self::__config().is_tool) {
241
- // return false;
242
- // }
232
+ // #inactive_class_early_return
243
233
244
234
<Self as #trait_path>:: get_property_list( self )
245
235
}
@@ -257,16 +247,14 @@ pub fn transform_trait_impl(original_impl: venial::Impl) -> ParseResult<TokenStr
257
247
}
258
248
259
249
"property_get_revert" => {
250
+ let inactive_class_early_return = make_inactive_class_check ( quote ! { None } ) ;
260
251
property_get_revert_impl = quote ! {
261
252
#( #cfg_attrs) *
262
253
impl :: godot:: obj:: cap:: GodotPropertyGetRevert for #class_name {
263
254
fn __godot_property_get_revert( & self , property: StringName ) -> Option <:: godot:: builtin:: Variant > {
264
255
use :: godot:: obj:: UserClass as _;
265
256
266
- #[ cfg( before_api = "4.3" ) ]
267
- if :: godot:: private:: is_class_inactive( Self :: __config( ) . is_tool) {
268
- return None ;
269
- }
257
+ #inactive_class_early_return
270
258
271
259
<Self as #trait_path>:: property_get_revert( self , property)
272
260
}
@@ -435,3 +423,17 @@ fn convert_to_match_expression_or_none(tokens: Option<TokenStream>) -> TokenStre
435
423
quote ! { None }
436
424
}
437
425
}
426
+
427
+ #[ cfg( before_api = "4.3" ) ]
428
+ fn make_inactive_class_check ( return_value : TokenStream ) -> TokenStream {
429
+ quote ! {
430
+ if :: godot:: private:: is_class_inactive( Self :: __config( ) . is_tool) {
431
+ return #return_value;
432
+ }
433
+ }
434
+ }
435
+
436
+ #[ cfg( since_api = "4.3" ) ]
437
+ fn make_inactive_class_check ( _return_value : TokenStream ) -> TokenStream {
438
+ TokenStream :: new ( )
439
+ }
0 commit comments