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

@ -29,7 +29,6 @@ namespace gui {
for(auto& [name, cell] : $gui.cells()) {
auto gui_id = $gui.entity(name);
$slot_to_name.insert_or_assign(gui_id, name);
if(name == "character_view") {
$gui.set<Rectangle>(gui_id, {});
@ -102,7 +101,7 @@ namespace gui {
}
bool StatusUI::place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity) {
auto& slot_name = $slot_to_name.at(gui_id);
auto& slot_name = $gui.name_for(gui_id);
auto player = $level.world->get_the<components::Player>();
auto& inventory = $level.world->get<inventory::Model>(player.entity);
@ -128,8 +127,7 @@ namespace gui {
// ground or moving from one container or another, so when loot_ui
// moves to use an ECS id to a container I can have the System
// do it.
dbc::log(fmt::format("removing slot: {}", slot_id));
auto& slot_name = $slot_to_name.at(slot_id);
auto& slot_name = $gui.name_for(slot_id);
auto player = $level.world->get_the<components::Player>();
auto& inventory = $level.world->get<inventory::Model>(player.entity);
@ -143,25 +141,17 @@ namespace gui {
void StatusUI::swap(guecs::Entity gui_a, guecs::Entity gui_b) {
if(gui_a != gui_b) {
auto& a_name = $gui.name_for(gui_a);
auto& b_name = $gui.name_for(gui_b);
auto player = $level.world->get_the<components::Player>();
auto& inventory = $level.world->get<inventory::Model>(player.entity);
auto& a_name = $slot_to_name.at(gui_a);
auto& b_name = $slot_to_name.at(gui_b);
auto a_ent = inventory.get(a_name);
auto b_ent = inventory.get(b_name);
inventory.swap(a_ent, b_ent);
System::inventory_swap($level, player.entity, a_name, b_name);
}
update();
}
bool StatusUI::occupied(guecs::Entity slot) {
dbc::check($slot_to_name.contains(slot), "jank ass slot to name thing isn't loaded right you idiot.");
auto player = $level.world->get_the<components::Player>();
auto& inventory = $level.world->get<inventory::Model>(player.entity);
auto& slot_name = $slot_to_name.at(slot);
return inventory.has(slot_name);
return System::inventory_occupied($level, player.entity, $gui.name_for(slot));
}
}