werewolves/werewolves-proto/src/message.rs

80 lines
1.6 KiB
Rust
Raw Normal View History

pub mod host;
mod ident;
pub mod night;
use core::{fmt::Display, num::NonZeroU8};
pub use ident::*;
use night::{ActionPrompt, ActionResponse, ActionResult, RoleChange};
use serde::{Deserialize, Serialize};
use crate::{
error::GameError,
game::GameOver,
player::{Character, CharacterId},
role::RoleTitle,
};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum ClientMessage {
Hello,
Goodbye,
GetState,
RoleAck,
UpdateSelf(UpdateSelf),
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum UpdateSelf {
Name(String),
Number(NonZeroU8),
Pronouns(Option<String>),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DayCharacter {
pub character_id: CharacterId,
pub name: String,
pub alive: bool,
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct Target {
pub character_id: CharacterId,
pub public: PublicIdentity,
}
impl Display for Target {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let Target {
character_id,
public,
} = self;
write!(f, "{public} [(c){character_id}]")
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ServerMessage {
Disconnect,
LobbyInfo {
joined: bool,
players: Box<[PublicIdentity]>,
},
GameInProgress,
GameStart {
role: RoleTitle,
},
InvalidMessageForGameState,
NoSuchTarget,
GameOver(GameOver),
Update(PlayerUpdate),
Sleep,
Reset,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum PlayerUpdate {
Number(NonZeroU8),
}