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) {
|
void Autowalker::send_event(game::Event ev, std::any data) {
|
||||||
fsm.event(ev, data);
|
fsm.event(ev, data);
|
||||||
fsm.render();
|
fsm.render();
|
||||||
fsm.handle_world_events();
|
fsm.handle_events();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Autowalker::player_health_good() {
|
bool Autowalker::player_health_good() {
|
||||||
|
|
@ -419,7 +419,7 @@ bool Autowalker::face_enemy() {
|
||||||
void Autowalker::click_inventory(const std::string& name, guecs::Modifiers mods) {
|
void Autowalker::click_inventory(const std::string& name, guecs::Modifiers mods) {
|
||||||
auto& cell = fsm.$status_ui.$gui.cell_for(name);
|
auto& cell = fsm.$status_ui.$gui.cell_for(name);
|
||||||
fsm.$status_ui.mouse(cell.mid_x, cell.mid_y, mods);
|
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) {
|
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) {
|
void FSM::IDLE(Event ev, std::any data) {
|
||||||
using enum Event;
|
using enum Event;
|
||||||
|
|
||||||
sound::stop("walk");
|
sound::stop("walk");
|
||||||
|
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
|
|
@ -152,29 +151,30 @@ namespace gui {
|
||||||
case CLOSE:
|
case CLOSE:
|
||||||
dbc::log("Nothing to close.");
|
dbc::log("Nothing to close.");
|
||||||
break;
|
break;
|
||||||
case BOSS_START:
|
case STAIRS_DOWN:
|
||||||
sound::stop("ambient");
|
sound::stop("ambient");
|
||||||
next_level(true);
|
next_level(true);
|
||||||
state(State::CUT_SCENE_PLAYING);
|
state(State::CUT_SCENE_PLAYING);
|
||||||
break;
|
break;
|
||||||
case LOOT_ITEM:
|
case LOOT_ITEM: {
|
||||||
$dnd_loot.event(Event::LOOT_ITEM);
|
auto entity = std::any_cast<DinkyECS::Entity>(data);
|
||||||
state(State::LOOTING);
|
$loot_ui.add_loose_item(entity);
|
||||||
break;
|
$dnd_loot.event(Event::LOOT_ITEM);
|
||||||
case LOOT_OPEN:
|
state(State::LOOTING);
|
||||||
$dnd_loot.event(Event::LOOT_OPEN);
|
} break;
|
||||||
state(State::LOOTING);
|
|
||||||
break;
|
|
||||||
case INV_SELECT:
|
case INV_SELECT:
|
||||||
$dnd_loot.event(Event::INV_SELECT, data);
|
$dnd_loot.event(Event::INV_SELECT, data);
|
||||||
state(State::LOOTING);
|
state(State::LOOTING);
|
||||||
break;
|
break;
|
||||||
|
case HP_STATUS:
|
||||||
|
System::player_status();
|
||||||
|
break;
|
||||||
case USE_ITEM: {
|
case USE_ITEM: {
|
||||||
auto gui_id = std::any_cast<guecs::Entity>(data);
|
auto gui_id = std::any_cast<guecs::Entity>(data);
|
||||||
auto& slot_name = $status_ui.$gui.name_for(gui_id);
|
auto& slot_name = $status_ui.$gui.name_for(gui_id);
|
||||||
|
|
||||||
$systems.runUseItem(slot_name);
|
$systems.runUseItem(slot_name);
|
||||||
$status_ui.update();
|
$status_ui.update();
|
||||||
} break;
|
} break;
|
||||||
case MOUSE_CLICK:
|
case MOUSE_CLICK:
|
||||||
mouse_action();
|
mouse_action();
|
||||||
|
|
@ -185,6 +185,38 @@ namespace gui {
|
||||||
case AIM_CLICK:
|
case AIM_CLICK:
|
||||||
$systems.runPickup();
|
$systems.runPickup();
|
||||||
break;
|
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:
|
default:
|
||||||
break; // ignore everything else
|
break; // ignore everything else
|
||||||
}
|
}
|
||||||
|
|
@ -299,7 +331,7 @@ namespace gui {
|
||||||
$main_ui.toggle_mind_reading();
|
$main_ui.toggle_mind_reading();
|
||||||
break;
|
break;
|
||||||
case KEY::X:
|
case KEY::X:
|
||||||
event(Event::BOSS_START);
|
event(Event::STAIRS_DOWN);
|
||||||
break;
|
break;
|
||||||
case KEY::F5:
|
case KEY::F5:
|
||||||
take_screenshot();
|
take_screenshot();
|
||||||
|
|
@ -387,69 +419,12 @@ namespace gui {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FSM::handle_world_events() {
|
void FSM::handle_events() {
|
||||||
using eGUI = game::Event;
|
|
||||||
auto world = GameDB::current_world();
|
auto world = GameDB::current_world();
|
||||||
|
|
||||||
while(world->has_event<eGUI>()) {
|
while(world->has_event<game::Event>()) {
|
||||||
auto [evt, entity, data] = world->recv<eGUI>();
|
auto [evt, entity, data] = world->recv<game::Event>();
|
||||||
auto player = world->get_the<Player>();
|
event(game::Event(evt), data);
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ namespace gui {
|
||||||
void render();
|
void render();
|
||||||
bool active();
|
bool active();
|
||||||
void run_systems();
|
void run_systems();
|
||||||
void handle_world_events();
|
void handle_events();
|
||||||
void handle_boss_fight_events();
|
void handle_boss_fight_events();
|
||||||
void next_level(bool bossfight);
|
void next_level(bool bossfight);
|
||||||
void debug_render();
|
void debug_render();
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ void play_game(std::shared_ptr<gui::FSM> main) {
|
||||||
main->event(game::Event::TICK);
|
main->event(game::Event::TICK);
|
||||||
}
|
}
|
||||||
|
|
||||||
main->handle_world_events();
|
main->handle_events();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue