Brought over a bunch of code from the roguelike and now will use it to generate a random map.

This commit is contained in:
Zed A. Shaw 2025-01-30 11:38:57 -05:00
parent 8d3d3b4ec3
commit 2daa1c9bd5
59 changed files with 4303 additions and 411 deletions

42
inventory.cpp Normal file
View file

@ -0,0 +1,42 @@
#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);
}
int Inventory::item_index(std::string id) {
for(size_t i = 0; i < items.size(); i++) {
if(items[i].data["id"] == id) {
return i;
}
}
return -1;
}
}