geogamer_data 0.1.16

Data format description exchanged between geogamer server and client
Documentation
use std::collections::HashMap;

use serde::{Deserialize, Serialize};
use uuid::Uuid;

use crate::{player, room};

pub type Id = Uuid;

/// GET /api/room/{room_id}
pub type GetRoomResponse = Room;

/// GET /api/rooms
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ListRoomsResponse {
    pub rooms: Vec<Room>,
    pub is_before: bool,
    pub is_after: bool,
    pub total_rooms: usize,
}

/// POST /api/rooms
pub type CreateRoomResponse = Room;

/// Room lobby, with a list of players and a host
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Room {
    pub id: Id,
    pub state: RoomState,
    pub host: Option<player::Player>,
    pub players: HashMap<player::Id, player::Player>,
}

/// Room current state
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum RoomState {
    Lobby,   //< Waiting for host to start game
    Started, //< Game is in progress
}

/// Event sent through websocket connection between server and client
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum RoomEvent {
    Server(RoomServerEvent),
    Client(RoomClientEvent),
}

/// Event broadcasted from server to clients
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum RoomServerEvent {
    RoomUpdate(room::Room), //< Room was updated (player joined/left, host changed, ...)
    GameStarted,            //< Game has started
}

/// Event sent from client to server
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum RoomClientEvent {
    PlayerNameUpdated(String), //< Player changed their name
    GameStarted,               //< Host triggered game start
}