Skip to main content

veloren_common/
character.rs

1//! Structs representing a playable Character
2
3use crate::{comp, comp::inventory::Inventory};
4use serde::{Deserialize, Serialize};
5
6/// The limit on how many characters that a player can have
7pub const MAX_CHARACTERS_PER_PLAYER: usize = 8;
8#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash, PartialOrd, Ord)]
9#[serde(transparent)]
10pub struct CharacterId(pub i64);
11
12pub const MAX_NAME_LENGTH: usize = 20;
13
14pub fn verify_character_name(name: &str) -> bool {
15    // Don't keep counting if it's longer than `MAX_NAME_LENGTH`.
16    name.chars().take(MAX_NAME_LENGTH + 1).count() <= MAX_NAME_LENGTH
17}
18
19/// The minimum character data we need to create a new character on the server.
20#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
21pub struct Character {
22    pub id: Option<CharacterId>,
23    pub alias: String,
24}
25
26/// Data needed to render a single character item in the character list
27/// presented during character selection.
28#[derive(Clone, Debug, Serialize, Deserialize)]
29pub struct CharacterItem<Location> {
30    pub character: Character,
31    pub body: comp::Body,
32    pub hardcore: bool,
33    pub inventory: Inventory,
34    pub location: Option<Location>,
35}