Skip to content

Commit 72d898b

Browse files
committed
Update itest so that duplicate() copies Rust properties
Remove Area2D again
1 parent c7e5bd1 commit 72d898b

File tree

3 files changed

+27
-46
lines changed

3 files changed

+27
-46
lines changed

godot-codegen/src/special_cases/codegen_special_cases.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,4 @@ const SELECTED_CLASSES: &[&str] = &[
193193
//
194194
// Collision
195195
"CollisionObject2D",
196-
"Area2D",
197196
];

itest/rust/src/object_tests/property_template_test.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ fn property_template_test(ctx: &TestContext) {
107107
"mismatch in property {name}:\n GDScript: {gdscript_prop:?}\n Rust: {rust_prop:?}"
108108
));
109109
}
110+
/*else { // Keep around for debugging.
111+
println!(
112+
"good property {name}:\n GDScript: {gdscript_prop:?}\n Rust: {rust_prop:?}"
113+
);
114+
}*/
110115
}
111116

112117
rust_properties.free();

itest/rust/src/object_tests/property_test.rs

Lines changed: 22 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
66
*/
77

8-
use godot::builtin::{dict, Color, Dictionary, GString, StringName, Variant, VariantType};
9-
use godot::classes::{Area2D, INode, IRefCounted, Node, Object, RefCounted, Resource, Texture};
8+
use godot::builtin::{dict, Color, Dictionary, GString, Variant, VariantType};
9+
use godot::classes::{INode, IRefCounted, Node, Object, RefCounted, Resource, Texture};
1010
use godot::global::{PropertyHint, PropertyUsageFlags};
1111
use godot::meta::{GodotConvert, PropertyHintInfo, ToGodot};
1212
use godot::obj::{Base, EngineBitfield, EngineEnum, Gd, NewAlloc, NewGd, OnEditor};
@@ -541,63 +541,40 @@ fn test_var_with_renamed_funcs() {
541541
#[derive(GodotClass)]
542542
#[class(init, base=Node)]
543543
struct SomeDuplicator {
544-
#[var]
544+
#[export(storage)]
545545
int_val: i32,
546546

547-
#[var]
547+
#[export(storage)]
548548
optional_node: Option<Gd<Node>>,
549549

550-
#[export]
550+
#[export(storage)]
551551
oneditor_node: OnEditor<Gd<Node>>,
552-
553-
#[export]
554-
oneditor_area: OnEditor<Gd<Area2D>>,
555552
}
556553

557554
#[itest]
558555
fn test_some_duplicator() {
559-
let mut obj = SomeDuplicator::new_alloc();
560-
obj.bind_mut().int_val = 5;
561-
562-
let some_node = Node::new_alloc();
563-
obj.bind_mut().optional_node = Some(some_node.clone());
556+
let mut original = SomeDuplicator::new_alloc();
557+
original.bind_mut().int_val = 5;
564558

565-
let mut editor_node = Node::new_alloc();
566-
editor_node.set_name("test");
567-
obj.bind_mut().oneditor_node.init(editor_node);
559+
let node_in_option = Node::new_alloc();
560+
original.bind_mut().optional_node = Some(node_in_option.clone());
568561

569-
let mut some_area = Area2D::new_alloc();
570-
some_area.set_collision_layer(1);
571-
some_area.set_collision_mask(1);
572-
obj.bind_mut().oneditor_area.init(some_area);
573-
assert_eq!(obj.bind().oneditor_area.get_collision_layer(), 1);
574-
assert_eq!(obj.bind().oneditor_area.get_collision_mask(), 1);
575-
576-
let duplicated_obj = obj.duplicate();
577-
let duplicated_obj: Gd<SomeDuplicator> = duplicated_obj.unwrap().cast();
562+
let node_in_editor = Node::new_alloc();
563+
original
564+
.bind_mut()
565+
.oneditor_node
566+
.init(node_in_editor.clone());
578567

568+
let duplicated: Gd<SomeDuplicator> = original.duplicate().unwrap().cast();
579569
{
580-
let duplicated = duplicated_obj.bind();
570+
let duplicated = duplicated.bind();
581571
assert_eq!(duplicated.int_val, 5);
582-
assert_eq!(
583-
duplicated.optional_node.as_ref().unwrap().instance_id(),
584-
some_node.instance_id()
585-
);
586-
assert_eq!(
587-
duplicated.optional_node.as_ref().unwrap().get_name(),
588-
StringName::from("renamed")
589-
);
590-
591-
assert_eq!(
592-
duplicated.oneditor_node.get_name(),
593-
StringName::from("test")
594-
);
595-
596-
assert_eq!(duplicated.oneditor_area.get_collision_layer(), 1);
597-
assert_eq!(duplicated.oneditor_area.get_collision_mask(), 1);
572+
assert_eq!(duplicated.optional_node.as_ref().unwrap(), &node_in_option);
573+
assert_eq!(&*duplicated.oneditor_node, &node_in_editor);
598574
}
599575

600-
some_node.free();
601-
duplicated_obj.free();
602-
obj.free();
576+
node_in_option.free();
577+
node_in_editor.free();
578+
duplicated.free();
579+
original.free();
603580
}

0 commit comments

Comments
 (0)