Properly handle disconnect during game

This commit is contained in:
Sofia 2026-07-23 23:58:28 +03:00
parent 3c3f4d9cc6
commit c09db7210a
2 changed files with 15 additions and 0 deletions

View File

@ -536,6 +536,11 @@ impl Game {
}
pub fn remove_player(&mut self, id: u16) {
if let Some(player) = self.find_player_mut(id)
&& let Some(mut character) = player.character.take()
{
character.queue_free();
}
self.players.retain(|p| p.id() != id);
self.run_deferred(move |s| s.signals().on_player_disconnected().emit(id));
}

View File

@ -11,6 +11,8 @@ use crate::{game_manager::Game, ui::player_listing::PlayerListing};
pub struct PlayerListings {
#[export]
player_listing_scene: Option<Gd<PackedScene>>,
#[export]
update_on_disconnect: bool,
base: Base<HBoxContainer>,
}
@ -18,6 +20,14 @@ pub struct PlayerListings {
#[godot_api]
impl IHBoxContainer for PlayerListings {
fn ready(&mut self) {
if let Some(game) = Game::singleton()
&& self.update_on_disconnect
{
game.signals()
.on_player_disconnected()
.connect_other(self, |s, _| s.update_player_listings());
}
self.run_deferred(|s| s.update_player_listings());
}
}