aboutsummaryrefslogtreecommitdiffstats
path: root/src/server.rs
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-04-08 13:47:18 +0200
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-04-08 15:23:13 +0200
commit1a559793251e80952bd3bdc668cfda46cbc38e73 (patch)
treea6b2649ac895a75ff48766e24c01202a1ca6a376 /src/server.rs
parentd39c819000569b468cfa68977f8a8b03062ac5d9 (diff)
feat: add player namesmain
Diffstat (limited to 'src/server.rs')
-rw-r--r--src/server.rs41
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())));
}
}