From 5a980b1115ecc7e2113bcde7e3a4fc55e8f162c2 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Mon, 13 Mar 2023 13:42:12 +0200 Subject: [PATCH] feat(client): derive Reflect for some types --- client/src/cfg/mod.rs | 9 ++++++--- client/src/main.rs | 5 ++++- client/src/plugins/menu/mod.rs | 2 ++ client/src/plugins/menu/ui/connect/mod.rs | 11 +++++++---- client/src/plugins/menu/ui/play/mod.rs | 12 ++++++++---- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/client/src/cfg/mod.rs b/client/src/cfg/mod.rs index 44ee446..a9569c6 100644 --- a/client/src/cfg/mod.rs +++ b/client/src/cfg/mod.rs @@ -20,7 +20,8 @@ pub const FILE_CFG_DEV: &str = ".cfgdev.json"; pub struct CfgDirs(pub directories::ProjectDirs); /// Various settings that can be changed from the... Settings. -#[derive(Serialize, Deserialize, Resource, Debug, Component, PartialEq, Clone)] +#[derive(Serialize, Deserialize, Resource, Reflect, Debug, Component, PartialEq, Clone)] +#[reflect(Resource)] pub struct CfgSettings { /// Master Volume pub volume_master: u32, @@ -41,7 +42,8 @@ impl Default for CfgSettings { } /// User details and status -#[derive(Serialize, Deserialize, Resource, Debug, Component, PartialEq, Clone)] +#[derive(Serialize, Deserialize, Resource, Reflect, Debug, Component, PartialEq, Clone)] +#[reflect(Resource)] pub struct CfgUser { /// User logged in status pub logged_in: bool, @@ -62,7 +64,8 @@ impl Default for CfgUser { } /// Settings that the user has no access to, or can only access through developer settings -#[derive(Serialize, Deserialize, Resource, Debug, Component, PartialEq, Clone)] +#[derive(Serialize, Deserialize, Resource, Reflect, Debug, Component, PartialEq, Clone)] +#[reflect(Resource)] pub struct CfgDev { /// Server pub server_address: String, diff --git a/client/src/main.rs b/client/src/main.rs index 571855a..7fd53be 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -99,8 +99,11 @@ fn main() { )); app.insert_resource(cfg::CfgSettings::default()) + .register_type::() .insert_resource(cfg::CfgUser::default()) - .insert_resource(cfg::CfgDev::default()); + .register_type::() + .insert_resource(cfg::CfgDev::default()) + .register_type::(); app.add_startup_system(setup).add_state::(); diff --git a/client/src/plugins/menu/mod.rs b/client/src/plugins/menu/mod.rs index c11ea51..131e29a 100644 --- a/client/src/plugins/menu/mod.rs +++ b/client/src/plugins/menu/mod.rs @@ -21,7 +21,9 @@ impl Plugin for MenuPlugin { add_state::() .add_system(menu_setup.in_schedule(OnEnter(GameState::MainMenu))) .insert_resource(ui::connect::ConnectScreenData::default()) + .register_type::() .insert_resource(ui::play::PlayScreenData::default()) + .register_type::() .add_systems( ( ui::connect::ui.run_if(in_state(MenuState::Connect)), diff --git a/client/src/plugins/menu/ui/connect/mod.rs b/client/src/plugins/menu/ui/connect/mod.rs index 11fd2d3..fc1d565 100644 --- a/client/src/plugins/menu/ui/connect/mod.rs +++ b/client/src/plugins/menu/ui/connect/mod.rs @@ -6,15 +6,18 @@ * See LICENSE for licensing information. */ -use bevy::ecs::system::Resource; +use bevy::{ + ecs::{reflect::ReflectResource, system::Resource}, + reflect::Reflect, +}; mod ui; pub use ui::*; -#[derive(Default, Resource)] +#[derive(Default, Resource, Reflect)] +#[reflect(Resource)] pub struct ConnectScreenData { pub state: ConnectState, - pub connecting: bool, pub username: String, pub email: String, pub password: String, @@ -22,7 +25,7 @@ pub struct ConnectScreenData { pub error: String, } -#[derive(Default, PartialEq)] +#[derive(Default, PartialEq, Reflect)] pub enum ConnectState { #[default] Login, diff --git a/client/src/plugins/menu/ui/play/mod.rs b/client/src/plugins/menu/ui/play/mod.rs index aebeff2..100cdcf 100644 --- a/client/src/plugins/menu/ui/play/mod.rs +++ b/client/src/plugins/menu/ui/play/mod.rs @@ -6,18 +6,22 @@ * See LICENSE for licensing information. */ -use bevy::ecs::system::Resource; +use bevy::{ + ecs::{reflect::ReflectResource, system::Resource}, + reflect::Reflect, +}; mod ui; pub use ui::*; -#[derive(Default, Resource)] +#[derive(Default, Resource, Reflect)] +#[reflect(Resource)] pub struct PlayScreenData { pub state: PlayScreenState, pub browse_state: PlayScreenBrowseState, } -#[derive(Default, PartialEq, Clone)] +#[derive(Default, PartialEq, Clone, Reflect)] pub enum PlayScreenState { #[default] Main, @@ -37,7 +41,7 @@ impl PlayScreenState { } } -#[derive(Default, PartialEq)] +#[derive(Default, PartialEq, Reflect)] pub enum PlayScreenBrowseState { #[default] Forming, -- 2.44.1