diff --git a/src/rpg/item/CMakeLists.txt b/src/rpg/item/CMakeLists.txt index 613b1ca..e1d291d 100644 --- a/src/rpg/item/CMakeLists.txt +++ b/src/rpg/item/CMakeLists.txt @@ -7,4 +7,5 @@ target_sources(${DUSK_TARGET_NAME} PRIVATE itemtype.c + inventory.c ) \ No newline at end of file diff --git a/src/rpg/item/inventory.c b/src/rpg/item/inventory.c new file mode 100644 index 0000000..1c6de8d --- /dev/null +++ b/src/rpg/item/inventory.c @@ -0,0 +1,16 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "assert/assert.h" +#include "inventory.h" +#include "util/memory.h" + +void inventoryInit(inventory_t *inventory) { + assertNotNull(inventory, "Inventory pointer cannot be NULL"); + + memoryZero(inventory, sizeof(inventory_t)); +} \ No newline at end of file diff --git a/src/rpg/item/inventory.h b/src/rpg/item/inventory.h new file mode 100644 index 0000000..0b47c0c --- /dev/null +++ b/src/rpg/item/inventory.h @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "itemstack.h" + +#define INVENTORY_ITEM_COUNT 32 + +typedef struct { + itemstack_t items[INVENTORY_ITEM_COUNT]; + uint8_t itemCount; +} inventory_t; + +/** + * Initializes the inventory. + * + * @param inventory Pointer to the inventory to initialize. + */ +void inventoryInit(inventory_t *inventory); \ No newline at end of file diff --git a/src/rpg/item/item.h b/src/rpg/item/itemstack.h similarity index 63% rename from src/rpg/item/item.h rename to src/rpg/item/itemstack.h index 33ebcfc..b691d5d 100644 --- a/src/rpg/item/item.h +++ b/src/rpg/item/itemstack.h @@ -6,4 +6,9 @@ */ #pragma once -#include "itemtype.h" \ No newline at end of file +#include "itemtype.h" + +typedef struct { + itemtype_t type; + uint8_t count; +} itemstack_t; \ No newline at end of file diff --git a/src/rpg/item/itemtype.c b/src/rpg/item/itemtype.c index 4b2f07f..01df5f9 100644 --- a/src/rpg/item/itemtype.c +++ b/src/rpg/item/itemtype.c @@ -5,6 +5,7 @@ * https://opensource.org/licenses/MIT */ +#include "assert/assert.h" #include "itemtype.h" iteminfo_t ITEM_INFO[ITEM_TYPE_COUNT] = { @@ -19,4 +20,9 @@ iteminfo_t ITEM_INFO[ITEM_TYPE_COUNT] = { // Cooked Items [ITEM_TYPE_BAKED_SWEET_POTATO] = { .stackable = true }, -}; \ No newline at end of file +}; + +static inline bool_t itemTypeIsStackable(const itemtype_t type) { + assert(type < ITEM_TYPE_COUNT, "Invalid item type"); + return ITEM_INFO[type].stackable; +} \ No newline at end of file diff --git a/src/rpg/item/itemtype.h b/src/rpg/item/itemtype.h index c8e605f..22cbb91 100644 --- a/src/rpg/item/itemtype.h +++ b/src/rpg/item/itemtype.h @@ -27,4 +27,12 @@ typedef enum { typedef struct { bool_t stackable; } iteminfo_t; -extern iteminfo_t ITEM_INFO[ITEM_TYPE_COUNT]; \ No newline at end of file +extern iteminfo_t ITEM_INFO[ITEM_TYPE_COUNT]; + +/** + * Returns true if the item type is stackable. + * + * @param type The item type to check. + * @return true if the item type is stackable, false otherwise. + */ +static inline bool_t itemTypeIsStackable(const itemtype_t type); \ No newline at end of file