|
5 | 5 | * file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
6 | 6 | */
|
7 | 7 |
|
8 |
| -use godot::builtin::{vdict, vslice, Color, Dictionary, GString, Variant, VariantType}; |
| 8 | +use godot::builtin::{ |
| 9 | + vdict, vslice, Color, Dictionary, GString, PackedInt32Array, Variant, VariantType, |
| 10 | +}; |
9 | 11 | use godot::classes::{INode, IRefCounted, Node, Object, RefCounted, Resource, Texture};
|
10 | 12 | use godot::global::{PropertyHint, PropertyUsageFlags};
|
11 | 13 | use godot::meta::{GodotConvert, PropertyHintInfo, ToGodot};
|
@@ -48,6 +50,9 @@ struct HasProperty {
|
48 | 50 |
|
49 | 51 | #[var(get = get_texture_val, set = set_texture_val, hint = RESOURCE_TYPE, hint_string = "Texture")]
|
50 | 52 | texture_val_rw: Option<Gd<Texture>>,
|
| 53 | + |
| 54 | + #[var] |
| 55 | + packed_int_array: PackedInt32Array, |
51 | 56 | }
|
52 | 57 |
|
53 | 58 | #[godot_api]
|
@@ -141,6 +146,7 @@ impl INode for HasProperty {
|
141 | 146 | string_val: GString::new(),
|
142 | 147 | texture_val: OnEditor::default(),
|
143 | 148 | texture_val_rw: None,
|
| 149 | + packed_int_array: PackedInt32Array::new(), |
144 | 150 | }
|
145 | 151 | }
|
146 | 152 | }
|
@@ -628,6 +634,33 @@ fn test_var_with_renamed_funcs() {
|
628 | 634 | obj.free();
|
629 | 635 | }
|
630 | 636 |
|
| 637 | +// Tests that CoW packed-arrays' changes are reflected from Rust. See: |
| 638 | +// * Rust (sync does work): https://github.com/godot-rust/gdext/pull/576 |
| 639 | +// * GDScript (not synced): https://github.com/godotengine/godot/issues/76150 |
| 640 | +#[itest] |
| 641 | +fn test_copy_on_write_var() { |
| 642 | + let mut obj = HasProperty::new_alloc(); |
| 643 | + |
| 644 | + // Mutate property via reflection -> verify change is reflected in Rust. |
| 645 | + obj.set( |
| 646 | + "packed_int_array", |
| 647 | + &PackedInt32Array::from([1, 2, 3]).to_variant(), |
| 648 | + ); |
| 649 | + assert_eq!( |
| 650 | + obj.bind().packed_int_array, |
| 651 | + PackedInt32Array::from(&[1, 2, 3]) |
| 652 | + ); |
| 653 | + |
| 654 | + // Mutate property in Rust -> verify change is reflected in Godot. |
| 655 | + obj.bind_mut().packed_int_array.push(4); |
| 656 | + assert_eq!( |
| 657 | + obj.get("packed_int_array").to::<PackedInt32Array>(), |
| 658 | + PackedInt32Array::from(&[1, 2, 3, 4]) |
| 659 | + ); |
| 660 | + |
| 661 | + obj.free(); |
| 662 | +} |
| 663 | + |
631 | 664 | // ----------------------------------------------------------------------------------------------------------------------------------------------
|
632 | 665 |
|
633 | 666 | #[derive(GodotClass)]
|
|
0 commit comments