diff --git a/Cargo.toml b/Cargo.toml index ac192f3..59a7f29 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_console" -version = "0.14.1" +version = "0.15.0" edition = "2021" authors = ["RichoDemus "] homepage = "https://github.com/RichoDemus/bevy-console" @@ -10,23 +10,23 @@ license = "MIT" readme = "README.md" [dependencies] -bevy = { version = "0.16", default-features = false, features = [ +bevy = { version = "0.17", default-features = false, features = [ "std", "bevy_log", ] } clap = { version = "4.5", features = ["derive"] } bevy_console_derive = { path = "./bevy_console_derive", version = "0.5.0" } -bevy_egui = { version = "0.34", default-features = false, features = [ +bevy_egui = { version = "0.37", default-features = false, features = [ "render", "default_fonts", ] } shlex = "1.3" ansi-parser = "0.9" strip-ansi-escapes = "0.2" -trie-rs = "0.2" +trie-rs = "0.4" [dev-dependencies] -bevy = { version = "0.16", features = ["std", "bevy_log"] } +bevy = { version = "0.17", features = ["std", "bevy_log"] } color-print = { version = "0.3" } diff --git a/examples/capture_bevy_logs.rs b/examples/capture_bevy_logs.rs index 2f78392..600d8fa 100644 --- a/examples/capture_bevy_logs.rs +++ b/examples/capture_bevy_logs.rs @@ -9,6 +9,7 @@ fn main() { level: log::Level::INFO, filter: "error,capture_bevy_logs=info".to_owned(), custom_layer: make_layer, + ..default() }), ConsolePlugin, )) diff --git a/examples/raw_commands.rs b/examples/raw_commands.rs index 00a047d..1eafd7f 100644 --- a/examples/raw_commands.rs +++ b/examples/raw_commands.rs @@ -8,7 +8,7 @@ fn main() { .run(); } -fn raw_commands(mut console_commands: EventReader) { +fn raw_commands(mut console_commands: MessageReader) { for ConsoleCommandEntered { command_name, args } in console_commands.read() { println!(r#"Entered command "{command_name}" with args {:#?}"#, args); } diff --git a/examples/write_to_console.rs b/examples/write_to_console.rs index 5b37630..0324341 100644 --- a/examples/write_to_console.rs +++ b/examples/write_to_console.rs @@ -12,6 +12,6 @@ fn main() { .run(); } -fn write_to_console(mut console_line: EventWriter) { +fn write_to_console(mut console_line: MessageWriter) { console_line.write(PrintConsoleLine::new("Hello".into())); } diff --git a/src/commands/exit.rs b/src/commands/exit.rs index 413b99c..7b87767 100644 --- a/src/commands/exit.rs +++ b/src/commands/exit.rs @@ -12,7 +12,7 @@ pub(crate) struct ExitCommand; pub(crate) fn exit_command( mut exit: ConsoleCommand, - mut exit_writer: EventWriter, + mut exit_writer: MessageWriter, ) { if let Some(Ok(_)) = exit.take() { exit_writer.write(AppExit::Success); diff --git a/src/console.rs b/src/console.rs index 81c5674..7f84b30 100644 --- a/src/console.rs +++ b/src/console.rs @@ -27,9 +27,9 @@ use crate::{ ConsoleSet, }; -type ConsoleCommandEnteredReaderSystemParam = EventReader<'static, 'static, ConsoleCommandEntered>; +type ConsoleCommandEnteredReaderSystemParam = MessageReader<'static, 'static, ConsoleCommandEntered>; -type PrintConsoleLineWriterSystemParam = EventWriter<'static, PrintConsoleLine>; +type PrintConsoleLineWriterSystemParam = MessageWriter<'static, PrintConsoleLine>; /// A super-trait for command like structures pub trait Command: NamedCommand + CommandFactory + FromArgMatches + Sized + Resource {} @@ -69,7 +69,7 @@ pub trait NamedCommand { /// ``` pub struct ConsoleCommand<'w, T> { command: Option>, - console_line: EventWriter<'w, PrintConsoleLine>, + console_line: MessageWriter<'w, PrintConsoleLine>, } impl ConsoleCommand<'_, T> { @@ -119,7 +119,7 @@ impl ConsoleCommand<'_, T> { pub struct ConsoleCommandState { #[allow(clippy::type_complexity)] - event_reader: ::State, + message_reader: ::State, console_line: ::State, marker: PhantomData, } @@ -128,15 +128,23 @@ unsafe impl SystemParam for ConsoleCommand<'_, T> { type State = ConsoleCommandState; type Item<'w, 's> = ConsoleCommand<'w, T>; - fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State { - let event_reader = ConsoleCommandEnteredReaderSystemParam::init_state(world, system_meta); - let console_line = PrintConsoleLineWriterSystemParam::init_state(world, system_meta); + fn init_state(world: &mut World) -> Self::State { + let message_reader = ConsoleCommandEnteredReaderSystemParam::init_state(world); + let console_line = PrintConsoleLineWriterSystemParam::init_state(world); ConsoleCommandState { - event_reader, + message_reader, console_line, marker: PhantomData, } } + + fn init_access( + _state: &Self::State, + _system_meta: &mut SystemMeta, + _component_access_set: &mut bevy::ecs::query::FilteredAccessSet, + _world: &mut World, + ) { + } #[inline] unsafe fn get_param<'w, 's>( @@ -145,8 +153,8 @@ unsafe impl SystemParam for ConsoleCommand<'_, T> { world: UnsafeWorldCell<'w>, change_tick: Tick, ) -> Self::Item<'w, 's> { - let mut event_reader = ConsoleCommandEnteredReaderSystemParam::get_param( - &mut state.event_reader, + let mut message_reader = ConsoleCommandEnteredReaderSystemParam::get_param( + &mut state.message_reader, system_meta, world, change_tick, @@ -158,7 +166,7 @@ unsafe impl SystemParam for ConsoleCommand<'_, T> { change_tick, ); - let command = event_reader.read().find_map(|command| { + let command = message_reader.read().find_map(|command| { if T::name() == command.command_name { let clap_command = T::command().no_binary_name(true); // .color(clap::ColorChoice::Always); @@ -189,7 +197,7 @@ unsafe impl SystemParam for ConsoleCommand<'_, T> { } } /// Parsed raw console command into `command` and `args`. -#[derive(Clone, Debug, Event)] +#[derive(Clone, Debug, Message)] pub struct ConsoleCommandEntered { /// the command definition pub command_name: String, @@ -197,8 +205,8 @@ pub struct ConsoleCommandEntered { pub args: Vec, } -/// Events to print to the console. -#[derive(Clone, Debug, Eq, Event, PartialEq)] +/// Messages to print to the console. +#[derive(Clone, Debug, Eq, Message, PartialEq)] pub struct PrintConsoleLine { /// Console line pub line: String, @@ -488,15 +496,15 @@ pub(crate) fn console_ui( mut egui_context: EguiContexts, config: Res, mut cache: ResMut, - mut keyboard_input_events: EventReader, + mut keyboard_input_events: MessageReader, mut state: ResMut, - command_entered: EventWriter, + command_entered: MessageWriter, mut console_open: ResMut, ) { let keyboard_input_events = keyboard_input_events.read().collect::>(); // If there is no egui context, return, this can happen when exiting the app - let ctx = if let Some(ctxt) = egui_context.try_ctx_mut() { + let ctx = if let Ok(ctxt) = egui_context.ctx_mut() { ctxt } else { return; @@ -669,7 +677,7 @@ fn handle_enter( config: Res<'_, ConsoleConfiguration>, cache: &ResMut<'_, ConsoleCache>, state: &mut ResMut<'_, ConsoleState>, - mut command_entered: EventWriter<'_, ConsoleCommandEntered>, + mut command_entered: MessageWriter<'_, ConsoleCommandEntered>, ui: &mut egui::Ui, text_edit_response: &egui::Response, ) { @@ -725,11 +733,11 @@ fn handle_enter( pub(crate) fn receive_console_line( mut console_state: ResMut, - mut events: EventReader, + mut messages: MessageReader, ) { - for event in events.read() { - let event: &PrintConsoleLine = event; - console_state.scrollback.push(event.line.clone()); + for message in messages.read() { + let message: &PrintConsoleLine = message; + console_state.scrollback.push(message.line.clone()); } } @@ -765,7 +773,7 @@ pub fn block_mouse_input( return; } - let Some(context) = contexts.try_ctx_mut() else { + let Ok(context) = contexts.ctx_mut() else { return; }; @@ -783,7 +791,7 @@ pub fn block_keyboard_input( return; } - let Some(context) = contexts.try_ctx_mut() else { + let Ok(context) = contexts.ctx_mut() else { return; }; diff --git a/src/lib.rs b/src/lib.rs index 99d6e42..a2866e9 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::{EguiContextPass, EguiPlugin, EguiPreUpdateSet}; +use bevy_egui::{EguiPlugin, EguiPreUpdateSet, EguiPrimaryContextPass}; use console::{block_keyboard_input, block_mouse_input, ConsoleCache}; use trie_rs::TrieBuilder; @@ -42,13 +42,13 @@ pub enum ConsoleSet { Commands, /// Systems running after command systems, which depend on the fact commands have executed beforehand (the output layer). - /// For example a system which makes use of [`PrintConsoleLine`] events should be placed in this set to be able to receive + /// For example a system which makes use of [`PrintConsoleLine`] messages should be placed in this set to be able to receive /// New lines to print in the same frame PostCommands, } /// Run condition which does not run any command systems if no command was entered -fn have_commands(commands: EventReader) -> bool { +fn have_commands(commands: MessageReader) -> bool { !commands.is_empty() } @@ -72,8 +72,8 @@ impl Plugin for ConsolePlugin { .init_resource::() .init_resource::() .init_resource::() - .add_event::() - .add_event::() + .add_message::() + .add_message::() .add_console_command::(clear_command) .add_console_command::(exit_command) .add_console_command::(help_command) @@ -86,14 +86,14 @@ impl Plugin for ConsolePlugin { .before(EguiPreUpdateSet::BeginPass), ) .add_systems( - EguiContextPass, + EguiPrimaryContextPass, ( console_ui.in_set(ConsoleSet::ConsoleUI), receive_console_line.in_set(ConsoleSet::PostCommands), ), ) .configure_sets( - EguiContextPass, + EguiPrimaryContextPass, ( ConsoleSet::Commands .after(ConsoleSet::ConsoleUI) @@ -105,9 +105,7 @@ 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 { - enable_multipass_for_primary_context: true, - }); + app.add_plugins(EguiPlugin::default()); } } } diff --git a/src/log.rs b/src/log.rs index 567fece..28611c4 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, IntoScheduleConfigs, ResMut, Resource}, + prelude::{MessageWriter, IntoScheduleConfigs, ResMut, Resource}, }; use crate::{ConsoleSet, PrintConsoleLine}; @@ -45,7 +45,7 @@ impl Write for BevyLogBufferWriter { /// Flushes the log buffer and sends its content to the console pub fn send_log_buffer_to_console( buffer: ResMut, - mut console_lines: EventWriter, + mut console_lines: MessageWriter, ) { let mut buffer = buffer.0.lock().unwrap(); // read and clean buffer