use std::cmp::{Eq, PartialEq};
use std::fmt;
use std::hash::{Hash, Hasher};
use ustr::Ustr;
use crate::{ARCHIPELAGO_NAME, protocol::NetworkPlayer};
#[derive(Debug, Clone)]
pub struct Player {
team: u32,
slot: u32,
alias: String,
name: Ustr,
game: Ustr,
}
impl Player {
pub(crate) fn hydrate(network: NetworkPlayer, game: Ustr) -> Self {
Player {
team: network.team,
slot: network.slot,
alias: network.alias,
name: network.name,
game,
}
}
pub(crate) fn archipelago(team: u32) -> Self {
Player {
team,
slot: 0,
alias: "Archipelago".into(),
name: *ARCHIPELAGO_NAME,
game: *ARCHIPELAGO_NAME,
}
}
pub fn team(&self) -> u32 {
self.team
}
pub fn slot(&self) -> u32 {
self.slot
}
pub fn alias(&self) -> &str {
self.alias.as_str()
}
pub fn name(&self) -> Ustr {
self.name
}
pub fn game(&self) -> Ustr {
self.game
}
}
impl fmt::Display for Player {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
self.alias.fmt(f)
}
}
impl PartialEq for Player {
fn eq(&self, other: &Self) -> bool {
self.team == other.team && self.slot == other.slot
}
}
impl Eq for Player {}
impl Hash for Player {
fn hash<H: Hasher>(&self, state: &mut H) {
self.team.hash(state);
self.slot.hash(state);
}
}