Basic inventory system working and can pick up items but needs to be reflected in the UI next.
This commit is contained in:
parent
d7353a02df
commit
135d9a128b
14 changed files with 212 additions and 48 deletions
32
inventory.cpp
Normal file
32
inventory.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include "inventory.hpp"
|
||||
|
||||
|
||||
namespace components {
|
||||
void Inventory::add(InventoryItem item) {
|
||||
std::string id = item.data["id"];
|
||||
|
||||
if(items.contains(id)) {
|
||||
auto &slot = items[id];
|
||||
slot.count += item.count;
|
||||
} else {
|
||||
items[id] = item;
|
||||
}
|
||||
}
|
||||
|
||||
InventoryItem& Inventory::get(std::string id) {
|
||||
dbc::check(items.contains(id), fmt::format("item id {} is not in inventory", id));
|
||||
return items[id];
|
||||
}
|
||||
|
||||
bool Inventory::decrease(std::string id, int count) {
|
||||
dbc::check(items.contains(id), fmt::format("item id {} is not in inventory", id));
|
||||
auto &slot = items[id];
|
||||
slot.count -= count;
|
||||
return slot.count > 0;
|
||||
}
|
||||
|
||||
void Inventory::remove_all(std::string id) {
|
||||
dbc::check(items.contains(id), fmt::format("item id {} is not in inventory", id));
|
||||
items.erase(id);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue