Skip to content

Commit ee5b0c2

Browse files
committed
Hide NOTIFICATION_* constants in favor of enum
1 parent 3a1d77a commit ee5b0c2

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

godot-codegen/src/util.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,15 @@ pub fn make_constant_definition(constant: &ClassConstant) -> TokenStream {
110110
let ClassConstant { name, value } = constant;
111111
let name = ident(name);
112112

113-
quote! {
114-
pub const #name: i32 = #value;
113+
if constant.name.starts_with("NOTIFICATION_") {
114+
// Already exposed through enums
115+
quote! {
116+
pub(crate) const #name: i32 = #value;
117+
}
118+
} else {
119+
quote! {
120+
pub const #name: i32 = #value;
121+
}
115122
}
116123
}
117124

itest/rust/src/virtual_methods_test.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,30 @@ impl NodeVirtual for ReturnVirtualTest {
123123

124124
// ----------------------------------------------------------------------------------------------------------------------------------------------
125125

126+
#[derive(Eq, PartialEq, Debug)]
127+
enum ReceivedEvent {
128+
Notification(NodeNotification),
129+
Ready,
130+
}
131+
126132
#[derive(GodotClass, Debug)]
127133
#[class(base=Node, init)]
128134
struct NotificationTest {
129135
#[base]
130136
base: Base<Node>,
131137

132-
sequence: Vec<NodeNotification>,
138+
sequence: Vec<ReceivedEvent>,
133139
}
134140

135141
#[godot_api]
136142
impl NodeVirtual for NotificationTest {
137143
fn on_notification(&mut self, what: NodeNotification) {
138-
self.sequence.push(what);
144+
self.sequence.push(ReceivedEvent::Notification(what));
139145
}
140146

141-
fn ready(&mut self) {}
147+
fn ready(&mut self) {
148+
self.sequence.push(ReceivedEvent::Ready);
149+
}
142150
}
143151

144152
// ----------------------------------------------------------------------------------------------------------------------------------------------
@@ -277,23 +285,24 @@ fn test_virtual_method_with_return() {
277285
obj.free();
278286
}
279287

280-
#[itest]
288+
#[itest(focus)]
281289
fn test_notifications() {
282290
let obj = Gd::<NotificationTest>::new_default();
283-
284291
let mut node = obj.share().upcast::<Node>();
285292
node.issue_notification(NodeNotification::Unpaused);
286293
node.issue_notification(NodeNotification::EditorPostSave);
287-
node.issue_notification(NodeNotification::WmSizeChanged);
294+
node.issue_notification(NodeNotification::Ready);
295+
node.issue_notification_reversed(NodeNotification::WmSizeChanged);
288296

289297
assert_eq!(
290298
obj.bind().sequence,
291299
vec![
292-
Node::NOTIFICATION_UNPAUSED.into(),
293-
Node::NOTIFICATION_EDITOR_POST_SAVE.into(),
294-
Node::NOTIFICATION_WM_SIZE_CHANGED.into(),
300+
ReceivedEvent::Notification(NodeNotification::Unpaused),
301+
ReceivedEvent::Notification(NodeNotification::EditorPostSave),
302+
ReceivedEvent::Ready,
303+
ReceivedEvent::Notification(NodeNotification::Ready),
304+
ReceivedEvent::Notification(NodeNotification::WmSizeChanged),
295305
]
296306
);
297-
298307
obj.free();
299308
}

0 commit comments

Comments
 (0)