mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
a04c1b1d1d
fix: world examples
42 lines
1014 B
Rust
42 lines
1014 B
Rust
use authc::Uuid;
|
|
use specs::{Component, FlaggedStorage, NullStorage};
|
|
use specs_idvs::IDVStorage;
|
|
|
|
const MAX_ALIAS_LEN: usize = 32;
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
pub struct Player {
|
|
pub alias: String,
|
|
pub view_distance: Option<u32>,
|
|
uuid: Uuid,
|
|
}
|
|
|
|
impl Player {
|
|
pub fn new(alias: String, view_distance: Option<u32>, uuid: Uuid) -> Self {
|
|
Self {
|
|
alias,
|
|
view_distance,
|
|
uuid,
|
|
}
|
|
}
|
|
|
|
pub fn is_valid(&self) -> bool { Self::alias_is_valid(&self.alias) }
|
|
|
|
pub fn alias_is_valid(alias: &str) -> bool {
|
|
alias.chars().all(|c| c.is_alphanumeric() || c == '_') && alias.len() <= MAX_ALIAS_LEN
|
|
}
|
|
|
|
/// Not to be confused with uid
|
|
pub fn uuid(&self) -> Uuid { self.uuid }
|
|
}
|
|
|
|
impl Component for Player {
|
|
type Storage = FlaggedStorage<Self, IDVStorage<Self>>;
|
|
}
|
|
|
|
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
|
pub struct Respawn;
|
|
impl Component for Respawn {
|
|
type Storage = NullStorage<Self>;
|
|
}
|