Commit 74ad2259 authored by Sarah's avatar Sarah
Browse files

Commands: Rename Plugin and Resource appropriately

May want to split commands into a separate plugin in the future
parent 62c5145f
Pipeline #922 passed with stage
in 13 minutes and 41 seconds
......@@ -12,6 +12,7 @@ path = "src/main.rs"
[dependencies]
mc-network = { package = "oxycraft-plugins-mc-network", path = "../plugins/mc-network" }
chat-bar = { package = "chat-bar", path = "../plugins/chat-bar" }
[target.'cfg(unix)'.dependencies]
bevy = { version = "0.5.0", features = ["dynamic"] }
......
use bevy::{app::AppExit, prelude::*};
use chat_bar::CommandsPlugin;
mod main_menu;
......@@ -14,6 +15,7 @@ fn main() {
App::build()
.insert_resource(Msaa { samples: 4 })
.add_plugins(DefaultPlugins)
.add_plugin(CommandsPlugin)
.add_state(GameState::MainMenu)
.add_plugin(main_menu::MenuPlugin)
.add_system_set(
......@@ -67,4 +69,4 @@ fn game_quit(
commands.entity(entity).despawn_recursive();
}
exit_events.send(AppExit);
}
\ No newline at end of file
}
......@@ -19,6 +19,7 @@ impl CommandError {
#[derive(Debug)]
pub enum CommandErrorKind {
FailedToRegister,
CommandAlreadyExists,
FailedToExecute,
}
......
......@@ -15,12 +15,12 @@ trait ChatCommand: Sync + Send {
#[derive(Default)]
struct ChatCommandResource {
struct CommandResource {
registered_commands: HashMap<String, Box<dyn ChatCommand>>,
queued_commands: Vec<Box<dyn ChatCommand>>,
}
impl ChatCommandResource {
impl CommandResource {
pub fn execute_queue(&mut self) {
let mut called_indices: Vec<usize> = vec![];
for (index, command) in self.queued_commands.iter_mut().enumerate() {
......@@ -59,19 +59,19 @@ impl ChatCommand for AboutCommand {
pub struct ChatBarPlugin;
pub struct CommandsPlugin;
impl Plugin for ChatBarPlugin {
impl Plugin for CommandsPlugin {
fn build(&self, builder: &mut bevy::prelude::AppBuilder) {
builder
.insert_resource(ChatCommandResource::default())
.insert_resource(CommandResource::default())
.add_system(startup.system());
}
}
fn startup(
mut _commands: Commands,
mut chat_commands: ResMut<ChatCommandResource>,
mut chat_commands: ResMut<CommandResource>,
) {
chat_commands.register_command(Box::new(AboutCommand)).unwrap();
chat_commands.execute_queue();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment