mirror of
https://codeberg.org/schrottkatze/mgd2-tram-championships.git
synced 2025-07-02 01:27:39 +00:00
refactor console to take DebugEvent
s directly
This commit is contained in:
parent
cf05050c95
commit
3157af2c2b
3 changed files with 11 additions and 14 deletions
|
@ -1,11 +1,17 @@
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
use clap::Subcommand;
|
||||||
|
|
||||||
mod console;
|
mod console;
|
||||||
|
|
||||||
#[derive(Event)]
|
#[derive(Event, Debug, Subcommand)]
|
||||||
enum DebugEvent {
|
enum DebugEvent {
|
||||||
|
/// Close the debug console.
|
||||||
|
#[command(name = "close", aliases = ["close-console"])]
|
||||||
CloseDebugConsole,
|
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) {
|
pub(super) fn plugin(app: &mut App) {
|
||||||
|
|
|
@ -98,7 +98,7 @@ fn execute_console_events(
|
||||||
for ev in ev_reader.read() {
|
for ev in ev_reader.read() {
|
||||||
match ev {
|
match ev {
|
||||||
DebugEvent::CloseDebugConsole => next_state.set(ConsoleState::Closed),
|
DebugEvent::CloseDebugConsole => next_state.set(ConsoleState::Closed),
|
||||||
DebugEvent::PrintToConsole(s) => log.output(s),
|
DebugEvent::PrintToConsole { text } => log.output(text),
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,21 +12,12 @@ pub(super) fn respond(line: &str) -> Result<DebugEvent, String> {
|
||||||
return Ok(DebugEvent::PrintToConsole(s));
|
return Ok(DebugEvent::PrintToConsole(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(match cli?.cmd {
|
Ok(cli?.cmd)
|
||||||
Commands::Close => DebugEvent::CloseDebugConsole,
|
|
||||||
Commands::Echo { text } => DebugEvent::PrintToConsole(text),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[command(multicall = true)]
|
#[command(multicall = true)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
cmd: Commands,
|
cmd: DebugEvent,
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Subcommand)]
|
|
||||||
enum Commands {
|
|
||||||
Close,
|
|
||||||
Echo { text: String },
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue