From c1de8c625f26a86986e4b3c317542749c934e323 Mon Sep 17 00:00:00 2001 From: CoCo_Sol007 Date: Sat, 16 Mar 2024 22:07:52 +0100 Subject: [PATCH] save --- crates/border-wars/src/connection.rs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/crates/border-wars/src/connection.rs b/crates/border-wars/src/connection.rs index d1518b6..4804203 100644 --- a/crates/border-wars/src/connection.rs +++ b/crates/border-wars/src/connection.rs @@ -7,10 +7,6 @@ use bevy::prelude::*; use serde::{Deserialize, Serialize}; use uuid::Uuid; -/// TODO -#[derive(Resource, Default, Deserialize, Serialize, Clone)] -pub struct AllPlayers(pub HashMap); - /// The plugin that manages the connection to the host. pub struct ConnectionPlugin; @@ -18,20 +14,30 @@ impl Plugin for ConnectionPlugin { fn build(&self, app: &mut App) { app.add_network_event::() .add_network_event::() + .add_network_event::() .init_resource::(); } } -#[derive(Event, Deserialize, Serialize)] +/// All the players in the game. +#[derive(Resource, Default)] +pub struct AllPlayers(HashMap); + /// The message sent by the client to the server to request a connection. +#[derive(Event, Deserialize, Serialize)] pub struct RequestConnection { /// The name of the player. pub name: String, } -#[derive(Event, Deserialize, Serialize)] -/// The message sent by the server to all clients when a new player joins. -pub struct UpdatePlayers { - /// All players in the game. - pub players: AllPlayers, +/// The message sent in order to update the list of players. +pub struct AddPlayer { + pub uuid: Uuid, + pub name: String, +} + +/// The packet sent when a player is removed. +#[derive(Event, Deserialize, Serialize)] +pub struct RemovePlayer { + pub uuid: String, }