Trying out Ragel's state machine generation as an alternative to the DinkyFSM style.

This commit is contained in:
Zed A. Shaw 2025-06-14 00:43:40 -04:00
parent 9468990f76
commit 7fc32b0248
10 changed files with 428 additions and 19 deletions

View file

@ -10,6 +10,7 @@ namespace gui {
$window(window),
$router(router)
{
event(Event::STARTED);
}
bool DNDLoot::event(Event ev, std::any data) {
@ -28,7 +29,7 @@ namespace gui {
void DNDLoot::START(Event ev) {
dbc::check(ev == Event::STARTED, "START not given a STARTED event.");
state(DNDState::LOOTING);
state(DNDState::END);
}
void DNDLoot::LOOTING(Event ev, std::any data) {
@ -142,9 +143,22 @@ namespace gui {
}
void DNDLoot::END(Event ev) {
dbc::check(ev == Event::STARTED, "END not given a STARTED event.");
$grab_source = std::nullopt;
state(DNDState::LOOTING);
using enum Event;
switch(ev) {
case LOOT_ITEM:
$loot_ui.active = true;
$grab_source = std::nullopt;
state(DNDState::LOOTING);
break;
case LOOT_OPEN:
$loot_ui.active = true;
$grab_source = std::nullopt;
state(DNDState::LOOTING);
break;
default:
dbc::sentinel(fmt::format("invalid event: {}", int(ev)));
}
}
sf::Vector2f DNDLoot::mouse_position() {