valence_command/
lib.rs

1pub mod graph;
2pub mod handler;
3pub mod manager;
4mod modifier_value;
5pub mod parsers;
6pub mod scopes;
7
8use std::collections::{HashMap, HashSet};
9use std::fmt::Debug;
10
11use bevy_app::App;
12use bevy_ecs::prelude::{Resource, SystemSet};
13pub use manager::{CommandExecutionEvent, CommandProcessedEvent};
14pub use modifier_value::ModifierValue;
15use petgraph::prelude::NodeIndex;
16pub use scopes::CommandScopeRegistry;
17
18use crate::graph::{CommandGraph, CommandGraphBuilder};
19use crate::handler::CommandHandlerPlugin;
20use crate::parsers::ParseInput;
21
22#[derive(SystemSet, Clone, PartialEq, Eq, Hash, Debug)]
23pub struct CommandSystemSet;
24
25#[derive(Resource, Default)]
26#[allow(clippy::type_complexity)]
27pub struct CommandRegistry {
28    pub graph: CommandGraph,
29    pub parsers: HashMap<NodeIndex, fn(&mut ParseInput) -> bool>,
30    pub modifiers: HashMap<NodeIndex, fn(String, &mut HashMap<ModifierValue, ModifierValue>)>,
31    pub executables: HashSet<NodeIndex>,
32}
33
34pub trait Command {
35    fn assemble_graph(graph: &mut CommandGraphBuilder<Self>)
36    where
37        Self: Sized;
38}
39
40pub trait AddCommand {
41    fn add_command<T: Command + Send + Sync + 'static>(&mut self) -> &mut Self;
42}
43
44impl AddCommand for App {
45    fn add_command<T: Command + Send + Sync + 'static>(&mut self) -> &mut Self {
46        self.add_plugins(CommandHandlerPlugin::<T>::new())
47    }
48}