refactor console to take DebugEvents directly

This commit is contained in:
Schrottkatze 2025-06-18 15:40:33 +02:00
parent cf05050c95
commit 3157af2c2b
Signed by: schrottkatze
SSH key fingerprint: SHA256:FPOYVeBy3QP20FEM42uWF1Wa/Qhlk+L3S2+Wuau/Auo
3 changed files with 11 additions and 14 deletions

View file

@ -1,11 +1,17 @@
use bevy::prelude::*;
use clap::Subcommand;
mod console;
#[derive(Event)]
#[derive(Event, Debug, Subcommand)]
enum DebugEvent {
/// Close the debug console.
#[command(name = "close", aliases = ["close-console"])]
CloseDebugConsole,
PrintToConsole(String),
/// Output a string to the console.
#[command(name = "echo", aliases = ["print", "print-to-console"])]
PrintToConsole { text: String },
}
pub(super) fn plugin(app: &mut App) {

View file

@ -98,7 +98,7 @@ fn execute_console_events(
for ev in ev_reader.read() {
match ev {
DebugEvent::CloseDebugConsole => next_state.set(ConsoleState::Closed),
DebugEvent::PrintToConsole(s) => log.output(s),
DebugEvent::PrintToConsole { text } => log.output(text),
_ => todo!(),
};
}

View file

@ -12,21 +12,12 @@ pub(super) fn respond(line: &str) -> Result<DebugEvent, String> {
return Ok(DebugEvent::PrintToConsole(s));
}
Ok(match cli?.cmd {
Commands::Close => DebugEvent::CloseDebugConsole,
Commands::Echo { text } => DebugEvent::PrintToConsole(text),
})
Ok(cli?.cmd)
}
#[derive(Debug, Parser)]
#[command(multicall = true)]
struct Cli {
#[command(subcommand)]
cmd: Commands,
}
#[derive(Debug, Subcommand)]
enum Commands {
Close,
Echo { text: String },
cmd: DebugEvent,
}