@@ -50,15 +50,14 @@ impl IPanel for Lobby {
5050 . builder ( )
5151 . connect_other_gd ( & gd_ref, |mut this : Gd < Self > , _id : i64 | {
5252 godot_print ! ( "Someone connected, start the game!" ) ;
53- let pong: Gd < Pong > =
54- load :: < PackedScene > ( "res://pong.tscn" ) . instantiate_as :: < Pong > ( ) ;
53+ let pong = load :: < PackedScene > ( "res://pong.tscn" ) . instantiate_as :: < Pong > ( ) ;
5554 // Connect deferred so we can safely erase it from the callback.
5655 pong. signals ( )
5756 . game_finished ( )
5857 . builder ( )
5958 . flags ( ConnectFlags :: DEFERRED )
60- . connect_other_gd ( & this, |mut this : Gd < Self > | {
61- this. bind_mut ( ) . end_game ( "Client disconnected." . to_string ( ) ) ;
59+ . connect_other_mut ( & this, |this| {
60+ this. end_game ( "Client disconnected." ) ;
6261 } ) ;
6362
6463 this. bind_mut ( )
@@ -74,25 +73,18 @@ impl IPanel for Lobby {
7473 . signals ( )
7574 . peer_disconnected ( )
7675 . builder ( )
77- . connect_other_mut ( & self . to_gd ( ) , |this : & mut Self , _id : i64 | {
76+ . connect_other_mut ( & gd_ref , |this, _id : i64 | {
7877 if this. base ( ) . get_multiplayer ( ) . unwrap ( ) . is_server ( ) {
79- this. end_game ( "Client disconnected." . to_string ( ) ) ;
78+ this. end_game ( "Client disconnected." ) ;
8079 } else {
81- this. end_game ( "Server disconnected." . to_string ( ) ) ;
80+ this. end_game ( "Server disconnected." ) ;
8281 }
8382 } ) ;
84- multiplayer
85- . signals ( )
86- . connected_to_server ( )
87- . builder ( )
88- . connect_other_mut ( & self . to_gd ( ) , |_this : & mut Self | {
89- // This function is not needed for this project.
90- } ) ;
9183 multiplayer
9284 . signals ( )
9385 . connection_failed ( )
9486 . builder ( )
95- . connect_other_mut ( & self . to_gd ( ) , |this : & mut Self | {
87+ . connect_other_mut ( & gd_ref , |this| {
9688 this. set_status ( "Couldn't connect." , false ) ;
9789 let mut multiplayer = this. base ( ) . get_multiplayer ( ) . unwrap ( ) ;
9890 multiplayer. set_multiplayer_peer ( Gd :: null_arg ( ) ) ; // Remove peer.
@@ -103,23 +95,23 @@ impl IPanel for Lobby {
10395 . signals ( )
10496 . server_disconnected ( )
10597 . builder ( )
106- . connect_other_mut ( & self . to_gd ( ) , |this : & mut Self | {
107- this. end_game ( "Server disconnected." . to_string ( ) ) ;
98+ . connect_other_mut ( & gd_ref , |this| {
99+ this. end_game ( "Server disconnected." ) ;
108100 } ) ;
109101
110102 self . host_button
111103 . signals ( )
112104 . pressed ( )
113105 . builder ( )
114- . connect_other_mut ( & gd_ref, |this : & mut Self | {
106+ . connect_other_mut ( & gd_ref, |this| {
115107 this. on_host_pressed ( ) ;
116108 } ) ;
117109
118110 self . join_button
119111 . signals ( )
120112 . pressed ( )
121113 . builder ( )
122- . connect_other_mut ( & gd_ref, |this : & mut Self | {
114+ . connect_other_mut ( & gd_ref, |this| {
123115 this. on_join_pressed ( ) ;
124116 } ) ;
125117 }
@@ -138,8 +130,7 @@ impl Lobby {
138130 }
139131 }
140132
141- #[ func]
142- fn end_game ( & mut self , with_error : String ) {
133+ fn end_game ( & mut self , with_error : & str ) {
143134 if self . base ( ) . has_node ( "/root/Pong" ) {
144135 // Erase immediately, otherwise network might show
145136 // errors (this is why we connected deferred above).
@@ -152,7 +143,7 @@ impl Lobby {
152143 self . host_button . set_disabled ( false ) ;
153144 self . join_button . set_disabled ( false ) ;
154145
155- self . set_status ( & with_error, false ) ;
146+ self . set_status ( with_error, false ) ;
156147 }
157148
158149 fn on_host_pressed ( & mut self ) {
0 commit comments