73 lines
2.4 KiB
Rust
73 lines
2.4 KiB
Rust
// use crate::dice;
|
|
// use crate::VERSION;
|
|
use bevy::{
|
|
app::{AppBuilder, EventReader, EventWriter, Plugin},
|
|
prelude::IntoSystem,
|
|
};
|
|
use bevy_console::{
|
|
ConsoleCommandEntered, ConsoleConfiguration, ConsolePlugin, HelpCommand, PrintConsoleLine,
|
|
};
|
|
|
|
pub struct ConsoleManager;
|
|
impl Plugin for ConsoleManager {
|
|
fn build(&self, app: &mut AppBuilder) {
|
|
// add things to your app here
|
|
|
|
app.add_plugin(ConsolePlugin)
|
|
.insert_resource(ConsoleConfiguration {
|
|
help: vec![
|
|
HelpCommand::new(
|
|
"dice".to_string(),
|
|
"Usage: dice <number of dice>d<dice sides>".to_string(),
|
|
),
|
|
HelpCommand::new(
|
|
"version".to_string(),
|
|
"prints the client version".to_string(),
|
|
),
|
|
],
|
|
..Default::default()
|
|
})
|
|
.add_system(listen_to_console_events.system());
|
|
}
|
|
}
|
|
fn listen_to_console_events(
|
|
mut console_events: EventReader<ConsoleCommandEntered>,
|
|
mut console_line: EventWriter<PrintConsoleLine>,
|
|
) {
|
|
for event in console_events.iter() {
|
|
let command: &str = &event.command;
|
|
|
|
// only useful for debuging
|
|
// println!("{:?}", event);
|
|
match command {
|
|
"hi" => {
|
|
console_line.send(PrintConsoleLine::new("Hello".to_string()));
|
|
}
|
|
"dice" => {
|
|
// console_line.send(PrintConsoleLine::new(dice(&event.args).to_string()));
|
|
}
|
|
"ban" => {
|
|
if &event.args == "" {
|
|
console_line.send(PrintConsoleLine::new("No user provided".to_string()));
|
|
} else {
|
|
let user_list = event.args.split(" ");
|
|
|
|
for user in user_list {
|
|
console_line.send(PrintConsoleLine::new(
|
|
format!("Banned {}", user).to_string(),
|
|
));
|
|
}
|
|
}
|
|
}
|
|
"version" => {
|
|
let version = format!("Current client version is ");
|
|
console_line.send(PrintConsoleLine::new(version.to_string()));
|
|
}
|
|
error => console_line.send(PrintConsoleLine::new(format!(
|
|
"Command {} not found",
|
|
error
|
|
))),
|
|
}
|
|
}
|
|
}
|