diff --git a/game/src/inventory/systems.rs b/game/src/inventory/systems.rs index bf414d7..1152893 100644 --- a/game/src/inventory/systems.rs +++ b/game/src/inventory/systems.rs @@ -29,6 +29,7 @@ pub fn apply_command( "Failed to add {:?} to the inventory as it doesn't exist.", item, ); + reply!(command, "Run \"item list\" to see available items.") }, } }, diff --git a/game/src/items/commands.rs b/game/src/items/commands.rs new file mode 100644 index 0000000..ef0b8be --- /dev/null +++ b/game/src/items/commands.rs @@ -0,0 +1,16 @@ +use crate::prelude::*; + +/// Controls the items. +#[derive(ConsoleCommand, Parser)] +#[command(name = "item")] +#[command(disable_help_flag = true)] +pub struct ItemCommand { + #[clap(subcommand)] + pub subcommand: ItemCommands, +} + +#[derive(Debug, Subcommand)] +pub enum ItemCommands { + /// Lists the available items. + List, +} diff --git a/game/src/items/mod.rs b/game/src/items/mod.rs index 384784f..ff6a89a 100644 --- a/game/src/items/mod.rs +++ b/game/src/items/mod.rs @@ -1,4 +1,6 @@ +pub mod commands; pub mod components; pub mod interfaces; pub mod plugin; pub mod registry; +pub mod systems; diff --git a/game/src/items/plugin.rs b/game/src/items/plugin.rs index c747b96..a1668dc 100644 --- a/game/src/items/plugin.rs +++ b/game/src/items/plugin.rs @@ -1,4 +1,10 @@ -use crate::prelude::*; +use crate::{ + items::{ + commands::*, + systems::*, + }, + prelude::*, +}; /// Plugin for managing items. pub struct ItemPlugin; @@ -11,5 +17,8 @@ impl Plugin for ItemPlugin { // Initialize registry. app.init_resource::(); + + // Add console commands. + app.add_console_command::(apply_command); } } diff --git a/game/src/items/systems.rs b/game/src/items/systems.rs new file mode 100644 index 0000000..7ce57df --- /dev/null +++ b/game/src/items/systems.rs @@ -0,0 +1,19 @@ +use crate::{ + items::commands::*, + prelude::*, +}; + + +/// Applies the item console commands. +pub fn apply_command(mut command: ConsoleCommand, item_registry: Res) { + if let Some(Ok(ItemCommand { subcommand })) = command.take() { + match subcommand { + ItemCommands::List => { + for (i, entry) in item_registry.iter().enumerate() { + reply!(command, "{}) {}", i + 1, entry.item.id()); + } + }, + } + reply!(command, ""); + } +}