DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

b764b2150cb7a3f64fb03177893ab0b6ed650674 — Jonni Liljamo 1 year, 5 months ago 73a5e4a
feat(client): player state, state change command
3 files changed, 26 insertions(+), 2 deletions(-)

M client/src/api/game/mod.rs
M client/src/game_status/mod.rs
M client/src/game_status/parser.rs
M client/src/api/game/mod.rs => client/src/api/game/mod.rs +3 -1
@@ 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)]

M client/src/game_status/mod.rs => client/src/game_status/mod.rs +13 -0
@@ 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<Card>,
    pub deck: Vec<Card>,
    pub discard: Vec<Card>,

M client/src/game_status/parser.rs => client/src/game_status/parser.rs +10 -1
@@ 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<GameStatus, ()> {
    let mut game_status = GameStatus {


@@ 21,12 21,18 @@ pub fn parse(game: &Game) -> Result<GameStatus, ()> {
    };

    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<GameStatus, ()> {
                assert!(*index <= target.hand.len());
                target.discard.push(target.hand.remove(*index));
            }
            Command::ChangePlayerState { state } => {
                target.state = *state;
            }
            _ => todo!(),
        }
    }