Skip to content

Upgrade to bevy 0.16.0 #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_console"
version = "0.13.1"
version = "0.14.1"
edition = "2021"
authors = ["RichoDemus <git@richodemus.com>"]
homepage = "https://github.com/RichoDemus/bevy-console"
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion examples/write_to_console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ fn main() {
}

fn write_to_console(mut console_line: EventWriter<PrintConsoleLine>) {
console_line.send(PrintConsoleLine::new("Hello".into()));
console_line.write(PrintConsoleLine::new("Hello".into()));
}
2 changes: 1 addition & 1 deletion src/commands/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub(crate) fn exit_command(
mut exit_writer: EventWriter<AppExit>,
) {
if let Some(Ok(_)) = exit.take() {
exit_writer.send(AppExit::Success);
exit_writer.write(AppExit::Success);
exit.ok();
}
}
26 changes: 16 additions & 10 deletions src/console.rs
Original file line number Diff line number Diff line change
@@ -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::*};
Expand Down Expand Up @@ -78,35 +78,36 @@ impl<T> 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<String>) {
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<String>) {
self.console_line.send(PrintConsoleLine::new(msg.into()));
self.console_line.write(PrintConsoleLine::new(msg.into()));
self.ok();
}

/// Print a reply in the console followed by `[failed]`.
///
/// See [`reply_failed!`](crate::reply_failed) for usage with the [`format!`] syntax.
pub fn reply_failed(&mut self, msg: impl Into<String>) {
self.console_line.send(PrintConsoleLine::new(msg.into()));
self.console_line.write(PrintConsoleLine::new(msg.into()));
self.failed();
}
}
Expand Down Expand Up @@ -168,7 +169,7 @@ unsafe impl<T: Command> 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));
}
}
Expand Down Expand Up @@ -289,14 +290,14 @@ pub trait AddConsoleCommand {
/// ```
fn add_console_command<T: Command, Params>(
&mut self,
system: impl IntoSystemConfigs<Params>,
system: impl IntoScheduleConfigs<ScheduleSystem, Params>,
) -> &mut Self;
}

impl AddConsoleCommand for App {
fn add_console_command<T: Command, Params>(
&mut self,
system: impl IntoSystemConfigs<Params>,
system: impl IntoScheduleConfigs<ScheduleSystem, Params>,
) -> &mut Self {
let sys = move |mut config: ResMut<ConsoleConfiguration>| {
let command = T::command().no_binary_name(true);
Expand Down Expand Up @@ -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: `{:?}`",
Expand Down Expand Up @@ -631,6 +632,7 @@ mod tests {
state: ButtonState::Pressed,
window: Entity::PLACEHOLDER,
repeat: false,
text: None,
};

let config = vec![KeyCode::Unidentified(NativeKeyCode::Xkb(41))];
Expand All @@ -647,6 +649,7 @@ mod tests {
state: ButtonState::Pressed,
window: Entity::PLACEHOLDER,
repeat: false,
text: None,
};

let config = vec![KeyCode::Unidentified(NativeKeyCode::Xkb(41))];
Expand All @@ -663,6 +666,7 @@ mod tests {
state: ButtonState::Pressed,
window: Entity::PLACEHOLDER,
repeat: false,
text: None,
};

let config = vec![KeyCode::Backquote];
Expand All @@ -679,6 +683,7 @@ mod tests {
state: ButtonState::Pressed,
window: Entity::PLACEHOLDER,
repeat: false,
text: None,
};

let config = vec![KeyCode::Backquote];
Expand All @@ -695,6 +700,7 @@ mod tests {
state: ButtonState::Released,
window: Entity::PLACEHOLDER,
repeat: false,
text: None,
};

let config = vec![KeyCode::Backquote];
Expand Down
10 changes: 6 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -58,14 +58,14 @@ impl Plugin for ConsolePlugin {
.add_console_command::<ExitCommand, _>(exit_command)
.add_console_command::<HelpCommand, _>(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)
Expand All @@ -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::<EguiPlugin>() {
app.add_plugins(EguiPlugin);
app.add_plugins(EguiPlugin {
enable_multipass_for_primary_context: true,
});
}
}
}
17 changes: 7 additions & 10 deletions src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -99,23 +99,20 @@ fn setup_layer(
send_log_buffer_to_console.in_set(ConsoleSet::PostCommands),
);

let layer: Box<dyn tracing_subscriber::Layer<Registry> + Send + Sync>;
layer = if let Some(filter) = filter {
// Layer::with_filter() returns a different impl, thus the split
Box::new(
let layer: Box<dyn tracing_subscriber::Layer<Registry> + 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)
Expand Down