diff options
Diffstat (limited to 'src/server.rs')
-rw-r--r-- | src/server.rs | 41 |
1 files changed, 14 insertions, 27 deletions
diff --git a/src/server.rs b/src/server.rs index b6c23c6..6b339d0 100644 --- a/src/server.rs +++ b/src/server.rs @@ -13,6 +13,7 @@ use crate::shared::health_event::*; use crate::shared::immovable::*; use crate::shared::imperative::*; use crate::shared::minion::*; +use crate::shared::name::*; use crate::shared::nexus::*; use crate::shared::player::*; use crate::shared::projectile::*; @@ -61,13 +62,7 @@ impl Plugin for ServerPlugin { }) .add_systems(Startup, setup) .add_systems(Update, (connects, disconnects)) - .add_systems( - Update, - ( - receive_message_select_champion, - receive_message_select_faction, - ), - ) + .add_systems(Update, receive_message_spawn) .add_systems( Update, (receive_message_imperative, receive_message_activation), @@ -179,38 +174,30 @@ fn connects( 50. * rng.gen_range(-2..=2) as f32, ); let color = Color::hsl(360. * rng.gen_range(0..=15) as f32 / 16., 0.95, 0.7); - let entity = commands.spawn(PlayerBundle::new(*client_id, position, color)); + let entity = commands.spawn(PlayerBundle::new( + *client_id, + "unknown".into(), + position, + color, + )); entity_map.0.insert(*client_id, entity.id()); } } -fn receive_message_select_champion( - entity_map: Res<EntityMap>, - mut commands: Commands, - mut reader: EventReader<MessageEvent<SelectChampion>>, -) { - for event in reader.read() { - let client_id = event.context(); - let SelectChampion(champion) = event.message(); - let Some(entity) = entity_map.0.get(client_id) else { - continue; - }; - commands.entity(*entity).insert(*champion); - } -} - -fn receive_message_select_faction( +fn receive_message_spawn( entity_map: Res<EntityMap>, mut commands: Commands, - mut reader: EventReader<MessageEvent<SelectFaction>>, + mut reader: EventReader<MessageEvent<Spawn>>, ) { for event in reader.read() { let client_id = event.context(); - let SelectFaction(faction) = event.message(); + let spawn = event.message(); let Some(entity) = entity_map.0.get(client_id) else { continue; }; - commands.entity(*entity).insert(*faction); + commands + .entity(*entity) + .insert((spawn.champion, spawn.faction, Name_(spawn.name.clone()))); } } |