From 348c550ca170ff94c3c9f76e2d85b0513011e063 Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Mon, 8 Apr 2024 11:42:25 +0200 Subject: fix: fix selecting factions --- src/server.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/server.rs b/src/server.rs index 84f9235..003b5e5 100644 --- a/src/server.rs +++ b/src/server.rs @@ -61,7 +61,7 @@ impl Plugin for ServerPlugin { }) .add_systems(Startup, setup) .add_systems(Update, (connects, disconnects)) - .add_systems(Update, receive_message) + .add_systems(Update, (receive_message_select_champion, receive_message_select_faction)) .add_systems(FixedUpdate, timers_tick) .add_systems(FixedUpdate, effective_stats.after(buffs_despawn)) .add_systems(FixedUpdate, health_regen.after(timers_tick)) @@ -174,7 +174,7 @@ fn connects( } } -fn receive_message( +fn receive_message_select_champion( entity_map: Res, mut commands: Commands, mut reader: EventReader>, @@ -189,6 +189,21 @@ fn receive_message( } } +fn receive_message_select_faction( + entity_map: Res, + mut commands: Commands, + mut reader: EventReader>, +) { + for event in reader.read() { + let client_id = event.context(); + let SelectFaction(faction) = event.message(); + let Some(entity) = entity_map.0.get(client_id) else { + continue; + }; + commands.entity(*entity).insert(*faction); + } +} + fn disconnects( mut commands: Commands, mut disconnects: EventReader, -- cgit v1.2.3