1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#![doc = include_str ! ("../README.md")]
#![deny(missing_docs)]
use bevy::prelude::*;
pub use bevy_console_derive::ConsoleCommand;
use bevy_egui::{EguiPlugin, EguiSettings};
use crate::commands::clear::{clear_command, ClearCommand};
use crate::commands::exit::{exit_command, ExitCommand};
use crate::commands::help::{help_command, HelpCommand};
pub use crate::console::{
AddConsoleCommand, Command, ConsoleCommand, ConsoleCommandEntered, ConsoleConfiguration,
ConsoleOpen, NamedCommand, PrintConsoleLine, ToggleConsoleKey,
};
use crate::console::{console_ui, receive_console_line, ConsoleState};
mod commands;
mod console;
mod macros;
pub struct ConsolePlugin;
#[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone)]
pub enum ConsoleSet {
ConsoleUI,
Commands,
PostCommands,
}
fn have_commands(commands: EventReader<ConsoleCommandEntered>) -> bool {
!commands.is_empty()
}
impl Plugin for ConsolePlugin {
fn build(&self, app: &mut App) {
app.init_resource::<ConsoleConfiguration>()
.init_resource::<ConsoleState>()
.init_resource::<ConsoleOpen>()
.add_event::<ConsoleCommandEntered>()
.add_event::<PrintConsoleLine>()
.add_console_command::<ClearCommand, _>(clear_command)
.add_console_command::<ExitCommand, _>(exit_command)
.add_console_command::<HelpCommand, _>(help_command)
.add_system(console_ui.in_set(ConsoleSet::ConsoleUI))
.add_system(receive_console_line.in_set(ConsoleSet::PostCommands))
.configure_set(
ConsoleSet::Commands
.after(ConsoleSet::ConsoleUI)
.run_if(have_commands),
)
.configure_set(ConsoleSet::PostCommands.after(ConsoleSet::Commands));
if !app.world.contains_resource::<EguiSettings>() {
app.add_plugin(EguiPlugin);
}
}
}