diff --git a/bevy_forge/Cargo.toml b/bevy_forge/Cargo.toml index 5301e71..d922223 100644 --- a/bevy_forge/Cargo.toml +++ b/bevy_forge/Cargo.toml @@ -29,7 +29,7 @@ serde_json = "1.0" futures-lite = "2.2.0" bevy_pkv = "0.9.1" bevy_button_released_plugin = "0.3.1" -bevy_simple_text_input = {version = "0.3.2", git="https://github.com/Leinnan/bevy_simple_text_input"} +bevy_simple_text_input = {git="https://github.com/Leinnan/bevy_simple_text_input"} bevy_args = "1.2.0" clap = { version = "4.4", features = ["derive"] } diff --git a/bevy_forge/src/debug.rs b/bevy_forge/src/debug.rs index f6dc427..06ae7b3 100644 --- a/bevy_forge/src/debug.rs +++ b/bevy_forge/src/debug.rs @@ -12,9 +12,17 @@ impl Plugin for DebugPlugin { fn build(&self, app: &mut App) { app.add_systems(Startup, git_info) .add_plugins(EguiPlugin) - .add_plugins(WorldInspectorPlugin::new().run_if(input_toggle_active(true, KeyCode::F1))) - .add_plugins(StateInspectorPlugin::::default()) - .add_plugins(StateInspectorPlugin::::default()); + .add_plugins( + WorldInspectorPlugin::new().run_if(input_toggle_active(false, KeyCode::F1)), + ) + .add_plugins( + StateInspectorPlugin::::default() + .run_if(input_toggle_active(false, KeyCode::F1)), + ) + .add_plugins( + StateInspectorPlugin::::default() + .run_if(input_toggle_active(false, KeyCode::F1)), + ); } } diff --git a/bevy_forge/src/main.rs b/bevy_forge/src/main.rs index 420c95d..e55e41b 100644 --- a/bevy_forge/src/main.rs +++ b/bevy_forge/src/main.rs @@ -1,11 +1,7 @@ -use std::time::Duration; - -use beam::{context::BeamContext, BeamPlugin}; - -use bevy::{asset::AssetMetaCheck, prelude::*, time::common_conditions::on_timer}; +use beam::BeamPlugin; +use bevy::{asset::AssetMetaCheck, prelude::*}; use bevy_args::BevyArgsPlugin; use debug::DebugPlugin; -use game::components::RequestText; use utils::GameArgs; pub mod beam; @@ -20,53 +16,17 @@ pub mod utils; fn main() { App::new() .insert_resource(ClearColor(consts::MY_BG_COLOR)) + .add_plugins(DefaultPlugins) + .add_plugins(BevyArgsPlugin::::default()) + .insert_resource(bevy_pkv::PkvStore::new("Beamable", "AiForge")) + // Never attempts to look up meta files. The default meta configuration will be used for each asset. + .insert_resource(AssetMetaCheck::Never) .add_plugins(( - DefaultPlugins, DebugPlugin, BeamPlugin, microservice::MicroservicePlugin, game::GamePlugin, states::GameStatesPlugin, )) - .add_plugins(BevyArgsPlugin::::default()) - .insert_resource(bevy_pkv::PkvStore::new("Beamable", "AiForge")) - // Never attempts to look up meta files. The default meta configuration will be used for each asset. - .insert_resource(AssetMetaCheck::Never) - .add_systems(Update, handle_request) - .add_systems( - Update, - send_request.run_if(on_timer(Duration::from_secs(5))), - ) .run(); } - -fn handle_request( - mut event_completed: EventReader, - mut text_query: Query<&mut Text, With>, -) { - let Ok(mut text) = text_query.get_single_mut() else { - return; - }; - for result in event_completed.read() { - let txt = match result.as_deref() { - Ok(response) => response.to_string(), - Err(error) => format!("{:#?}", error), - }; - text.sections[0].value = format!("Microservice request result:\n{}", txt); - text.sections[0].style.color = if result.is_ok() { - Color::YELLOW_GREEN - } else { - Color::ORANGE_RED - }; - } -} - -fn send_request(mut ev: EventWriter, context: Option>) { - let Some(ctx) = context else { - return; - }; - - ev.send(microservice::SayHiEvent( - beam_microservice::models::SayHiRequestArgs::new(ctx.get_name().to_owned()), - )); -} diff --git a/bevy_forge/src/states/login_screen.rs b/bevy_forge/src/states/login_screen.rs index 084c05d..1255231 100644 --- a/bevy_forge/src/states/login_screen.rs +++ b/bevy_forge/src/states/login_screen.rs @@ -40,7 +40,9 @@ fn handle_buttons( mut beam: ResMut, ) { if let Ok(text) = text.get_single() { - beam.name = Some((**text).clone()); + if !text.0.is_empty() { + beam.name = Some((**text).clone()); + } } for event in reader.read() { let Ok(button) = q.get(**event) else { diff --git a/bevy_forge/src/states/menu.rs b/bevy_forge/src/states/menu.rs index ccb9de8..7967326 100644 --- a/bevy_forge/src/states/menu.rs +++ b/bevy_forge/src/states/menu.rs @@ -1,5 +1,9 @@ +use crate::game::components::RequestText; use bevy::prelude::*; +use bevy::time::common_conditions::on_timer; +use std::time::Duration; +use crate::microservice; use crate::{consts, game::components::*, utils::despawn_recursive_by_component}; pub struct MenuStatePlugin; @@ -9,6 +13,13 @@ impl Plugin for MenuStatePlugin { app.add_systems( OnEnter(super::MainGameState::Menu), (setup, despawn_recursive_by_component::), + ) + .add_systems(Update, handle_request) + .add_systems( + Update, + send_request.run_if( + on_timer(Duration::from_secs(5)).and_then(in_state(super::MainGameState::Menu)), + ), ); } } @@ -80,3 +91,33 @@ fn setup( }); }); } + +fn handle_request( + mut event_completed: EventReader, + mut text_query: Query<&mut Text, With>, +) { + let Ok(mut text) = text_query.get_single_mut() else { + return; + }; + for result in event_completed.read() { + let txt = match result.as_deref() { + Ok(response) => response.to_string(), + Err(error) => format!("{:#?}", error), + }; + text.sections[0].value = format!("Microservice request result:\n{}", txt); + text.sections[0].style.color = if result.is_ok() { + Color::YELLOW_GREEN + } else { + Color::ORANGE_RED + }; + } +} + +fn send_request( + mut ev: EventWriter, + context: Res, +) { + ev.send(microservice::SayHiEvent( + beam_microservice::models::SayHiRequestArgs::new(context.get_name().to_owned()), + )); +}