DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

18acb7d0f8dc4c048b3cf39391845a1b527b8350 — skye 1 year, 7 months ago 2b02659
feat!(client): replace gamestate consts with enums
4 files changed, 28 insertions(+), 9 deletions(-)

M Cargo.lock
M client/Cargo.toml
M client/src/api/game/mod.rs
M client/src/plugins/menu/ui/browse.rs
M Cargo.lock => Cargo.lock +12 -0
@@ 2032,6 2032,7 @@ dependencies = [
 "futures-lite",
 "reqwest",
 "serde",
 "serde_repr",
]

[[package]]


@@ 2870,6 2871,17 @@ dependencies = [
]

[[package]]
name = "serde_repr"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcec881020c684085e55a25f7fd888954d56609ef363479dc5a1305eb0d40cab"
dependencies = [
 "proc-macro2",
 "quote",
 "syn 2.0.15",
]

[[package]]
name = "serde_urlencoded"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"

M client/Cargo.toml => client/Cargo.toml +2 -0
@@ 15,6 15,8 @@ futures-lite = "1.13.0"

reqwest = { version = "0.11.16", features = [ "blocking", "json", "gzip" ] }

serde_repr = "0.1.12"

[dependencies.serde]
version = "1.0.160"
default-features = false

M client/src/api/game/mod.rs => client/src/api/game/mod.rs +11 -6
@@ 7,6 7,7 @@
 */

use serde::{Deserialize, Serialize};
use serde_repr::Deserialize_repr;

use super::user::User;



@@ 49,6 50,15 @@ pub struct Action {
    pub command: Command,
}

#[derive(Deserialize_repr, Clone, PartialEq)]
#[repr(u8)]
pub enum GameState {
    Forming = 0,
    InProgress= 1,
    Finished = 2,
    Cancelled = 3,
}

#[derive(Deserialize, Clone)]
pub struct Game {
    pub id: String,


@@ 59,12 69,7 @@ pub struct Game {
    pub host: Option<User>,
    pub guest_id: String,
    pub guest: Option<User>,
    pub state: u8,
    pub state: GameState,
    pub turn: u8,
    pub actions: Option<Vec<Action>>,
}

pub const GAMESTATE_FORMING: u8 = 0;
pub const GAMESTATE_INPROGRESS: u8 = 1;
pub const GAMESTATE_FINISHED: u8 = 2;
pub const GAMESTATE_CANCELLED: u8 = 3;

M client/src/plugins/menu/ui/browse.rs => client/src/plugins/menu/ui/browse.rs +3 -3
@@ 13,7 13,7 @@ use crate::{plugins::{
    GameCreateCallEvent, BrowseState, 
    GameFormingCallEvent, GameMyGamesCallEvent,
    GameJoinCallEvent, menu::MenuState
}, api::game::{GAMESTATE_INPROGRESS, GAMESTATE_FINISHED}, Global, AppState};
}, api::game::GameState, Global, AppState};

use super::{MenuData, MenuUIState};



@@ 106,7 106,7 @@ pub fn view(
            }
            BrowseState::InProgress => {
                let mut games = data.my_games.clone();
                games.retain(|g| g.state == GAMESTATE_INPROGRESS); 
                games.retain(|g| g.state == GameState::InProgress);
                for game in &games {
                    egui::Frame::none()
                        .fill(egui::Color32::BLACK)


@@ 131,7 131,7 @@ pub fn view(
            }
            BrowseState::Finished => {
                let mut games = data.my_games.clone();
                games.retain(|g| g.state == GAMESTATE_FINISHED);
                games.retain(|g| g.state == GameState::Finished);
                for game in &games {
                    egui::Frame::none()
                        .fill(egui::Color32::BLACK)