Inventory

This commit is contained in:
2025-06-08 14:47:15 -05:00
parent 0b6b33721b
commit 823aa454bd
6 changed files with 62 additions and 3 deletions

View File

@ -7,4 +7,5 @@
target_sources(${DUSK_TARGET_NAME}
PRIVATE
itemtype.c
inventory.c
)

16
src/rpg/item/inventory.c Normal file
View File

@ -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));
}

23
src/rpg/item/inventory.h Normal file
View File

@ -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);

View File

@ -7,3 +7,8 @@
#pragma once
#include "itemtype.h"
typedef struct {
itemtype_t type;
uint8_t count;
} itemstack_t;

View File

@ -5,6 +5,7 @@
* https://opensource.org/licenses/MIT
*/
#include "assert/assert.h"
#include "itemtype.h"
iteminfo_t ITEM_INFO[ITEM_TYPE_COUNT] = {
@ -20,3 +21,8 @@ iteminfo_t ITEM_INFO[ITEM_TYPE_COUNT] = {
// Cooked Items
[ITEM_TYPE_BAKED_SWEET_POTATO] = { .stackable = true },
};
static inline bool_t itemTypeIsStackable(const itemtype_t type) {
assert(type < ITEM_TYPE_COUNT, "Invalid item type");
return ITEM_INFO[type].stackable;
}

View File

@ -28,3 +28,11 @@ typedef struct {
bool_t stackable;
} iteminfo_t;
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);