DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

9b08f485a28b692e0b7671bc5e1b77029d1d3f85 — Jonni Liljamo 1 year, 5 months ago 065c110
feat(client): add a few reflects for debugging
M client/src/api/game/mod.rs => client/src/api/game/mod.rs +7 -2
@@ 6,6 6,7 @@
 * See LICENSE for licensing information.
 */

use bevy::reflect::{Reflect, FromReflect};
use serde::{Deserialize, Serialize};
use serde_repr::Deserialize_repr;



@@ 96,7 97,7 @@ impl Action {
    }
}

#[derive(Debug, Deserialize_repr, Clone, PartialEq)]
#[derive(Debug, Deserialize_repr, Clone, PartialEq, Reflect, FromReflect)]
#[repr(u8)]
pub enum GameState {
    Forming = 0,


@@ 105,11 106,14 @@ pub enum GameState {
    Cancelled = 3,
}

#[derive(Deserialize, Clone)]
#[derive(Deserialize, Clone, Reflect, FromReflect)]
pub struct Game {
    pub id: String,
    #[reflect(ignore)]
    pub created_at: chrono::DateTime<chrono::Utc>,
    #[reflect(ignore)]
    pub updated_at: chrono::DateTime<chrono::Utc>,
    #[reflect(ignore)]
    pub ended_at: chrono::DateTime<chrono::Utc>,
    pub host_id: String,
    pub host: Option<User>,


@@ 117,5 121,6 @@ pub struct Game {
    pub guest: Option<User>,
    pub state: GameState,
    pub turn: u8,
    #[reflect(ignore)]
    pub actions: Option<Vec<Action>>,
}

M client/src/api/user/mod.rs => client/src/api/user/mod.rs +2 -1
@@ 6,6 6,7 @@
 * See LICENSE for licensing information.
 */

use bevy::reflect::{Reflect, FromReflect};
use serde::Deserialize;

mod login;


@@ 14,7 15,7 @@ pub use login::*;
mod register;
pub use register::*;

#[derive(Deserialize, Clone)]
#[derive(Deserialize, Clone, Reflect, FromReflect)]
pub struct User {
    pub id: String,
    pub created_at: String,

M client/src/main.rs => client/src/main.rs +29 -11
@@ 96,16 96,12 @@ fn main() {
    app.add_state::<AppState>();

    // holds networking options and a request agent
    app.insert_resource(NetworkingOptions {
        api_address: "http://localhost:3000/api".to_string(),
        req: reqwest::blocking::Client::new(),
        user_token: "".to_string(),
    });
    app.register_type::<NetworkingOptions>()
        .init_resource::<NetworkingOptions>();

    app.insert_resource(Global {
        user: None,
        cur_game_id: "".to_string(),
    });
    app.register_type::<Global>()
        .register_type::<User>()
        .init_resource::<Global>();

    // has handlers for all async tasks
    app.add_plugin(plugins::AsyncTasksPlugin);


@@ 192,21 188,43 @@ fn editor_controls() -> bevy_editor_pls::controls::EditorControls {
    editor_controls
}

#[derive(Clone, Resource)]
#[derive(Clone, Resource, Reflect)]
#[reflect(Resource)]
pub struct NetworkingOptions {
    /// api address with no trailing slash
    api_address: String,
    /// reqwest agent
    /// NOTE: mainly for the future, because it can hold cookies
    #[reflect(ignore)]
    req: reqwest::blocking::Client,
    /// feels wrong storing this here but "it's temporary"
    user_token: String,
}

#[derive(Resource)]
impl Default for NetworkingOptions {
    fn default() -> Self {
        Self {
            api_address: "http://localhost:3000/api".to_string(),
            req: reqwest::blocking::Client::new(),
            user_token: "".to_string(),
        }
    }
}

#[derive(Resource, Reflect)]
#[reflect(Resource)]
pub struct Global {
    /// details of the logged in user
    user: Option<User>,
    /// current game id, set from browse
    cur_game_id: String,
}

impl Default for Global {
    fn default() -> Self {
        Self {
            user: None,
            cur_game_id: "".to_string(),
        }
    }
}

M client/src/plugins/game/mod.rs => client/src/plugins/game/mod.rs +8 -3
@@ 9,7 9,7 @@
use bevy::prelude::*;
use bevy_rapier3d::prelude::*;

use crate::{api::game::Game, game_status::GameStatus, AppState, Global};
use crate::{api::game::{Game, GameState}, game_status::GameStatus, AppState, Global};

use self::{hand::SpawnHandEvent, supply::SpawnSupplyPilesEvent};



@@ 24,7 24,10 @@ pub struct GamePlugin;

impl Plugin for GamePlugin {
    fn build(&self, app: &mut App) {
        app.insert_resource(GameData::default())
        app.register_type::<GameData>()
            .register_type::<Game>()
            .register_type::<GameState>()
            .init_resource::<GameData>()
            .add_plugin(ui::GameUIPlugin)
            .add_plugin(card::CardPlugin)
            .add_plugin(supply::SupplyPlugin)


@@ 39,9 42,11 @@ impl Plugin for GamePlugin {
    }
}

#[derive(Resource, Clone)]
#[derive(Resource, Clone, Reflect)]
#[reflect(Resource)]
pub struct GameData {
    pub game: Option<Game>,
    #[reflect(ignore)]
    pub game_status: Option<GameStatus>,

    pub locked: bool,