diff --git a/Cargo.toml b/Cargo.toml index 819012e..308a065 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_console" -version = "0.13.1" +version = "0.14.1" edition = "2021" authors = ["RichoDemus "] homepage = "https://github.com/RichoDemus/bevy-console" @@ -10,16 +10,16 @@ license = "MIT" readme = "README.md" [dependencies] -bevy = { version = "0.15", default-features = false } +bevy = { version = "0.16", default-features = false } clap = { version = "4.5", features = ["derive", "color", "help"] } bevy_console_derive = { path = "./bevy_console_derive", version = "0.5.0" } -bevy_egui = "0.31.1" +bevy_egui = "0.34" shlex = "1.3" ansi-parser = "0.9" strip-ansi-escapes = "0.2" [dev-dependencies] -bevy = { version = "0.15" } +bevy = { version = "0.16" } color-print = { version = "0.3" } [workspace] diff --git a/examples/write_to_console.rs b/examples/write_to_console.rs index 685bea2..5b37630 100644 --- a/examples/write_to_console.rs +++ b/examples/write_to_console.rs @@ -13,5 +13,5 @@ fn main() { } fn write_to_console(mut console_line: EventWriter) { - console_line.send(PrintConsoleLine::new("Hello".into())); + console_line.write(PrintConsoleLine::new("Hello".into())); } diff --git a/src/commands/exit.rs b/src/commands/exit.rs index 02e60eb..413b99c 100644 --- a/src/commands/exit.rs +++ b/src/commands/exit.rs @@ -15,7 +15,7 @@ pub(crate) fn exit_command( mut exit_writer: EventWriter, ) { if let Some(Ok(_)) = exit.take() { - exit_writer.send(AppExit::Success); + exit_writer.write(AppExit::Success); exit.ok(); } } diff --git a/src/console.rs b/src/console.rs index 4c6c78a..081f1f7 100644 --- a/src/console.rs +++ b/src/console.rs @@ -1,6 +1,6 @@ use bevy::ecs::{ component::Tick, - system::{Resource, SystemMeta, SystemParam}, + system::{ScheduleSystem, SystemMeta, SystemParam}, world::unsafe_world_cell::UnsafeWorldCell, }; use bevy::{input::keyboard::KeyboardInput, prelude::*}; @@ -78,27 +78,28 @@ impl ConsoleCommand<'_, T> { /// Print `[ok]` in the console. pub fn ok(&mut self) { - self.console_line.send(PrintConsoleLine::new("[ok]".into())); + self.console_line + .write(PrintConsoleLine::new("[ok]".into())); } /// Print `[failed]` in the console. pub fn failed(&mut self) { self.console_line - .send(PrintConsoleLine::new("[failed]".into())); + .write(PrintConsoleLine::new("[failed]".into())); } /// Print a reply in the console. /// /// See [`reply!`](crate::reply) for usage with the [`format!`] syntax. pub fn reply(&mut self, msg: impl Into) { - self.console_line.send(PrintConsoleLine::new(msg.into())); + self.console_line.write(PrintConsoleLine::new(msg.into())); } /// Print a reply in the console followed by `[ok]`. /// /// See [`reply_ok!`](crate::reply_ok) for usage with the [`format!`] syntax. pub fn reply_ok(&mut self, msg: impl Into) { - self.console_line.send(PrintConsoleLine::new(msg.into())); + self.console_line.write(PrintConsoleLine::new(msg.into())); self.ok(); } @@ -106,7 +107,7 @@ impl ConsoleCommand<'_, T> { /// /// See [`reply_failed!`](crate::reply_failed) for usage with the [`format!`] syntax. pub fn reply_failed(&mut self, msg: impl Into) { - self.console_line.send(PrintConsoleLine::new(msg.into())); + self.console_line.write(PrintConsoleLine::new(msg.into())); self.failed(); } } @@ -168,7 +169,7 @@ unsafe impl SystemParam for ConsoleCommand<'_, T> { return Some(T::from_arg_matches(&matches)); } Err(err) => { - console_line.send(PrintConsoleLine::new(err.to_string())); + console_line.write(PrintConsoleLine::new(err.to_string())); return Some(Err(err)); } } @@ -289,14 +290,14 @@ pub trait AddConsoleCommand { /// ``` fn add_console_command( &mut self, - system: impl IntoSystemConfigs, + system: impl IntoScheduleConfigs, ) -> &mut Self; } impl AddConsoleCommand for App { fn add_console_command( &mut self, - system: impl IntoSystemConfigs, + system: impl IntoScheduleConfigs, ) -> &mut Self { let sys = move |mut config: ResMut| { let command = T::command().no_binary_name(true); @@ -526,7 +527,7 @@ pub(crate) fn console_ui( if command.is_some() { command_entered - .send(ConsoleCommandEntered { command_name, args }); + .write(ConsoleCommandEntered { command_name, args }); } else { debug!( "Command not recognized, recognized commands: `{:?}`", @@ -631,6 +632,7 @@ mod tests { state: ButtonState::Pressed, window: Entity::PLACEHOLDER, repeat: false, + text: None, }; let config = vec![KeyCode::Unidentified(NativeKeyCode::Xkb(41))]; @@ -647,6 +649,7 @@ mod tests { state: ButtonState::Pressed, window: Entity::PLACEHOLDER, repeat: false, + text: None, }; let config = vec![KeyCode::Unidentified(NativeKeyCode::Xkb(41))]; @@ -663,6 +666,7 @@ mod tests { state: ButtonState::Pressed, window: Entity::PLACEHOLDER, repeat: false, + text: None, }; let config = vec![KeyCode::Backquote]; @@ -679,6 +683,7 @@ mod tests { state: ButtonState::Pressed, window: Entity::PLACEHOLDER, repeat: false, + text: None, }; let config = vec![KeyCode::Backquote]; @@ -695,6 +700,7 @@ mod tests { state: ButtonState::Released, window: Entity::PLACEHOLDER, repeat: false, + text: None, }; let config = vec![KeyCode::Backquote]; diff --git a/src/lib.rs b/src/lib.rs index 816b160..01e00f5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,7 @@ use bevy::prelude::*; pub use bevy_console_derive::ConsoleCommand; -use bevy_egui::EguiPlugin; +use bevy_egui::{EguiContextPass, EguiPlugin}; use crate::commands::clear::{clear_command, ClearCommand}; use crate::commands::exit::{exit_command, ExitCommand}; @@ -58,14 +58,14 @@ impl Plugin for ConsolePlugin { .add_console_command::(exit_command) .add_console_command::(help_command) .add_systems( - Update, + EguiContextPass, ( console_ui.in_set(ConsoleSet::ConsoleUI), receive_console_line.in_set(ConsoleSet::PostCommands), ), ) .configure_sets( - Update, + EguiContextPass, ( ConsoleSet::Commands .after(ConsoleSet::ConsoleUI) @@ -77,7 +77,9 @@ impl Plugin for ConsolePlugin { // Don't initialize an egui plugin if one already exists. // This can happen if another plugin is using egui and was installed before us. if !app.is_plugin_added::() { - app.add_plugins(EguiPlugin); + app.add_plugins(EguiPlugin { + enable_multipass_for_primary_context: true, + }); } } } diff --git a/src/log.rs b/src/log.rs index 745c7f6..567fece 100644 --- a/src/log.rs +++ b/src/log.rs @@ -6,7 +6,7 @@ use std::{ use bevy::{ app::{App, Update}, log::tracing_subscriber::{self, EnvFilter, Layer, Registry}, - prelude::{EventWriter, IntoSystemConfigs, ResMut, Resource}, + prelude::{EventWriter, IntoScheduleConfigs, ResMut, Resource}, }; use crate::{ConsoleSet, PrintConsoleLine}; @@ -51,7 +51,7 @@ pub fn send_log_buffer_to_console( // read and clean buffer let buffer = buffer.get_mut(); for line in buffer.lines().map_while(Result::ok) { - console_lines.send(PrintConsoleLine { line }); + console_lines.write(PrintConsoleLine { line }); } buffer.clear(); } @@ -99,23 +99,20 @@ fn setup_layer( send_log_buffer_to_console.in_set(ConsoleSet::PostCommands), ); - let layer: Box + Send + Sync>; - layer = if let Some(filter) = filter { - // Layer::with_filter() returns a different impl, thus the split - Box::new( + let layer: Box + Send + Sync> = match filter { + Some(filter) => Box::new( tracing_subscriber::fmt::Layer::new() .with_target(false) .with_ansi(true) .with_writer(move || BevyLogBufferWriter(buffer.clone())) .with_filter(filter), - ) - } else { - Box::new( + ), + None => Box::new( tracing_subscriber::fmt::Layer::new() .with_target(false) .with_ansi(true) .with_writer(move || BevyLogBufferWriter(buffer.clone())), - ) + ), }; Some(layer)