Clean things up before solving the move problem.

This commit is contained in:
Zed A. Shaw 2025-07-02 10:51:23 -04:00
parent 6576164fad
commit 8c8d6dc9e7
4 changed files with 16 additions and 18 deletions

View file

@ -62,8 +62,9 @@ namespace gui {
END(CLOSE);
break;
case LOOT_SELECT:
commit_move($loot_ui.$gui, $grab_source, data);
state(DNDState::LOOTING);
if(commit_move($loot_ui.$gui, $grab_source, data)) {
state(DNDState::LOOTING);
}
break;
case INV_SELECT:
if(commit_drop($loot_ui.$gui,
@ -92,9 +93,9 @@ namespace gui {
}
break;
case INV_SELECT:
// BUG: should I do a bool here and not transition?
commit_move($status_ui.$gui, $grab_source, data);
state(DNDState::LOOTING);
if(commit_move($status_ui.$gui, $grab_source, data)) {
state(DNDState::LOOTING);
}
break;
default:
handle_mouse(ev, $status_ui.$gui);
@ -111,8 +112,9 @@ namespace gui {
END(CLOSE);
} break;
case INV_SELECT:
commit_move($status_ui.$gui, $grab_source, data);
END(CLOSE);
if(commit_move($status_ui.$gui, $grab_source, data)) {
END(CLOSE);
}
break;
default:
handle_mouse(ev, $status_ui.$gui);
@ -228,8 +230,8 @@ namespace gui {
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);
auto& drop = target.get<guecs::DropTarget>(target_id);
if(drop.commit(grab.world_entity)) {
grab.commit();
@ -240,8 +242,9 @@ namespace gui {
}
}
void DNDLoot::commit_move(guecs::UI& gui, std::optional<guecs::Entity> source_id, std::any data) {
bool DNDLoot::commit_move(guecs::UI& gui, std::optional<guecs::Entity> source_id, std::any data) {
dbc::check(source_id != std::nullopt, "source_id must exist");
auto& grab = gui.get<guecs::GrabSource>(*source_id);
grab.commit();
@ -250,13 +253,11 @@ namespace gui {
if(drop.commit(grab.world_entity)) {
clear_grab();
return true;
} else {
dbc::log("commit drop didn't happen");
// swap with the target instead
return false;
}
// 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?
}
bool DNDLoot::hold_world_item() {