The next little game in the series where I make a fancy rogue game.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
roguish/inventory.cpp

32 lines
823 B

#include "inventory.hpp"
namespace components {
void Inventory::add(InventoryItem new_item) {
for(auto &slot : items) {
if(new_item.data["id"] == slot.data["id"]) {
slot.count += new_item.count;
return;
}
}
items.push_back(new_item);
}
InventoryItem& Inventory::get(size_t at) {
dbc::check(at < items.size(), fmt::format("inventory index {} too big", at));
return items[at];
}
bool Inventory::decrease(size_t at, int count) {
dbc::check(at < items.size(), fmt::format("inventory index {} too big", at));
auto &slot = items[at];
slot.count -= count;
return slot.count > 0;
}
void Inventory::erase_item(size_t at) {
dbc::check(at < items.size(), fmt::format("inventory index {} too big", at));
items.erase(items.begin() + at);
}
}