konnektoren_core/
session.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{game::GameState, player_profile::PlayerProfile};
4
5#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)]
6pub struct Session {
7    pub id: String,
8    pub player_profile: PlayerProfile,
9    pub game_state: GameState,
10}
11
12impl Session {
13    pub fn new(id: String) -> Self {
14        let player_profile = PlayerProfile::new(id.clone());
15        Session {
16            id,
17            player_profile,
18            game_state: GameState::default(),
19        }
20    }
21
22    pub fn new_with_profile(player_profile: PlayerProfile) -> Self {
23        Session {
24            id: player_profile.id.clone(),
25            player_profile,
26            game_state: GameState::default(),
27        }
28    }
29}
30
31#[cfg(test)]
32mod tests {
33    use super::*;
34
35    #[test]
36    fn new_session() {
37        let id = "123".to_string();
38        let session = Session::new(id.clone());
39        assert_eq!(session.id, id);
40        assert_eq!(session.player_profile.id, id);
41        assert_eq!(
42            session.game_state.game.game_paths[0].challenge_ids().len(),
43            8
44        );
45    }
46}