Finally unified all of my events into one place.
This commit is contained in:
parent
6c34fea64a
commit
c618a4828f
30 changed files with 215 additions and 216 deletions
|
|
@ -18,7 +18,7 @@ namespace boss {
|
|||
$ui.init();
|
||||
}
|
||||
|
||||
bool Fight::event(gui::Event ev, std::any data) {
|
||||
bool Fight::event(game::Event ev, std::any data) {
|
||||
// if the mouse event is handled the done, this may be wrong later
|
||||
if(handle_mouse(ev)) return in_state(State::END);
|
||||
|
||||
|
|
@ -35,8 +35,8 @@ namespace boss {
|
|||
return in_state(State::END);
|
||||
}
|
||||
|
||||
void Fight::START(gui::Event ev, std::any) {
|
||||
using enum gui::Event;
|
||||
void Fight::START(game::Event ev, std::any) {
|
||||
using enum game::Event;
|
||||
|
||||
switch(ev) {
|
||||
// this is only if using the debug X key to skip it
|
||||
|
|
@ -53,15 +53,15 @@ namespace boss {
|
|||
}
|
||||
}
|
||||
|
||||
void Fight::PLAYER_REQUESTS(gui::Event ev, std::any data) {
|
||||
using enum gui::Event;
|
||||
void Fight::PLAYER_REQUESTS(game::Event ev, std::any data) {
|
||||
using enum game::Event;
|
||||
|
||||
switch(ev) {
|
||||
// this is only if using the debug X key to skip it
|
||||
case BOSS_START:
|
||||
state(State::END);
|
||||
break;
|
||||
case START_COMBAT:
|
||||
case COMBAT_START:
|
||||
System::plan_battle($battle, $world, $boss_id);
|
||||
$ui.status(L"PLANNING BATTLE");
|
||||
state(State::PLAN_BATTLE);
|
||||
|
|
@ -81,15 +81,15 @@ namespace boss {
|
|||
}
|
||||
}
|
||||
|
||||
void Fight::PLAN_BATTLE(gui::Event ev, std::any data) {
|
||||
using enum gui::Event;
|
||||
void Fight::PLAN_BATTLE(game::Event ev, std::any data) {
|
||||
using enum game::Event;
|
||||
|
||||
switch(ev) {
|
||||
// this is only if using the debug X key to skip it
|
||||
case BOSS_START:
|
||||
state(State::END);
|
||||
break;
|
||||
case START_COMBAT:
|
||||
case COMBAT_START:
|
||||
$ui.status(L"EXEC PLAN");
|
||||
state(State::EXEC_PLAN);
|
||||
break;
|
||||
|
|
@ -114,12 +114,12 @@ namespace boss {
|
|||
}
|
||||
|
||||
void Fight::do_combat(std::any data) {
|
||||
if(data.type() != typeid(Events::Combat)) {
|
||||
if(data.type() != typeid(components::CombatResult)) {
|
||||
std::cout << "!!!!!! INVALID thing do_combat received: {}" << data.type().name() << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
auto result = std::any_cast<Events::Combat>(data);
|
||||
auto result = std::any_cast<components::CombatResult>(data);
|
||||
|
||||
if(result.enemy_did > 0) {
|
||||
// make boss move
|
||||
|
|
@ -134,15 +134,15 @@ namespace boss {
|
|||
|
||||
}
|
||||
|
||||
void Fight::EXEC_PLAN(gui::Event ev, std::any data) {
|
||||
using enum gui::Event;
|
||||
void Fight::EXEC_PLAN(game::Event ev, std::any data) {
|
||||
using enum game::Event;
|
||||
|
||||
switch(ev) {
|
||||
// this is only if using the debug X key to skip it
|
||||
case BOSS_START:
|
||||
state(State::END);
|
||||
break;
|
||||
case START_COMBAT:
|
||||
case COMBAT_START:
|
||||
next_combat_dumb_name();
|
||||
break;
|
||||
case COMBAT:
|
||||
|
|
@ -154,7 +154,7 @@ namespace boss {
|
|||
}
|
||||
}
|
||||
|
||||
void Fight::END(gui::Event ev, std::any) {
|
||||
void Fight::END(game::Event ev, std::any) {
|
||||
fmt::println("BOSS_FIGHT:END event {}", (int)ev);
|
||||
}
|
||||
|
||||
|
|
@ -171,8 +171,8 @@ namespace boss {
|
|||
$ui.render(window);
|
||||
}
|
||||
|
||||
bool Fight::handle_mouse(gui::Event ev) {
|
||||
using enum gui::Event;
|
||||
bool Fight::handle_mouse(game::Event ev) {
|
||||
using enum game::Event;
|
||||
|
||||
switch(ev) {
|
||||
case MOUSE_CLICK: {
|
||||
|
|
@ -209,30 +209,31 @@ namespace boss {
|
|||
|
||||
void Fight::handle_world_events() {
|
||||
fmt::println(">>>>>>>>>>>>>>>>> BOSS FIGHT EVENTS");
|
||||
dbc::check($world->has_event<Events::GUI>(), "World doesn't have GUI events.");
|
||||
dbc::check($world->has_event<game::Event>(), "World doesn't have GUI events.");
|
||||
|
||||
while($world->has_event<Events::GUI>()) {
|
||||
auto [evt, entity, data] = $world->recv<Events::GUI>();
|
||||
while($world->has_event<game::Event>()) {
|
||||
auto [evt, entity, data] = $world->recv<game::Event>();
|
||||
fmt::println("boss fight received event", int(evt));
|
||||
|
||||
switch(evt) {
|
||||
case Events::GUI::ATTACK:
|
||||
case game::Event::ATTACK:
|
||||
fmt::println("sending attack");
|
||||
event(gui::Event::ATTACK, data);
|
||||
event(game::Event::ATTACK, data);
|
||||
break;
|
||||
case Events::GUI::COMBAT_START:
|
||||
case game::Event::COMBAT_START:
|
||||
fmt::println("sending combat start {}", data.type().name());
|
||||
event(gui::Event::START_COMBAT, data);
|
||||
event(game::Event::COMBAT_START, data);
|
||||
break;
|
||||
case Events::GUI::COMBAT:
|
||||
case game::Event::COMBAT:
|
||||
fmt::println("sending combat {}", data.type().name());
|
||||
event(gui::Event::COMBAT, data);
|
||||
event(game::Event::COMBAT, data);
|
||||
break;
|
||||
default:
|
||||
fmt::println("GUI EVENT: {} entity={}", int(evt), entity);
|
||||
}
|
||||
}
|
||||
dbc::check(!$world->has_event<Events::GUI>(), "World still has events!");
|
||||
|
||||
dbc::check(!$world->has_event<game::Event>(), "World still has events!");
|
||||
fmt::println("<<<<<<<<<<<<<<<< BOSS FIGHT EVENTS");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include "simplefsm.hpp"
|
||||
#include "dinkyecs.hpp"
|
||||
#include "boss/ui.hpp"
|
||||
#include "gui/fsm_events.hpp"
|
||||
#include "events.hpp"
|
||||
#include "battle.hpp"
|
||||
#include <memory>
|
||||
#include <any>
|
||||
|
|
@ -20,7 +20,7 @@ namespace boss {
|
|||
END=4
|
||||
};
|
||||
|
||||
class Fight : public DeadSimpleFSM<State, gui::Event> {
|
||||
class Fight : public DeadSimpleFSM<State, game::Event> {
|
||||
public:
|
||||
shared_ptr<World> $world = nullptr;
|
||||
DinkyECS::Entity $boss_id = NONE;
|
||||
|
|
@ -32,14 +32,14 @@ namespace boss {
|
|||
|
||||
Fight(shared_ptr<World> world, Entity boss_id, Entity player_id);
|
||||
|
||||
bool handle_mouse(gui::Event ev);
|
||||
bool event(gui::Event ev, std::any data);
|
||||
bool handle_mouse(game::Event ev);
|
||||
bool event(game::Event ev, std::any data);
|
||||
|
||||
void START(gui::Event ev, std::any data);
|
||||
void PLAYER_REQUESTS(gui::Event ev, std::any data);
|
||||
void PLAN_BATTLE(gui::Event ev, std::any data);
|
||||
void EXEC_PLAN(gui::Event ev, std::any data);
|
||||
void END(gui::Event ev, std::any data);
|
||||
void START(game::Event ev, std::any data);
|
||||
void PLAYER_REQUESTS(game::Event ev, std::any data);
|
||||
void PLAN_BATTLE(game::Event ev, std::any data);
|
||||
void EXEC_PLAN(game::Event ev, std::any data);
|
||||
void END(game::Event ev, std::any data);
|
||||
void render(sf::RenderWindow& window);
|
||||
|
||||
void handle_world_events();
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ namespace boss {
|
|||
|
||||
auto& [enemy, wants_to, cost, host_state] = action;
|
||||
|
||||
Events::Combat result{};
|
||||
components::CombatResult result{};
|
||||
|
||||
switch(host_state) {
|
||||
case BattleHostState::agree:
|
||||
|
|
@ -127,6 +127,6 @@ namespace boss {
|
|||
break;
|
||||
}
|
||||
|
||||
world->send<Events::GUI>(Events::GUI::COMBAT, enemy.entity, result);
|
||||
world->send<game::Event>(game::Event::COMBAT, enemy.entity, result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
#include <fmt/xchar.h>
|
||||
#include "game_level.hpp"
|
||||
#include "gui/guecstra.hpp"
|
||||
#include "gui/fsm_events.hpp"
|
||||
#include "events.hpp"
|
||||
|
||||
namespace boss {
|
||||
using namespace guecs;
|
||||
|
|
@ -44,7 +44,7 @@ namespace boss {
|
|||
$actions.set<Text>(commit, {L"COMMIT"});
|
||||
$actions.set<Effect>(commit, {});
|
||||
$actions.set<Clickable>(commit,
|
||||
guecs::make_action(commit, Events::GUI::COMBAT_START, {}));
|
||||
guecs::make_action(commit, game::Event::COMBAT_START, {}));
|
||||
|
||||
auto stats = $actions.entity("stats");
|
||||
$actions.set<Rectangle>(stats, {});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue