76 lines
1.8 KiB
Rust
76 lines
1.8 KiB
Rust
|
|
use core::{fmt::Display, num::NonZeroU8};
|
||
|
|
|
||
|
|
use serde::{Deserialize, Serialize};
|
||
|
|
|
||
|
|
use crate::{
|
||
|
|
diedto::DiedTo,
|
||
|
|
player::{CharacterId, PlayerId},
|
||
|
|
role::RoleTitle,
|
||
|
|
};
|
||
|
|
|
||
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||
|
|
pub struct Identification {
|
||
|
|
pub player_id: PlayerId,
|
||
|
|
pub public: PublicIdentity,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||
|
|
pub struct PublicIdentity {
|
||
|
|
pub name: String,
|
||
|
|
pub pronouns: Option<String>,
|
||
|
|
pub number: NonZeroU8,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl Default for PublicIdentity {
|
||
|
|
fn default() -> Self {
|
||
|
|
Self {
|
||
|
|
name: Default::default(),
|
||
|
|
pronouns: Default::default(),
|
||
|
|
number: NonZeroU8::new(1).unwrap(),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl Display for PublicIdentity {
|
||
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||
|
|
let PublicIdentity {
|
||
|
|
name,
|
||
|
|
pronouns,
|
||
|
|
number,
|
||
|
|
} = self;
|
||
|
|
let pronouns = pronouns
|
||
|
|
.as_ref()
|
||
|
|
.map(|p| format!(" ({p})"))
|
||
|
|
.unwrap_or_default();
|
||
|
|
write!(f, "[{number}] {name}{pronouns}")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl core::hash::Hash for Identification {
|
||
|
|
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||
|
|
self.player_id.hash(state);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl Display for Identification {
|
||
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||
|
|
let Identification { player_id, public } = self;
|
||
|
|
write!(f, "{public} [{player_id}]")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||
|
|
pub struct PlayerState {
|
||
|
|
pub identification: Identification,
|
||
|
|
pub connected: bool,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||
|
|
pub struct CharacterState {
|
||
|
|
pub player_id: PlayerId,
|
||
|
|
pub character_id: CharacterId,
|
||
|
|
pub public_identity: PublicIdentity,
|
||
|
|
pub role: RoleTitle,
|
||
|
|
pub died_to: Option<DiedTo>,
|
||
|
|
}
|