1- use crate :: helper_functions:: * ;
2- use gdnative:: prelude:: * ;
1+ use crate :: * ;
32use ggrs:: * ;
43use std:: convert:: TryInto ;
54use std:: option:: * ;
@@ -152,6 +151,28 @@ impl GodotGGRSP2PSpectatorSession {
152151 None => godot_error ! ( "{}" , ERR_MESSAGE_NO_SESSION_MADE ) ,
153152 }
154153 }
154+
155+ #[ export]
156+ fn get_events ( & mut self , _owner : & Node ) ->Vec < ( & str , Variant ) > {
157+ let mut result: Vec < ( & str , Variant ) > = Vec :: new ( ) ;
158+ match & mut self . sess {
159+ Some ( s) => {
160+ for event in s. events ( ) {
161+ match event {
162+ GGRSEvent :: WaitRecommendation { skip_frames } => result. push ( ( "WaitRecommendation" , skip_frames. to_variant ( ) ) ) ,
163+ GGRSEvent :: NetworkInterrupted { player_handle, disconnect_timeout} => result. push ( ( "NetworkInterrupted" , ( player_handle, disconnect_timeout as u64 ) . to_variant ( ) ) ) ,
164+ GGRSEvent :: NetworkResumed { player_handle } => result. push ( ( "NetworkResumed" , player_handle. to_variant ( ) ) ) ,
165+ GGRSEvent :: Disconnected { player_handle } => result. push ( ( "Disconnected" , player_handle. to_variant ( ) ) ) ,
166+ GGRSEvent :: Synchronized { player_handle } => result. push ( ( "Synchronized" , player_handle. to_variant ( ) ) ) ,
167+ GGRSEvent :: Synchronizing { player_handle, total, count} => result. push ( ( "Synchronizing" , ( player_handle, total, count) . to_variant ( ) ) ) ,
168+ }
169+ }
170+ } ,
171+ None => godot_error ! ( "{}" , ERR_MESSAGE_NO_SESSION_MADE )
172+ } ;
173+ return result
174+ }
175+
155176 //NON-EXPORTED FUNCTIONS
156177 fn handle_requests ( & mut self , requests : Vec < GGRSRequest > ) {
157178 for item in requests {
@@ -185,7 +206,7 @@ impl GodotGGRSP2PSpectatorSession {
185206 . to_variant ( ) ;
186207 godot_array. push ( result) ;
187208 }
188- unsafe { node. call ( "ggrs_advance_frame" , & [ godot_array. to_variant ( ) ] ) } ;
209+ unsafe { node. call ( CALLBACK_FUNC_ADVANCE_FRAME , & [ godot_array. to_variant ( ) ] ) } ;
189210 }
190211 None => {
191212 godot_error ! ( "{}" , ERR_MESSAGE_NO_CALLBACK_NODE ) ;
@@ -203,7 +224,7 @@ impl GodotGGRSP2PSpectatorSession {
203224 let buffer =
204225 ByteArray :: from_vec ( game_state. buffer . unwrap_or_default ( ) ) . to_variant ( ) ;
205226 let checksum = game_state. checksum . to_variant ( ) ;
206- unsafe { node. call ( "ggrs_load_game_state" , & [ frame, buffer, checksum] ) } ;
227+ unsafe { node. call ( CALLBACK_FUNC_LOAD_GAME_STATE , & [ frame, buffer, checksum] ) } ;
207228 }
208229 None => {
209230 godot_error ! ( "{}" , ERR_MESSAGE_NO_CALLBACK_NODE ) ;
@@ -217,7 +238,7 @@ impl GodotGGRSP2PSpectatorSession {
217238 Some ( s) => {
218239 let node = unsafe { s. assume_safe ( ) } ;
219240 let state: Variant =
220- unsafe { node. call ( "ggrs_save_game_state" , & [ frame. to_variant ( ) ] ) } ;
241+ unsafe { node. call ( CALLBACK_FUNC_SAVE_GAME_STATE , & [ frame. to_variant ( ) ] ) } ;
221242 let state_bytes = ByteArray :: from_variant ( & state) . unwrap_or_default ( ) ;
222243 let mut state_bytes_vec = Vec :: new ( ) ;
223244 for i in 0 ..state_bytes. len ( ) {
0 commit comments