cards/lib/src/lib.rs
2024-12-03 17:45:50 -05:00

190 lines
4.3 KiB
Rust

use serde::{Deserialize, Serialize};
pub enum ClientToServerMessage {}
#[derive(Serialize, Deserialize, Debug)]
pub enum ServerToClientMessage {
CardPacksMeta(CardPacksMeta),
ChatMessage(ChatMessage),
ChatUpdate(ChatUpdate),
GameMeta(GameMeta),
GameStateMeta(GameStateMeta),
GamesUpdate(GamesUpdate),
JudgeRound(JudgeRound),
ServerActiveGames(ServerActiveGames),
ServerOnlineUsers(ServerOnlineUsers),
UserUpdate(UserUpdate),
}
#[derive(Serialize, Deserialize)]
pub enum CardsMessage {
BlackCardMeta(BlackCardMeta),
CardPackMeta(CardPackMeta),
GameBrowserMeta(GameBrowserMeta),
GameDeleteRequest(GameDeleteRequest),
GameJoinRequest(GameJoinRequest),
GamePlayerMeta(GamePlayerMeta),
JudgeDecisionRequest(JudgeDecisionRequest),
JudgeEntry(JudgeEntry),
NewGameRequest(NewGameRequest),
PlayerMoveRequest(PlayerMoveRequest),
UserLogInRequest(UserLogInRequest),
WhiteCardMeta(WhiteCardMeta),
}
/// Judge decision
#[derive(Clone, Serialize, Deserialize)]
pub struct JudgeDecisionRequest {
pub game_id: String,
pub winning_cards: Vec<String>,
}
/// White Card Meta
#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
pub struct WhiteCardMeta {
pub uuid: String,
pub text: String,
}
/// Judge entry
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct JudgeEntry {
pub cards_to_judge: Vec<WhiteCardMeta>,
}
/// Judge round
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct JudgeRound {
pub entries: Vec<JudgeEntry>,
}
/// Delete game request
#[derive(Serialize, Deserialize)]
pub struct GameDeleteRequest {
pub delete_game_id: String,
}
/// Game join request
#[derive(Serialize, Deserialize)]
pub struct GameJoinRequest {
pub id: String,
}
/// Player Move Request
#[derive(Clone, Serialize, Deserialize)]
pub struct PlayerMoveRequest {
pub game_id: String,
pub card_ids: Vec<String>,
}
/// Game Player Meta
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct GamePlayerMeta {
pub name: String,
pub score: u32,
pub submitted: bool,
}
/// Game meta
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct GameMeta {
pub uuid: String,
pub name: String,
pub host: String,
pub players: Vec<GamePlayerMeta>,
pub czar: String,
pub packs: Vec<u8>,
pub white_count: u32,
pub black_count: u32,
pub white_discard_count: u32,
}
/// Black card meta
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct BlackCardMeta {
pub text: String,
pub pick: u32,
}
/// Game state meta
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct GameStateMeta {
pub black: Option<BlackCardMeta>, // this has to be an option or prost gets cranky
pub white: Vec<WhiteCardMeta>,
}
/// Game browser meta
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct GameBrowserMeta {
pub uuid: String,
pub name: String,
pub host: String,
pub players: u32,
pub packs: Vec<u8>,
}
/// Card Pack Meta
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct CardPackMeta {
pub name: String,
pub pack: String,
pub num_white: u32,
pub num_black: u32,
}
/// Card Packs Meta
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct CardPacksMeta {
pub official_meta: Vec<CardPackMeta>,
pub unofficial_meta: Vec<CardPackMeta>,
}
/// Games update
#[derive(Serialize, Deserialize, Debug)]
pub struct GamesUpdate {
pub games: Vec<GameBrowserMeta>,
}
/// Chat update
#[derive(Serialize, Deserialize, Debug)]
pub struct ChatUpdate {
pub room: String,
pub users: Vec<String>,
}
/// User login request (to change name)
#[derive(Serialize, Deserialize)]
pub struct UserLogInRequest {
pub username: String,
}
/// Response to user name change containing new name
#[derive(Debug, Serialize, Deserialize)]
pub struct UserUpdate {
pub username: String,
}
/// Chat message
#[derive(Debug, Serialize, Deserialize)]
pub struct ChatMessage {
pub text: String,
}
/// Server user count
#[derive(Serialize, Deserialize, Debug)]
pub struct ServerOnlineUsers {
pub online_users: u32,
}
/// Server games count
#[derive(Serialize, Deserialize, Debug)]
pub struct ServerActiveGames {
pub active_games: u32,
}
/// New game request structure
#[derive(Serialize, Deserialize)]
pub struct NewGameRequest {
pub game_name: String,
pub game_packs: Vec<String>,
}