First round of cleanup. dnd_loot.

This commit is contained in:
Zed A. Shaw 2025-06-25 14:28:35 -04:00
parent 689bb150c6
commit f668ff6b7a
9 changed files with 169 additions and 38 deletions

View file

@ -29,8 +29,9 @@ namespace gui {
}
void DNDLoot::START(Event ev) {
dbc::check(ev == Event::STARTED, "START not given a STARTED event.");
END(Event::CLOSE);
using enum Event;
dbc::check(ev == STARTED, "START not given a STARTED event.");
END(CLOSE);
}
void DNDLoot::LOOTING(Event ev, std::any data) {
@ -38,7 +39,7 @@ namespace gui {
switch(ev) {
case LOOT_OPEN:
END(Event::CLOSE);
END(CLOSE);
break;
case LOOT_SELECT:
$grab_source = start_grab($loot_ui.$gui, data);
@ -49,7 +50,7 @@ namespace gui {
if($grab_source) state(DNDState::INV_GRAB);
break;
default:
state(DNDState::LOOTING);
break; // ignore
}
}
@ -58,7 +59,7 @@ namespace gui {
switch(ev) {
case LOOT_OPEN:
END(Event::CLOSE);
END(CLOSE);
break;
case LOOT_SELECT:
commit_move($loot_ui.$gui, $grab_source, data);
@ -81,7 +82,7 @@ namespace gui {
switch(ev) {
case LOOT_OPEN:
END(Event::CLOSE);
END(CLOSE);
break;
case LOOT_SELECT:
if(commit_drop($status_ui.$gui,
@ -107,12 +108,12 @@ namespace gui {
case AIM_CLICK: {
bool worked = throw_on_floor();
dbc::check(worked, "Need to fix this, should be able to abort.");
END(Event::CLOSE);
END(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);
END(CLOSE);
break;
default:
handle_mouse(ev, $status_ui.$gui);
@ -126,13 +127,17 @@ namespace gui {
case INV_SELECT:
if(commit_drop($loot_ui.$gui, $status_ui.$gui, $grab_source, data))
{
END(Event::CLOSE);
END(CLOSE);
}
break;
case LOOT_ITEM:
case AIM_CLICK:
// BUG: because I put things into fake loot containers it's actually
// hard to put things back. It's probably a System::remove from the
// loot container combined with a System::drop_item
dbc::log("Put it back?");
break;
default:
handle_mouse(ev, $loot_ui.$gui);
handle_mouse(ev, $loot_ui.$gui);
}
}
@ -140,30 +145,14 @@ namespace gui {
using enum Event;
switch(ev) {
case LOOT_ITEM: {
// NOTE: if > 1 items, go to LOOT_OPEN instead
auto gui_id = $loot_ui.$gui.entity("item_0");
$grab_source = start_grab($loot_ui.$gui, gui_id);
if($grab_source) {
auto& source = $loot_ui.$gui.get<guecs::GrabSource>(*$grab_source);
$grab_sprite = source.sprite;
// call this once to properly position the sprite
handle_mouse(Event::MOUSE_MOVE, $loot_ui.$gui);
state(DNDState::ITEM_PICKUP);
}
} break;
case INV_SELECT: {
$grab_source = start_grab($status_ui.$gui, data);
if($grab_source) {
auto& source = $status_ui.$gui.get<guecs::GrabSource>(*$grab_source);
$grab_sprite = source.sprite;
state(DNDState::INV_PICKUP);
} else {
dbc::log("inv slot empty");
}
} break;
case LOOT_ITEM:
hold_world_item();
state(DNDState::ITEM_PICKUP);
break;
case INV_SELECT:
hold_inv_item(data);
state(DNDState::INV_PICKUP);
break;
case LOOT_OPEN:
open();
state(DNDState::LOOTING);
@ -268,14 +257,42 @@ namespace gui {
// Or, maybe save the commit?
}
void DNDLoot::hold_world_item() {
// NOTE: if > 1 items, go to LOOT_OPEN instead
auto gui_id = $loot_ui.$gui.entity("item_0");
$grab_source = start_grab($loot_ui.$gui, gui_id);
if($grab_source) {
auto& source = $loot_ui.$gui.get<guecs::GrabSource>(*$grab_source);
$grab_sprite = source.sprite;
// call this once to properly position the sprite
handle_mouse(Event::MOUSE_MOVE, $loot_ui.$gui);
}
}
void DNDLoot::hold_inv_item(std::any& data) {
$grab_source = start_grab($status_ui.$gui, data);
if($grab_source) {
auto& source = $status_ui.$gui.get<guecs::GrabSource>(*$grab_source);
$grab_sprite = source.sprite;
} else {
dbc::log("inv slot empty");
}
}
/*
* 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");
dbc::check($status_ui.$gui.has<guecs::GrabSource>(*$grab_source),
"StatusUI doesn't actually have that GrabSource in the gui.");
auto& grab = $status_ui.$gui.get<guecs::GrabSource>(*$grab_source);
grab.commit();
bool result = $status_ui.drop_item(grab.world_entity);
clear_grab();
return result;