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.
33 lines
825 B
33 lines
825 B
6 days ago
|
#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);
|
||
|
}
|
||
|
}
|