basic_game_events/
player.rs1use crate::{commands::Commands, topic_ids::TopicIds};
2use pubsub_bus::*;
3
4pub struct Player {
5 pub id: u32,
6}
7
8impl Subscriber<Commands, TopicIds> for Player {
9 fn on_event(&mut self, event: &BusEvent<Commands, TopicIds>) {
10 let event_id = event.get_id();
11 let event_source_id = event.get_source_id();
12 match event.get_content() {
13 Commands::Move { dx, dy } => {
14 println!(
15 "[Player {}] Received event {} from ID{}: Move({}, {})",
16 self.id, event_id, event_source_id, dx, dy
17 );
18 }
19 Commands::Atack => {
20 println!(
21 "[Player {}] Received event {} from ID{}: Atack",
22 self.id, event_id, event_source_id
23 );
24 }
25 }
26 }
27
28 fn is_subscribed_to(&self, topic_id: &TopicIds) -> bool {
29 match topic_id {
30 TopicIds::Player1 => self.id == 1,
31 TopicIds::Player2 => self.id == 2,
32 }
33 }
34}