Can now round-trip a torch from loot to inventory and back.
This commit is contained in:
parent
4b0d76bbcc
commit
2a6b892e7f
5 changed files with 80 additions and 22 deletions
|
@ -78,10 +78,25 @@ namespace gui {
|
|||
auto& sprite = $level.world->get<components::Sprite>(item);
|
||||
guecs::GrabSource grabber{sprite.name};
|
||||
$gui.set_init<guecs::Sprite>(id, grabber);
|
||||
} else {
|
||||
$gui.set<guecs::DropTarget>(id, {
|
||||
[&, id]() -> bool { return place_slot(id); }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool LootUI::place_slot(DinkyECS::Entity id) {
|
||||
if(contents.size() < INV_SLOTS && !contents.contains(id)) {
|
||||
contents.try_emplace(id, $selected_entity);
|
||||
dbc::log(fmt::format("adding entity {}", id));
|
||||
update();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool LootUI::has_grab_source(DinkyECS::Entity gui_id) {
|
||||
return $gui.has<guecs::Sprite>(gui_id);
|
||||
}
|
||||
|
@ -109,4 +124,19 @@ namespace gui {
|
|||
guecs::DropTarget& LootUI::get_drop_target(DinkyECS::Entity gui_id) {
|
||||
return $gui.get<guecs::DropTarget>(gui_id);
|
||||
}
|
||||
|
||||
void LootUI::begin_drop(DinkyECS::Entity world_entity) {
|
||||
dbc::log("begin the loot drop");
|
||||
$selected_entity = world_entity;
|
||||
}
|
||||
|
||||
bool LootUI::commit_drop(DinkyECS::Entity gui_id) {
|
||||
if($gui.has<guecs::DropTarget>(gui_id)) {
|
||||
auto& drop = get_drop_target(gui_id);
|
||||
return drop.commit();
|
||||
} else {
|
||||
// NOTE: I think I need to cancel the drop or something?
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue