8
8
use crate :: context:: Context ;
9
9
use crate :: models:: domain:: TyName ;
10
10
use crate :: models:: json:: JsonClassConstant ;
11
- use crate :: { conv , util} ;
11
+ use crate :: util;
12
12
use proc_macro2:: { Ident , TokenStream } ;
13
- use quote:: { format_ident , quote} ;
13
+ use quote:: quote;
14
14
15
15
pub fn make_notify_methods ( class_name : & TyName , ctx : & mut Context ) -> TokenStream {
16
16
// Note: there are two more methods, but only from Node downwards, not from Object:
@@ -85,10 +85,10 @@ pub fn make_notification_enum(
85
85
c = class_name. rust_ty
86
86
) ;
87
87
88
- let mut notification_enumerators_pascal = Vec :: new ( ) ;
88
+ let mut notification_enumerators_shout = Vec :: new ( ) ;
89
89
let mut notification_enumerators_ord = Vec :: new ( ) ;
90
90
for ( constant_ident, constant_value) in all_constants {
91
- notification_enumerators_pascal . push ( constant_ident) ;
91
+ notification_enumerators_shout . push ( constant_ident) ;
92
92
notification_enumerators_ord. push ( constant_value) ;
93
93
}
94
94
@@ -101,10 +101,11 @@ pub fn make_notification_enum(
101
101
/// Contains the [`Unknown`] variant for forward compatibility.
102
102
#[ derive( Copy , Clone , Eq , PartialEq , Ord , PartialOrd , Hash , Debug ) ]
103
103
#[ repr( i32 ) ]
104
+ #[ allow( non_camel_case_types) ]
104
105
#cfg_attributes
105
106
pub enum #enum_name {
106
107
#(
107
- #notification_enumerators_pascal = #notification_enumerators_ord,
108
+ #notification_enumerators_shout = #notification_enumerators_ord,
108
109
) *
109
110
110
111
/// Since Godot represents notifications as integers, it's always possible that a notification outside the known types
@@ -117,7 +118,7 @@ pub fn make_notification_enum(
117
118
fn from( enumerator: i32 ) -> Self {
118
119
match enumerator {
119
120
#(
120
- #notification_enumerators_ord => Self :: #notification_enumerators_pascal ,
121
+ #notification_enumerators_ord => Self :: #notification_enumerators_shout ,
121
122
) *
122
123
other_int => Self :: Unknown ( other_int) ,
123
124
}
@@ -128,7 +129,7 @@ pub fn make_notification_enum(
128
129
fn from( notification: #enum_name) -> i32 {
129
130
match notification {
130
131
#(
131
- #enum_name:: #notification_enumerators_pascal => #notification_enumerators_ord,
132
+ #enum_name:: #notification_enumerators_shout => #notification_enumerators_ord,
132
133
) *
133
134
#enum_name:: Unknown ( int) => int,
134
135
}
@@ -141,27 +142,27 @@ pub fn make_notification_enum(
141
142
142
143
/// Tries to interpret the constant as a notification one, and transforms it to a Rust identifier on success.
143
144
pub fn try_to_notification ( constant : & JsonClassConstant ) -> Option < Ident > {
144
- constant
145
- . name
146
- . strip_prefix ( "NOTIFICATION_" )
147
- . map ( |s| util:: ident ( & conv:: shout_to_pascal ( s) ) )
145
+ constant. name . strip_prefix ( "NOTIFICATION_" ) . map ( util:: ident) // used to be conv::shout_to_pascal(s)
148
146
}
149
147
150
148
// ----------------------------------------------------------------------------------------------------------------------------------------------
151
149
// Implementation
152
150
153
- /// Workaround for Godot bug https://github.com/godotengine/godot/issues/75839
151
+ /// Workaround for Godot bug https://github.com/godotengine/godot/issues/75839, fixed in 4.2.
154
152
///
155
153
/// Godot has a collision for two notification constants (DRAW, NODE_CACHE_REQUESTED) in the same inheritance branch (as of 4.0.2).
156
154
/// This cannot be represented in a Rust enum, so we merge the two constants into a single enumerator.
157
155
fn workaround_constant_collision ( all_constants : & mut Vec < ( Ident , i32 ) > ) {
156
+ #[ cfg( before_api = "4.2" ) ]
158
157
for first in [ "Draw" , "VisibilityChanged" ] {
159
158
if let Some ( index_of_draw) = all_constants
160
159
. iter ( )
161
160
. position ( |( constant_name, _) | constant_name == first)
162
161
{
163
- all_constants[ index_of_draw] . 0 = format_ident ! ( "{first}OrNodeRecacheRequested" ) ;
162
+ all_constants[ index_of_draw] . 0 = quote :: format_ident!( "{first}OrNodeRecacheRequested" ) ;
164
163
all_constants. retain ( |( constant_name, _) | constant_name != "NodeRecacheRequested" ) ;
165
164
}
166
165
}
166
+
167
+ let _ = & all_constants; // unused warning
167
168
}
0 commit comments