-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathlog_command.rs
More file actions
38 lines (32 loc) · 938 Bytes
/
Copy pathlog_command.rs
File metadata and controls
38 lines (32 loc) · 938 Bytes
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
use bevy::prelude::*;
use bevy_console::{AddConsoleCommand, ConsoleCommand, ConsolePlugin, reply};
use clap::Parser;
fn main() {
App::new()
// set background to red
.add_plugins((DefaultPlugins, ConsolePlugin))
.add_systems(Startup, setup_camera_system)
.add_console_command::<LogCommand, _>(log_command)
.run();
}
fn setup_camera_system(mut commands: Commands) {
commands.spawn(Camera2d);
}
/// Prints given arguments to the console
#[derive(Parser, ConsoleCommand)]
#[command(name = "log")]
struct LogCommand {
/// Message to print
msg: String,
/// Number of times to print message
num: Option<i64>,
}
fn log_command(mut log: ConsoleCommand<LogCommand>) {
if let Some(Ok(LogCommand { msg, num })) = log.take() {
let repeat_count = num.unwrap_or(1);
for _ in 0..repeat_count {
reply!(log, "{msg}");
}
log.ok();
}
}