Cleaned up the move operation more so that I can use it in the other places that I need it.
This commit is contained in:
parent
f559b5a39d
commit
6ff1919587
5 changed files with 52 additions and 8 deletions
|
@ -101,17 +101,18 @@ namespace gui {
|
|||
|
||||
void DNDLoot::INV_PICKUP(Event ev, std::any data) {
|
||||
using enum Event;
|
||||
(void)data;
|
||||
|
||||
switch(ev) {
|
||||
case AIM_CLICK: {
|
||||
fmt::println("IN INV_PICKUP AIM CLICK!");
|
||||
auto& grab = $status_ui.$gui.get<guecs::GrabSource>(*$grab_source);
|
||||
grab.commit();
|
||||
bool dropped = $status_ui.drop_item(grab.world_entity);
|
||||
dbc::check(dropped, "DROP FAILED!");
|
||||
bool worked = throw_on_floor();
|
||||
dbc::check(worked, "Need to fix this, should be able to abort.");
|
||||
END(Event::CLOSE);
|
||||
} break;
|
||||
case INV_SELECT:
|
||||
// BUG: should I do a bool here and not transition?
|
||||
commit_move($status_ui.$gui, $grab_source, data);
|
||||
END(Event::CLOSE);
|
||||
} break;
|
||||
break;
|
||||
default:
|
||||
handle_mouse(ev, $status_ui.$gui);
|
||||
}
|
||||
|
@ -228,6 +229,13 @@ namespace gui {
|
|||
{
|
||||
if(!source_id) return false;
|
||||
auto target_id = std::any_cast<guecs::Entity>(data);
|
||||
fmt::println("!!!!!!!!!source_id = {} target_id = {}",
|
||||
*source_id, target_id);
|
||||
|
||||
dbc::check(target.has<guecs::DropTarget>(target_id),
|
||||
"gui does not have a DropTarget at that slot");
|
||||
dbc::check(source.has<guecs::GrabSource>(*source_id),
|
||||
"gui does not have a GrabSource at that slot");
|
||||
|
||||
auto& drop = target.get<guecs::DropTarget>(target_id);
|
||||
auto& grab = source.get<guecs::GrabSource>(*source_id);
|
||||
|
@ -239,4 +247,28 @@ namespace gui {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void DNDLoot::commit_move(guecs::UI& gui, std::optional<guecs::Entity> source_id, std::any data) {
|
||||
auto& grab = gui.get<guecs::GrabSource>(*source_id);
|
||||
grab.commit();
|
||||
|
||||
auto drop_id = std::any_cast<guecs::Entity>(data);
|
||||
auto& drop = gui.get<guecs::DropTarget>(drop_id);
|
||||
drop.commit(grab.world_entity);
|
||||
|
||||
// BUG: if the drop fails then need to put the grab back?
|
||||
// How to confirm the drop will work before doing it?
|
||||
// Or, maybe save the commit?
|
||||
}
|
||||
|
||||
/*
|
||||
* Dropping on the ground is only possible from the
|
||||
* status_ui for now.
|
||||
*/
|
||||
bool DNDLoot::throw_on_floor() {
|
||||
dbc::check($grab_source != std::nullopt, "attempt to commit_drop but no grab_source set");
|
||||
auto& grab = $status_ui.$gui.get<guecs::GrabSource>(*$grab_source);
|
||||
grab.commit();
|
||||
return $status_ui.drop_item(grab.world_entity);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,9 +45,15 @@ namespace gui {
|
|||
void close();
|
||||
|
||||
std::optional<guecs::Entity> start_grab(guecs::UI& gui, std::any data);
|
||||
|
||||
bool commit_drop(guecs::UI& source, guecs::UI& target,
|
||||
std::optional<guecs::Entity> source_id, std::any data);
|
||||
|
||||
void commit_move(guecs::UI& gui,
|
||||
std::optional<guecs::Entity> source_id, std::any data);
|
||||
|
||||
bool throw_on_floor();
|
||||
|
||||
sf::Vector2f mouse_position();
|
||||
};
|
||||
}
|
||||
|
|
|
@ -117,7 +117,6 @@ 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;
|
||||
}
|
||||
|
@ -128,6 +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& inventory = $level.world->get_the<inventory::Model>();
|
||||
inventory.remove(slot_name);
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
#include "dinkyecs.hpp"
|
||||
#include <unordered_map>
|
||||
|
||||
// BUG: this should have a bool for "permanent" or "constant" so that
|
||||
// everything working with it knows to do the make_constant/not_constant
|
||||
// dance when using it. Idea is the System:: ops for this would get it
|
||||
// and then look at the bool and add the constant ops as needed.
|
||||
namespace inventory {
|
||||
using Slot = std::string;
|
||||
|
||||
|
|
|
@ -509,12 +509,14 @@ bool System::drop_item(GameLevel& level, Entity item) {
|
|||
for(matrix::box it{map.walls(), player_pos.location.x, player_pos.location.y, 1}; it.next();)
|
||||
{
|
||||
Position pos{it.x, it.y};
|
||||
|
||||
if(map.can_move(pos.location) && !collision.occupied(pos.location)) {
|
||||
world.set<Position>(item, pos);
|
||||
collision.insert(pos.location, item);
|
||||
// BUG: really there should be another system that handles loot->inv moves
|
||||
if(player_inv.has(item)) player_inv.remove(item);
|
||||
level.world->send<Events::GUI>(Events::GUI::ENEMY_SPAWN, item, {});
|
||||
level.world->not_constant(item);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue