File tree 2 files changed +51
-0
lines changed
itest/rust/src/object_tests 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 5
5
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
6
*/
7
7
8
+ use crate :: property:: { Export , Property , PropertyHintInfo } ;
8
9
use std:: mem;
9
10
10
11
/// Ergonomic late-initialization container with `ready()` support.
@@ -186,7 +187,32 @@ impl<T> std::ops::DerefMut for OnReady<T> {
186
187
}
187
188
}
188
189
190
+ impl < T : Property > Property for OnReady < T > {
191
+ type Intermediate = T :: Intermediate ;
192
+
193
+ fn get_property ( & self ) -> Self :: Intermediate {
194
+ let deref: & T = self ;
195
+ deref. get_property ( )
196
+ }
197
+
198
+ fn set_property ( & mut self , value : Self :: Intermediate ) {
199
+ let deref: & mut T = self ;
200
+ deref. set_property ( value) ;
201
+ }
202
+
203
+ fn property_hint ( ) -> PropertyHintInfo {
204
+ T :: property_hint ( )
205
+ }
206
+ }
207
+
208
+ impl < T : Export > Export for OnReady < T > {
209
+ fn default_export_info ( ) -> PropertyHintInfo {
210
+ T :: default_export_info ( )
211
+ }
212
+ }
213
+
189
214
// ----------------------------------------------------------------------------------------------------------------------------------------------
215
+ // Implementation
190
216
191
217
enum InitState < T > {
192
218
ManualUninitialized ,
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ use godot::engine::notify::NodeNotification;
11
11
use godot:: engine:: INode ;
12
12
13
13
use godot:: obj:: { Gd , OnReady } ;
14
+ use godot:: prelude:: ToGodot ;
14
15
15
16
#[ itest]
16
17
fn onready_deref ( ) {
@@ -116,12 +117,36 @@ fn onready_lifecycle_with_impl_without_ready() {
116
117
obj. free ( ) ;
117
118
}
118
119
120
+ #[ itest]
121
+ fn onready_property_access ( ) {
122
+ let mut obj = OnReadyWithImpl :: create ( true ) ;
123
+ obj. notify ( NodeNotification :: Ready ) ;
124
+
125
+ obj. set ( "auto" . into ( ) , 33 . to_variant ( ) ) ;
126
+ obj. set ( "manual" . into ( ) , 44 . to_variant ( ) ) ;
127
+
128
+ {
129
+ let obj = obj. bind ( ) ;
130
+ assert_eq ! ( * obj. auto, 33 ) ;
131
+ assert_eq ! ( * obj. manual, 44 ) ;
132
+ }
133
+
134
+ let auto = obj. get ( "auto" . into ( ) ) . to :: < i32 > ( ) ;
135
+ let manual = obj. get ( "manual" . into ( ) ) . to :: < i64 > ( ) ;
136
+ assert_eq ! ( auto, 33 ) ;
137
+ assert_eq ! ( manual, 44 ) ;
138
+
139
+ obj. free ( ) ;
140
+ }
141
+
119
142
// ----------------------------------------------------------------------------------------------------------------------------------------------
120
143
121
144
#[ derive( GodotClass ) ]
122
145
#[ class( base=Node ) ]
123
146
struct OnReadyWithImpl {
147
+ #[ export]
124
148
auto : OnReady < i32 > ,
149
+ #[ var]
125
150
manual : OnReady < i32 > ,
126
151
runs_manual_init : bool ,
127
152
}
You can’t perform that action at this time.
0 commit comments