|
8 | 8 | use std::str::FromStr;
|
9 | 9 |
|
10 | 10 | use godot::builtin::{vslice, NodePath};
|
| 11 | +use godot::classes::notify::NodeNotification; |
11 | 12 | use godot::classes::{Node, Node3D, PackedScene, SceneTree};
|
12 | 13 | use godot::global;
|
13 | 14 | use godot::obj::{NewAlloc, NewGd};
|
| 15 | +use godot::prelude::*; |
14 | 16 |
|
15 | 17 | use crate::framework::{itest, TestContext};
|
16 | 18 |
|
@@ -92,3 +94,46 @@ fn node_call_group(ctx: &TestContext) {
|
92 | 94 | node.add_to_group("group");
|
93 | 95 | tree.call_group("group", "set_name", vslice!["name"]);
|
94 | 96 | }
|
| 97 | + |
| 98 | +#[derive(GodotClass, Debug)] |
| 99 | +#[class(base=Node)] |
| 100 | +struct NodeChild { |
| 101 | + child: Gd<Node>, |
| 102 | + notifications: Vec<NodeNotification>, |
| 103 | +} |
| 104 | + |
| 105 | +#[godot_api] |
| 106 | +impl INode for NodeChild { |
| 107 | + fn init(_: Base<Node>) -> Self { |
| 108 | + let child = Node::new_alloc(); |
| 109 | + Self { |
| 110 | + child, |
| 111 | + notifications: vec![], |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + fn on_notification(&mut self, what: NodeNotification) { |
| 116 | + match what { |
| 117 | + NodeNotification::READY => self.notifications.push(NodeNotification::READY), |
| 118 | + NodeNotification::PARENTED => self.notifications.push(NodeNotification::PARENTED), |
| 119 | + NodeNotification::POSTINITIALIZE => { |
| 120 | + self.notifications.push(NodeNotification::POSTINITIALIZE) |
| 121 | + } |
| 122 | + _ => {} |
| 123 | + }; |
| 124 | + } |
| 125 | +} |
| 126 | + |
| 127 | +// https://github.com/godotengine/godot/issues/91023 |
| 128 | +#[cfg(since_api = "4.4")] |
| 129 | +#[itest] |
| 130 | +fn node_add_child_in_init() { |
| 131 | + let node = NodeChild::new_alloc(); |
| 132 | + let dup: Gd<NodeChild> = node.duplicate().unwrap().cast(); |
| 133 | + assert_eq!( |
| 134 | + dup.bind().notifications, |
| 135 | + vec![NodeNotification::POSTINITIALIZE,] |
| 136 | + ); |
| 137 | + node.free(); |
| 138 | + dup.free(); |
| 139 | +} |
0 commit comments