From b764b2150cb7a3f64fb03177893ab0b6ed650674 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Fri, 5 May 2023 15:31:54 +0300 Subject: [PATCH] feat(client): player state, state change command --- client/src/api/game/mod.rs | 4 +++- client/src/game_status/mod.rs | 13 +++++++++++++ client/src/game_status/parser.rs | 11 ++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/client/src/api/game/mod.rs b/client/src/api/game/mod.rs index 6cad5a5..2752a93 100644 --- a/client/src/api/game/mod.rs +++ b/client/src/api/game/mod.rs @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize}; use serde_repr::Deserialize_repr; -use crate::game_status::Card; +use crate::game_status::{Card, PlayerState}; use super::user::User; @@ -40,6 +40,8 @@ pub enum Command { Draw { amount: usize }, /// discard card from hand in slot N Discard { index: usize }, + /// change player state to another + ChangePlayerState { state: PlayerState }, } #[derive(Deserialize, Serialize, Clone)] diff --git a/client/src/game_status/mod.rs b/client/src/game_status/mod.rs index 8ab94f4..bc65ac9 100644 --- a/client/src/game_status/mod.rs +++ b/client/src/game_status/mod.rs @@ -42,7 +42,20 @@ pub struct SupplyPile { pub amount: usize, } +#[derive(Deserialize, Serialize, Clone, Copy)] +pub enum PlayerState { + /// e.g. not their turn + Idle, + /// action phase, playing cards + ActionPhase, + /// buy phase, buying cards + BuyPhase, +} + pub struct PlayerStatus { + pub state: PlayerState, + pub currency: i16, + pub vp: i16, pub hand: Vec, pub deck: Vec, pub discard: Vec, diff --git a/client/src/game_status/parser.rs b/client/src/game_status/parser.rs index f5289bb..c79d457 100644 --- a/client/src/game_status/parser.rs +++ b/client/src/game_status/parser.rs @@ -11,7 +11,7 @@ use fastrand::Rng; use crate::{api::game::{Action, Command, Game}, game_status::SupplyPile}; -use super::{GameStatus, PlayerStatus, Card}; +use super::{GameStatus, PlayerState, PlayerStatus, Card}; pub fn parse(game: &Game) -> Result { let mut game_status = GameStatus { @@ -21,12 +21,18 @@ pub fn parse(game: &Game) -> Result { }; game_status.players.insert(game.host_id.clone(), PlayerStatus { + state: PlayerState::Idle, + currency: 0, + vp: 2, hand: vec![], deck: vec![], discard: vec![] }); game_status.players.insert(game.guest_id.clone(), PlayerStatus { + state: PlayerState::Idle, + currency: 0, + vp: 2, hand: vec![], deck: vec![], discard: vec![] @@ -79,6 +85,9 @@ pub fn parse(game: &Game) -> Result { assert!(*index <= target.hand.len()); target.discard.push(target.hand.remove(*index)); } + Command::ChangePlayerState { state } => { + target.state = *state; + } _ => todo!(), } } -- 2.44.1