Tracked down the bug that was caused by picking up an item but not removing its Position in the world, so when you go to another level it gets brought back to life causing a dupe.

This commit is contained in:
Zed A. Shaw 2025-06-22 12:50:09 -04:00
parent 2c6565c40a
commit e0588847fa
7 changed files with 62 additions and 5 deletions

View file

@ -454,7 +454,7 @@ namespace gui {
break;
case eGUI::AIM_CLICK:
if(auto aimed_at = $main_ui.camera_aim()) {
dbc::log("clicked on a thing");
fmt::println("clicked on a thing: {}", aimed_at);
System::pickup($level, aimed_at);
} else {
dbc::log("there's no thing there!");
@ -463,6 +463,7 @@ namespace gui {
case eGUI::LOOT_ITEM: {
dbc::check(world.has<components::InventoryItem>(entity),
"INVALID LOOT_ITEM, that entity has no InventoryItem");
fmt::println("in FSM LOOT_ITEM the entity is {}", entity);
System::place_in_container(*$level.world, $temp_loot, "item_0", entity);
$loot_ui.set_target($temp_loot);
$loot_ui.update();
@ -509,6 +510,10 @@ namespace gui {
$levels.create_level($level.world);
$level = $levels.next();
// this has to go away, but clear out the inventory
$temp_loot = $level.world->entity();
$level.world->set<inventory::Model>($temp_loot, {});
$status_ui.update_level($level);
$map_ui.update_level($level);
$mini_map.update_level($level);

View file

@ -16,12 +16,15 @@ namespace guecs {
}
DinkyECS::Entity GrabSource::grab() {
fmt::println("> Grab entity {}", world_entity);
return world_entity;
}
void GrabSource::setSprite(guecs::UI& gui, guecs::Entity gui_id) {
dbc::check(gui.has<guecs::Sprite>(gui_id), "GrabSource given sprite gui_id that doesn't exist");
fmt::println("> Grabsource Set sprite entity {}", world_entity);
auto& sp = gui.get<guecs::Sprite>(gui_id);
sprite = sp.sprite;
}

View file

@ -94,13 +94,16 @@ namespace gui {
}
}
void LootUI::remove_slot(DinkyECS::Entity slot_id) {
void LootUI::remove_slot(guecs::Entity slot_id) {
auto& name = $slot_to_name.at(slot_id);
fmt::println("LootUI remove slot inv::Model id={} slot={}", $target, name);
System::remove_from_container(*$level.world, $target, name);
update();
}
bool LootUI::place_slot(guecs::Entity id, DinkyECS::Entity world_entity) {
fmt::println("LootUI target={} placing world entity {} in slot id {}",
$target, id, world_entity);
auto& name = $slot_to_name.at(id);
bool worked = System::place_in_container(*$level.world, $target, name, world_entity);
if(worked) update();

View file

@ -102,6 +102,16 @@ namespace gui {
bool StatusUI::place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity) {
auto& slot_name = $slot_to_name.at(gui_id);
auto& inventory = $level.world->get_the<inventory::Model>();
for(auto [ent, slot] : inventory.by_entity) {
fmt::println("BY_ENTITY: ent={}, slot={}", ent, slot);
}
for(auto [slot, ent] : inventory.by_slot) {
fmt::println("BY_SLOT: ent={}, slot={}", ent, slot);
}
$level.world->make_constant(world_entity);
inventory.add(slot_name, world_entity);
update();
return true;
@ -109,6 +119,7 @@ namespace gui {
bool StatusUI::drop_item(DinkyECS::Entity item_id) {
bool dropped = System::drop_item($level, item_id);
$level.world->not_constant(item_id);
if(dropped) update();
return dropped;
}