From 392b93d47baeb6bee26c0eda86ac67748eb8af1b Mon Sep 17 00:00:00 2001 From: demenik Date: Wed, 10 Dec 2025 18:13:22 +0100 Subject: [PATCH] docs: add documentation for inventory and shop systems (#65) --- src/features/inventory/components.rs | 7 +++++++ src/features/inventory/mod.rs | 3 +++ src/features/inventory/ui/inventory.rs | 1 + src/features/inventory/ui/item.rs | 1 + src/features/shop/components.rs | 5 +++++ src/features/shop/mod.rs | 2 ++ src/features/shop/ui/offer.rs | 2 ++ src/features/shop/ui/shop.rs | 1 + 8 files changed, 22 insertions(+) diff --git a/src/features/inventory/components.rs b/src/features/inventory/components.rs index ab3f75a..2efa7a6 100644 --- a/src/features/inventory/components.rs +++ b/src/features/inventory/components.rs @@ -1,6 +1,7 @@ use crate::features::config::components::BerrySeedConfig; use crate::prelude::*; +/// Types of items available in the game. #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Hash)] pub enum ItemType { Berry, @@ -102,18 +103,21 @@ impl ItemType { } } +/// A stack of items of a specific type. #[derive(Component, Serialize, Deserialize, Clone, Debug)] pub struct ItemStack { pub item_type: ItemType, pub amount: u32, } +/// Resource containing all items owned by the player. #[derive(Resource, Default, Serialize, Deserialize)] pub struct Inventory { pub items: Vec, } impl Inventory { + /// Checks if the inventory contains a specific item type. pub fn has_item_type(&self, items_query: &Query<&ItemStack>, item_type: ItemType) -> bool { self.items.iter().any(|&entity| { if let Ok(stack) = items_query.get(entity) { @@ -124,6 +128,7 @@ impl Inventory { }) } + /// Adds or removes items from the inventory. pub fn update_item_stack( &mut self, commands: &mut Commands, @@ -193,11 +198,13 @@ impl Inventory { } } +/// Markers for inventory UI root nodes. #[derive(Component)] pub enum RootMarker { Inventory, } +/// Markers for inventory-related buttons. #[derive(Component)] pub enum ButtonType { InventoryOpen, diff --git a/src/features/inventory/mod.rs b/src/features/inventory/mod.rs index 49df63b..878fc95 100644 --- a/src/features/inventory/mod.rs +++ b/src/features/inventory/mod.rs @@ -5,6 +5,7 @@ use components::*; pub mod components; pub mod ui; +/// Plugin for the inventory system, including storage and UI. pub struct InventoryPlugin; impl Plugin for InventoryPlugin { @@ -18,6 +19,7 @@ impl Plugin for InventoryPlugin { } } +/// Handles inventory button interactions. fn buttons( mut commands: Commands, mut interaction_query: Query<(&Interaction, &ButtonType), (Changed, With