From 9b08f485a28b692e0b7671bc5e1b77029d1d3f85 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Wed, 17 May 2023 10:49:59 +0300 Subject: [PATCH] feat(client): add a few reflects for debugging --- client/src/api/game/mod.rs | 9 ++++++-- client/src/api/user/mod.rs | 3 ++- client/src/main.rs | 40 ++++++++++++++++++++++++---------- client/src/plugins/game/mod.rs | 11 +++++++--- 4 files changed, 46 insertions(+), 17 deletions(-) diff --git a/client/src/api/game/mod.rs b/client/src/api/game/mod.rs index 073283d..439e724 100644 --- a/client/src/api/game/mod.rs +++ b/client/src/api/game/mod.rs @@ -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, + #[reflect(ignore)] pub updated_at: chrono::DateTime, + #[reflect(ignore)] pub ended_at: chrono::DateTime, pub host_id: String, pub host: Option, @@ -117,5 +121,6 @@ pub struct Game { pub guest: Option, pub state: GameState, pub turn: u8, + #[reflect(ignore)] pub actions: Option>, } diff --git a/client/src/api/user/mod.rs b/client/src/api/user/mod.rs index 2ebcb50..2002ea6 100644 --- a/client/src/api/user/mod.rs +++ b/client/src/api/user/mod.rs @@ -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, diff --git a/client/src/main.rs b/client/src/main.rs index 297fcb0..ed570e9 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -96,16 +96,12 @@ fn main() { app.add_state::(); // 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::() + .init_resource::(); - app.insert_resource(Global { - user: None, - cur_game_id: "".to_string(), - }); + app.register_type::() + .register_type::() + .init_resource::(); // 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, /// 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(), + } + } +} diff --git a/client/src/plugins/game/mod.rs b/client/src/plugins/game/mod.rs index 15b1b99..2c53b0f 100644 --- a/client/src/plugins/game/mod.rs +++ b/client/src/plugins/game/mod.rs @@ -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::() + .register_type::() + .register_type::() + .init_resource::() .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, + #[reflect(ignore)] pub game_status: Option, pub locked: bool, -- 2.44.1