Cleared out the handle_world_events so now just need to fix death and attack animations.
This commit is contained in:
parent
0f20f5b6e3
commit
2b68696328
4 changed files with 55 additions and 80 deletions
|
|
@ -348,7 +348,7 @@ bool Autowalker::found_item() {
|
|||
void Autowalker::send_event(game::Event ev, std::any data) {
|
||||
fsm.event(ev, data);
|
||||
fsm.render();
|
||||
fsm.handle_world_events();
|
||||
fsm.handle_events();
|
||||
}
|
||||
|
||||
bool Autowalker::player_health_good() {
|
||||
|
|
@ -419,7 +419,7 @@ bool Autowalker::face_enemy() {
|
|||
void Autowalker::click_inventory(const std::string& name, guecs::Modifiers mods) {
|
||||
auto& cell = fsm.$status_ui.$gui.cell_for(name);
|
||||
fsm.$status_ui.mouse(cell.mid_x, cell.mid_y, mods);
|
||||
fsm.handle_world_events();
|
||||
fsm.handle_events();
|
||||
}
|
||||
|
||||
void Autowalker::pocket_potion(GameDB::Level &level) {
|
||||
|
|
|
|||
127
src/gui/fsm.cpp
127
src/gui/fsm.cpp
|
|
@ -109,7 +109,6 @@ namespace gui {
|
|||
|
||||
void FSM::IDLE(Event ev, std::any data) {
|
||||
using enum Event;
|
||||
|
||||
sound::stop("walk");
|
||||
|
||||
switch(ev) {
|
||||
|
|
@ -152,29 +151,30 @@ namespace gui {
|
|||
case CLOSE:
|
||||
dbc::log("Nothing to close.");
|
||||
break;
|
||||
case BOSS_START:
|
||||
case STAIRS_DOWN:
|
||||
sound::stop("ambient");
|
||||
next_level(true);
|
||||
state(State::CUT_SCENE_PLAYING);
|
||||
break;
|
||||
case LOOT_ITEM:
|
||||
$dnd_loot.event(Event::LOOT_ITEM);
|
||||
state(State::LOOTING);
|
||||
break;
|
||||
case LOOT_OPEN:
|
||||
$dnd_loot.event(Event::LOOT_OPEN);
|
||||
state(State::LOOTING);
|
||||
break;
|
||||
case LOOT_ITEM: {
|
||||
auto entity = std::any_cast<DinkyECS::Entity>(data);
|
||||
$loot_ui.add_loose_item(entity);
|
||||
$dnd_loot.event(Event::LOOT_ITEM);
|
||||
state(State::LOOTING);
|
||||
} break;
|
||||
case INV_SELECT:
|
||||
$dnd_loot.event(Event::INV_SELECT, data);
|
||||
state(State::LOOTING);
|
||||
break;
|
||||
case HP_STATUS:
|
||||
System::player_status();
|
||||
break;
|
||||
case USE_ITEM: {
|
||||
auto gui_id = std::any_cast<guecs::Entity>(data);
|
||||
auto& slot_name = $status_ui.$gui.name_for(gui_id);
|
||||
auto gui_id = std::any_cast<guecs::Entity>(data);
|
||||
auto& slot_name = $status_ui.$gui.name_for(gui_id);
|
||||
|
||||
$systems.runUseItem(slot_name);
|
||||
$status_ui.update();
|
||||
$systems.runUseItem(slot_name);
|
||||
$status_ui.update();
|
||||
} break;
|
||||
case MOUSE_CLICK:
|
||||
mouse_action();
|
||||
|
|
@ -185,6 +185,38 @@ namespace gui {
|
|||
case AIM_CLICK:
|
||||
$systems.runPickup();
|
||||
break;
|
||||
case COMBAT:
|
||||
$map_ui.log(std::any_cast<components::CombatResult&>(data));
|
||||
break;
|
||||
case COMBAT_START:
|
||||
$main_ui.show_combat();
|
||||
break;
|
||||
case COMBAT_STOP: // BUG: should these combine?
|
||||
case NO_NEIGHBORS:
|
||||
$main_ui.close_combat();
|
||||
break;
|
||||
case LOOT_CONTAINER: {
|
||||
$loot_ui.set_target($loot_ui.$temp_loot);
|
||||
$loot_ui.update();
|
||||
$dnd_loot.event(Event::LOOT_OPEN);
|
||||
state(State::LOOTING);
|
||||
} break;
|
||||
case NEW_RITUAL:
|
||||
$combat_ui.init(COMBAT_UI_X, COMBAT_UI_Y, COMBAT_UI_WIDTH, COMBAT_UI_HEIGHT);
|
||||
break;
|
||||
case DEATH: {
|
||||
// BUG: this is hot dogshit
|
||||
auto world = GameDB::current_world();
|
||||
auto player = world->get_the<Player>();
|
||||
auto entity = std::any_cast<DinkyECS::Entity>(data);
|
||||
|
||||
$status_ui.update();
|
||||
if(entity != player.entity) {
|
||||
$main_ui.dead_entity(entity);
|
||||
} else {
|
||||
dbc::log("NEED TO HANDLE PLAYER DYING.");
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
break; // ignore everything else
|
||||
}
|
||||
|
|
@ -299,7 +331,7 @@ namespace gui {
|
|||
$main_ui.toggle_mind_reading();
|
||||
break;
|
||||
case KEY::X:
|
||||
event(Event::BOSS_START);
|
||||
event(Event::STAIRS_DOWN);
|
||||
break;
|
||||
case KEY::F5:
|
||||
take_screenshot();
|
||||
|
|
@ -387,69 +419,12 @@ namespace gui {
|
|||
}
|
||||
}
|
||||
|
||||
void FSM::handle_world_events() {
|
||||
using eGUI = game::Event;
|
||||
void FSM::handle_events() {
|
||||
auto world = GameDB::current_world();
|
||||
|
||||
while(world->has_event<eGUI>()) {
|
||||
auto [evt, entity, data] = world->recv<eGUI>();
|
||||
auto player = world->get_the<Player>();
|
||||
|
||||
// HERE: this has to go, unify these events and just use them in the state machine directly
|
||||
|
||||
switch(evt) {
|
||||
case eGUI::COMBAT:
|
||||
$map_ui.log(std::any_cast<components::CombatResult&>(data));
|
||||
break;
|
||||
case eGUI::COMBAT_START:
|
||||
$main_ui.show_combat();
|
||||
break;
|
||||
case eGUI::COMBAT_STOP: // BUG: should these combine?
|
||||
case eGUI::NO_NEIGHBORS:
|
||||
$main_ui.close_combat();
|
||||
break;
|
||||
case eGUI::STAIRS_DOWN:
|
||||
event(Event::BOSS_START);
|
||||
break;
|
||||
case eGUI::LOOT_ITEM: {
|
||||
dbc::check(world->has<components::InventoryItem>(entity),
|
||||
"INVALID LOOT_ITEM, that entity has no InventoryItem");
|
||||
$loot_ui.add_loose_item(entity);
|
||||
event(Event::LOOT_ITEM);
|
||||
} break;
|
||||
case eGUI::LOOT_CONTAINER: {
|
||||
$loot_ui.set_target($loot_ui.$temp_loot);
|
||||
$loot_ui.update();
|
||||
event(Event::LOOT_OPEN);
|
||||
} break;
|
||||
case eGUI::HP_STATUS:
|
||||
System::player_status();
|
||||
break;
|
||||
case eGUI::NEW_RITUAL:
|
||||
$combat_ui.init(COMBAT_UI_X, COMBAT_UI_Y, COMBAT_UI_WIDTH, COMBAT_UI_HEIGHT);
|
||||
break;
|
||||
case eGUI::DEATH: {
|
||||
$status_ui.update();
|
||||
if(entity != player.entity) {
|
||||
$main_ui.dead_entity(entity);
|
||||
} else {
|
||||
dbc::log("NEED TO HANDLE PLAYER DYING.");
|
||||
}
|
||||
} break;
|
||||
case eGUI::INV_SELECT:
|
||||
case eGUI::USE_ITEM:
|
||||
case eGUI::AIM_CLICK:
|
||||
case eGUI::LOOT_SELECT:
|
||||
case eGUI::LOOT_CLOSE:
|
||||
case eGUI::ATTACK:
|
||||
// BUG: need to resolve GUI events vs. FSM events better
|
||||
event(Event(evt), data);
|
||||
break;
|
||||
default:
|
||||
dbc::log($F("Unhandled event: evt={}; enemy={}; data={}",
|
||||
evt, entity, data.type().name()));
|
||||
event(game::Event(evt), data);
|
||||
}
|
||||
while(world->has_event<game::Event>()) {
|
||||
auto [evt, entity, data] = world->recv<game::Event>();
|
||||
event(game::Event(evt), data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ namespace gui {
|
|||
void render();
|
||||
bool active();
|
||||
void run_systems();
|
||||
void handle_world_events();
|
||||
void handle_events();
|
||||
void handle_boss_fight_events();
|
||||
void next_level(bool bossfight);
|
||||
void debug_render();
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ void play_game(std::shared_ptr<gui::FSM> main) {
|
|||
main->event(game::Event::TICK);
|
||||
}
|
||||
|
||||
main->handle_world_events();
|
||||
main->handle_events();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue