konnektoren_core/
player_profile.rs

1//! Player profile module.
2
3use serde::{Deserialize, Serialize};
4
5use crate::Xp;
6
7#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8pub struct PlayerProfile {
9    pub id: String,
10    pub name: String,
11    pub xp: Xp,
12}
13
14impl PlayerProfile {
15    pub fn new(id: String) -> Self {
16        PlayerProfile {
17            id,
18            ..Default::default()
19        }
20    }
21}
22
23impl Default for PlayerProfile {
24    fn default() -> Self {
25        let mut generator = names::Generator::default();
26        let name = generator.next().unwrap();
27
28        PlayerProfile {
29            id: "".to_string(),
30            name,
31            xp: 0,
32        }
33    }
34}
35
36#[cfg(test)]
37mod tests {
38    use super::*;
39
40    #[test]
41    fn new_profile() {
42        let id = "123".to_string();
43        let profile = PlayerProfile::new(id.clone());
44        assert_eq!(profile.id, id);
45    }
46}