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