Finally have inventory not crashing for most edge cases. This solves many bugs but mostly closes #58.

This commit is contained in:
Zed A. Shaw 2025-07-07 13:25:17 -04:00
parent 601f3331ed
commit f64b202ee7
9 changed files with 90 additions and 43 deletions

View file

@ -562,3 +562,18 @@ Position& System::player_position(GameLevel& level) {
auto& player = level.world->get_the<components::Player>();
return level.world->get<components::Position>(player.entity);
}
void System::inventory_swap(GameLevel &level, Entity container_id, const std::string& a_name, const std::string &b_name) {
dbc::check(a_name != b_name, "Attempt to inventory swap the same slot, you should check this and avoid calling me.");
auto& inventory = level.world->get<inventory::Model>(container_id);
auto a_ent = inventory.get(a_name);
auto b_ent = inventory.get(b_name);
inventory.swap(a_ent, b_ent);
}
bool System::inventory_occupied(GameLevel& level, Entity container_id, const std::string& name) {
auto& inventory = level.world->get<inventory::Model>(container_id);
return inventory.has(name);
}