2025-06-23 09:48:28 +01:00
|
|
|
use werewolves_proto::error::GameError;
|
|
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
|
communication::{host::HostComms, player::PlayerIdComms},
|
|
|
|
|
runner::Message,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pub mod host;
|
|
|
|
|
pub mod lobby;
|
|
|
|
|
pub mod player;
|
|
|
|
|
|
|
|
|
|
pub struct Comms {
|
|
|
|
|
host: HostComms,
|
|
|
|
|
player: PlayerIdComms,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Comms {
|
|
|
|
|
pub const fn new(host: HostComms, player: PlayerIdComms) -> Self {
|
|
|
|
|
Self { host, player }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub const fn host(&mut self) -> &mut HostComms {
|
|
|
|
|
&mut self.host
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-03 00:00:39 +01:00
|
|
|
#[allow(unused)]
|
2025-06-23 09:48:28 +01:00
|
|
|
pub const fn player(&mut self) -> &mut PlayerIdComms {
|
|
|
|
|
&mut self.player
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub async fn message(&mut self) -> Result<Message, GameError> {
|
|
|
|
|
tokio::select! {
|
|
|
|
|
msg = self.host.recv() => {
|
|
|
|
|
match msg {
|
|
|
|
|
Some(msg) => Ok(Message::Host(msg)),
|
|
|
|
|
None => Err(GameError::HostChannelClosed),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
Ok(msg) = self.player.recv() => {
|
|
|
|
|
Ok(Message::Client(msg))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|