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
|
|
@ -89,9 +89,9 @@ void Autowalker::process_combat() {
|
||||||
|| fsm.in_state(gui::State::ATTACKING))
|
|| fsm.in_state(gui::State::ATTACKING))
|
||||||
{
|
{
|
||||||
if(fsm.in_state(gui::State::ATTACKING)) {
|
if(fsm.in_state(gui::State::ATTACKING)) {
|
||||||
send_event(gui::Event::TICK);
|
send_event(game::Event::TICK);
|
||||||
} else {
|
} else {
|
||||||
send_event(gui::Event::ATTACK);
|
send_event(game::Event::ATTACK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -101,7 +101,7 @@ void Autowalker::path_fail(const std::string& msg, Matrix& bad_paths, Point pos)
|
||||||
status(L"PATH FAIL");
|
status(L"PATH FAIL");
|
||||||
matrix::dump("MOVE FAIL PATHS", bad_paths, pos.x, pos.y);
|
matrix::dump("MOVE FAIL PATHS", bad_paths, pos.x, pos.y);
|
||||||
log(L"Autowalk failed to find a path.");
|
log(L"Autowalk failed to find a path.");
|
||||||
send_event(gui::Event::BOSS_START);
|
send_event(game::Event::BOSS_START);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Autowalker::path_player(Pathing& paths, Point& target_out) {
|
bool Autowalker::path_player(Pathing& paths, Point& target_out) {
|
||||||
|
|
@ -146,7 +146,7 @@ void Autowalker::rotate_player(Point target) {
|
||||||
while(fsm.in_state(gui::State::ROTATING) ||
|
while(fsm.in_state(gui::State::ROTATING) ||
|
||||||
fsm.in_state(gui::State::COMBAT_ROTATE))
|
fsm.in_state(gui::State::COMBAT_ROTATE))
|
||||||
{
|
{
|
||||||
send_event(gui::Event::TICK);
|
send_event(game::Event::TICK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -178,7 +178,7 @@ void Autowalker::handle_boss_fight() {
|
||||||
// skip the boss fight for now
|
// skip the boss fight for now
|
||||||
if(fsm.in_state(gui::State::BOSS_FIGHT)) {
|
if(fsm.in_state(gui::State::BOSS_FIGHT)) {
|
||||||
// eventually we'll have AI handle this too
|
// eventually we'll have AI handle this too
|
||||||
send_event(gui::Event::BOSS_END);
|
send_event(game::Event::BOSS_END);
|
||||||
face_enemy();
|
face_enemy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -240,23 +240,23 @@ void Autowalker::craft_weapon() {
|
||||||
fsm.$status_ui.$gui.click_on("ritual_ui");
|
fsm.$status_ui.$gui.click_on("ritual_ui");
|
||||||
|
|
||||||
while(!ritual_ui.in_state(gui::ritual::State::OPENED)) {
|
while(!ritual_ui.in_state(gui::ritual::State::OPENED)) {
|
||||||
send_event(gui::Event::TICK);
|
send_event(game::Event::TICK);
|
||||||
}
|
}
|
||||||
|
|
||||||
ritual_ui.$gui.click_on("inv_slot0");
|
ritual_ui.$gui.click_on("inv_slot0");
|
||||||
send_event(gui::Event::TICK);
|
send_event(game::Event::TICK);
|
||||||
ritual_ui.$gui.click_on("inv_slot1");
|
ritual_ui.$gui.click_on("inv_slot1");
|
||||||
send_event(gui::Event::TICK);
|
send_event(game::Event::TICK);
|
||||||
|
|
||||||
while(!ritual_ui.in_state(gui::ritual::State::CRAFTING)) {
|
while(!ritual_ui.in_state(gui::ritual::State::CRAFTING)) {
|
||||||
send_event(gui::Event::TICK);
|
send_event(game::Event::TICK);
|
||||||
}
|
}
|
||||||
|
|
||||||
ritual_ui.$gui.click_on("result_image", true);
|
ritual_ui.$gui.click_on("result_image", true);
|
||||||
send_event(gui::Event::TICK);
|
send_event(game::Event::TICK);
|
||||||
|
|
||||||
ritual_ui.$gui.click_on("ritual_ui");
|
ritual_ui.$gui.click_on("ritual_ui");
|
||||||
send_event(gui::Event::TICK);
|
send_event(game::Event::TICK);
|
||||||
weapon_crafted = true;
|
weapon_crafted = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -264,7 +264,7 @@ void Autowalker::craft_weapon() {
|
||||||
void Autowalker::open_map() {
|
void Autowalker::open_map() {
|
||||||
if(!map_opened_once) {
|
if(!map_opened_once) {
|
||||||
if(!fsm.$map_open) {
|
if(!fsm.$map_open) {
|
||||||
send_event(gui::Event::MAP_OPEN);
|
send_event(game::Event::MAP_OPEN);
|
||||||
map_opened_once = true;
|
map_opened_once = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -272,7 +272,7 @@ void Autowalker::open_map() {
|
||||||
|
|
||||||
void Autowalker::close_map() {
|
void Autowalker::close_map() {
|
||||||
if(fsm.$map_open) {
|
if(fsm.$map_open) {
|
||||||
send_event(gui::Event::MAP_OPEN);
|
send_event(game::Event::MAP_OPEN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -319,8 +319,8 @@ bool Autowalker::process_move(Pathing& paths, std::function<bool(Point)> is_that
|
||||||
bool found_it = is_that_it(target_out);
|
bool found_it = is_that_it(target_out);
|
||||||
|
|
||||||
if(!found_it) {
|
if(!found_it) {
|
||||||
send_event(gui::Event::MOVE_FORWARD);
|
send_event(game::Event::MOVE_FORWARD);
|
||||||
while(fsm.in_state(gui::State::MOVING)) send_event(gui::Event::TICK);
|
while(fsm.in_state(gui::State::MOVING)) send_event(game::Event::TICK);
|
||||||
}
|
}
|
||||||
|
|
||||||
return found_it;
|
return found_it;
|
||||||
|
|
@ -347,7 +347,7 @@ bool Autowalker::found_item() {
|
||||||
return aimed_at != DinkyECS::NONE && world->has<components::InventoryItem>(aimed_at);
|
return aimed_at != DinkyECS::NONE && world->has<components::InventoryItem>(aimed_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Autowalker::send_event(gui::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_world_events();
|
||||||
|
|
@ -385,12 +385,12 @@ void Autowalker::player_use_healing() {
|
||||||
|
|
||||||
if(inventory.has("pocket_r")) {
|
if(inventory.has("pocket_r")) {
|
||||||
auto gui_id = fsm.$status_ui.$gui.entity("pocket_r");
|
auto gui_id = fsm.$status_ui.$gui.entity("pocket_r");
|
||||||
send_event(gui::Event::USE_ITEM, gui_id);
|
send_event(game::Event::USE_ITEM, gui_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(inventory.has("pocket_l")) {
|
if(inventory.has("pocket_l")) {
|
||||||
auto gui_id = fsm.$status_ui.$gui.entity("pocket_l");
|
auto gui_id = fsm.$status_ui.$gui.entity("pocket_l");
|
||||||
send_event(gui::Event::USE_ITEM, gui_id);
|
send_event(game::Event::USE_ITEM, gui_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -431,7 +431,7 @@ void Autowalker::pocket_potion(GameDB::Level &level) {
|
||||||
player_use_healing();
|
player_use_healing();
|
||||||
}
|
}
|
||||||
|
|
||||||
send_event(gui::Event::AIM_CLICK);
|
send_event(game::Event::AIM_CLICK);
|
||||||
|
|
||||||
if(inventory.has("pocket_r")) {
|
if(inventory.has("pocket_r")) {
|
||||||
click_inventory("pocket_l", {1 << guecs::ModBit::left});
|
click_inventory("pocket_l", {1 << guecs::ModBit::left});
|
||||||
|
|
@ -454,7 +454,7 @@ void Autowalker::pickup_item() {
|
||||||
pocket_potion(level);
|
pocket_potion(level);
|
||||||
status(L"A POTION");
|
status(L"A POTION");
|
||||||
} else {
|
} else {
|
||||||
send_event(gui::Event::AIM_CLICK);
|
send_event(game::Event::AIM_CLICK);
|
||||||
status(L"I DON'T KNOW");
|
status(L"I DON'T KNOW");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ struct Autowalker {
|
||||||
void handle_boss_fight();
|
void handle_boss_fight();
|
||||||
void handle_player_walk(ai::State& start, ai::State& goal);
|
void handle_player_walk(ai::State& start, ai::State& goal);
|
||||||
|
|
||||||
void send_event(gui::Event ev, std::any data={});
|
void send_event(game::Event ev, std::any data={});
|
||||||
void process_combat();
|
void process_combat();
|
||||||
bool process_move(Pathing& paths, std::function<bool(Point)> cb);
|
bool process_move(Pathing& paths, std::function<bool(Point)> cb);
|
||||||
bool path_player(Pathing& paths, Point &target_out);
|
bool path_player(Pathing& paths, Point &target_out);
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ namespace boss {
|
||||||
$ui.init();
|
$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 the mouse event is handled the done, this may be wrong later
|
||||||
if(handle_mouse(ev)) return in_state(State::END);
|
if(handle_mouse(ev)) return in_state(State::END);
|
||||||
|
|
||||||
|
|
@ -35,8 +35,8 @@ namespace boss {
|
||||||
return in_state(State::END);
|
return in_state(State::END);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fight::START(gui::Event ev, std::any) {
|
void Fight::START(game::Event ev, std::any) {
|
||||||
using enum gui::Event;
|
using enum game::Event;
|
||||||
|
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
// this is only if using the debug X key to skip it
|
// 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) {
|
void Fight::PLAYER_REQUESTS(game::Event ev, std::any data) {
|
||||||
using enum gui::Event;
|
using enum game::Event;
|
||||||
|
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
// this is only if using the debug X key to skip it
|
// this is only if using the debug X key to skip it
|
||||||
case BOSS_START:
|
case BOSS_START:
|
||||||
state(State::END);
|
state(State::END);
|
||||||
break;
|
break;
|
||||||
case START_COMBAT:
|
case COMBAT_START:
|
||||||
System::plan_battle($battle, $world, $boss_id);
|
System::plan_battle($battle, $world, $boss_id);
|
||||||
$ui.status(L"PLANNING BATTLE");
|
$ui.status(L"PLANNING BATTLE");
|
||||||
state(State::PLAN_BATTLE);
|
state(State::PLAN_BATTLE);
|
||||||
|
|
@ -81,15 +81,15 @@ namespace boss {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fight::PLAN_BATTLE(gui::Event ev, std::any data) {
|
void Fight::PLAN_BATTLE(game::Event ev, std::any data) {
|
||||||
using enum gui::Event;
|
using enum game::Event;
|
||||||
|
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
// this is only if using the debug X key to skip it
|
// this is only if using the debug X key to skip it
|
||||||
case BOSS_START:
|
case BOSS_START:
|
||||||
state(State::END);
|
state(State::END);
|
||||||
break;
|
break;
|
||||||
case START_COMBAT:
|
case COMBAT_START:
|
||||||
$ui.status(L"EXEC PLAN");
|
$ui.status(L"EXEC PLAN");
|
||||||
state(State::EXEC_PLAN);
|
state(State::EXEC_PLAN);
|
||||||
break;
|
break;
|
||||||
|
|
@ -114,12 +114,12 @@ namespace boss {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fight::do_combat(std::any data) {
|
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;
|
std::cout << "!!!!!! INVALID thing do_combat received: {}" << data.type().name() << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto result = std::any_cast<Events::Combat>(data);
|
auto result = std::any_cast<components::CombatResult>(data);
|
||||||
|
|
||||||
if(result.enemy_did > 0) {
|
if(result.enemy_did > 0) {
|
||||||
// make boss move
|
// make boss move
|
||||||
|
|
@ -134,15 +134,15 @@ namespace boss {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fight::EXEC_PLAN(gui::Event ev, std::any data) {
|
void Fight::EXEC_PLAN(game::Event ev, std::any data) {
|
||||||
using enum gui::Event;
|
using enum game::Event;
|
||||||
|
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
// this is only if using the debug X key to skip it
|
// this is only if using the debug X key to skip it
|
||||||
case BOSS_START:
|
case BOSS_START:
|
||||||
state(State::END);
|
state(State::END);
|
||||||
break;
|
break;
|
||||||
case START_COMBAT:
|
case COMBAT_START:
|
||||||
next_combat_dumb_name();
|
next_combat_dumb_name();
|
||||||
break;
|
break;
|
||||||
case COMBAT:
|
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);
|
fmt::println("BOSS_FIGHT:END event {}", (int)ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -171,8 +171,8 @@ namespace boss {
|
||||||
$ui.render(window);
|
$ui.render(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Fight::handle_mouse(gui::Event ev) {
|
bool Fight::handle_mouse(game::Event ev) {
|
||||||
using enum gui::Event;
|
using enum game::Event;
|
||||||
|
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
case MOUSE_CLICK: {
|
case MOUSE_CLICK: {
|
||||||
|
|
@ -209,30 +209,31 @@ namespace boss {
|
||||||
|
|
||||||
void Fight::handle_world_events() {
|
void Fight::handle_world_events() {
|
||||||
fmt::println(">>>>>>>>>>>>>>>>> BOSS FIGHT 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>()) {
|
while($world->has_event<game::Event>()) {
|
||||||
auto [evt, entity, data] = $world->recv<Events::GUI>();
|
auto [evt, entity, data] = $world->recv<game::Event>();
|
||||||
fmt::println("boss fight received event", int(evt));
|
fmt::println("boss fight received event", int(evt));
|
||||||
|
|
||||||
switch(evt) {
|
switch(evt) {
|
||||||
case Events::GUI::ATTACK:
|
case game::Event::ATTACK:
|
||||||
fmt::println("sending attack");
|
fmt::println("sending attack");
|
||||||
event(gui::Event::ATTACK, data);
|
event(game::Event::ATTACK, data);
|
||||||
break;
|
break;
|
||||||
case Events::GUI::COMBAT_START:
|
case game::Event::COMBAT_START:
|
||||||
fmt::println("sending combat start {}", data.type().name());
|
fmt::println("sending combat start {}", data.type().name());
|
||||||
event(gui::Event::START_COMBAT, data);
|
event(game::Event::COMBAT_START, data);
|
||||||
break;
|
break;
|
||||||
case Events::GUI::COMBAT:
|
case game::Event::COMBAT:
|
||||||
fmt::println("sending combat {}", data.type().name());
|
fmt::println("sending combat {}", data.type().name());
|
||||||
event(gui::Event::COMBAT, data);
|
event(game::Event::COMBAT, data);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fmt::println("GUI EVENT: {} entity={}", int(evt), entity);
|
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");
|
fmt::println("<<<<<<<<<<<<<<<< BOSS FIGHT EVENTS");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
#include "simplefsm.hpp"
|
#include "simplefsm.hpp"
|
||||||
#include "dinkyecs.hpp"
|
#include "dinkyecs.hpp"
|
||||||
#include "boss/ui.hpp"
|
#include "boss/ui.hpp"
|
||||||
#include "gui/fsm_events.hpp"
|
#include "events.hpp"
|
||||||
#include "battle.hpp"
|
#include "battle.hpp"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <any>
|
#include <any>
|
||||||
|
|
@ -20,7 +20,7 @@ namespace boss {
|
||||||
END=4
|
END=4
|
||||||
};
|
};
|
||||||
|
|
||||||
class Fight : public DeadSimpleFSM<State, gui::Event> {
|
class Fight : public DeadSimpleFSM<State, game::Event> {
|
||||||
public:
|
public:
|
||||||
shared_ptr<World> $world = nullptr;
|
shared_ptr<World> $world = nullptr;
|
||||||
DinkyECS::Entity $boss_id = NONE;
|
DinkyECS::Entity $boss_id = NONE;
|
||||||
|
|
@ -32,14 +32,14 @@ namespace boss {
|
||||||
|
|
||||||
Fight(shared_ptr<World> world, Entity boss_id, Entity player_id);
|
Fight(shared_ptr<World> world, Entity boss_id, Entity player_id);
|
||||||
|
|
||||||
bool handle_mouse(gui::Event ev);
|
bool handle_mouse(game::Event ev);
|
||||||
bool event(gui::Event ev, std::any data);
|
bool event(game::Event ev, std::any data);
|
||||||
|
|
||||||
void START(gui::Event ev, std::any data);
|
void START(game::Event ev, std::any data);
|
||||||
void PLAYER_REQUESTS(gui::Event ev, std::any data);
|
void PLAYER_REQUESTS(game::Event ev, std::any data);
|
||||||
void PLAN_BATTLE(gui::Event ev, std::any data);
|
void PLAN_BATTLE(game::Event ev, std::any data);
|
||||||
void EXEC_PLAN(gui::Event ev, std::any data);
|
void EXEC_PLAN(game::Event ev, std::any data);
|
||||||
void END(gui::Event ev, std::any data);
|
void END(game::Event ev, std::any data);
|
||||||
void render(sf::RenderWindow& window);
|
void render(sf::RenderWindow& window);
|
||||||
|
|
||||||
void handle_world_events();
|
void handle_world_events();
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ namespace boss {
|
||||||
|
|
||||||
auto& [enemy, wants_to, cost, host_state] = action;
|
auto& [enemy, wants_to, cost, host_state] = action;
|
||||||
|
|
||||||
Events::Combat result{};
|
components::CombatResult result{};
|
||||||
|
|
||||||
switch(host_state) {
|
switch(host_state) {
|
||||||
case BattleHostState::agree:
|
case BattleHostState::agree:
|
||||||
|
|
@ -127,6 +127,6 @@ namespace boss {
|
||||||
break;
|
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 <fmt/xchar.h>
|
||||||
#include "game_level.hpp"
|
#include "game_level.hpp"
|
||||||
#include "gui/guecstra.hpp"
|
#include "gui/guecstra.hpp"
|
||||||
#include "gui/fsm_events.hpp"
|
#include "events.hpp"
|
||||||
|
|
||||||
namespace boss {
|
namespace boss {
|
||||||
using namespace guecs;
|
using namespace guecs;
|
||||||
|
|
@ -44,7 +44,7 @@ namespace boss {
|
||||||
$actions.set<Text>(commit, {L"COMMIT"});
|
$actions.set<Text>(commit, {L"COMMIT"});
|
||||||
$actions.set<Effect>(commit, {});
|
$actions.set<Effect>(commit, {});
|
||||||
$actions.set<Clickable>(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");
|
auto stats = $actions.entity("stats");
|
||||||
$actions.set<Rectangle>(stats, {});
|
$actions.set<Rectangle>(stats, {});
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,11 @@ namespace components {
|
||||||
using std::string;
|
using std::string;
|
||||||
using namespace nlohmann;
|
using namespace nlohmann;
|
||||||
|
|
||||||
|
struct CombatResult {
|
||||||
|
int player_did;
|
||||||
|
int enemy_did;
|
||||||
|
};
|
||||||
|
|
||||||
struct InventoryItem {
|
struct InventoryItem {
|
||||||
int count;
|
int count;
|
||||||
json data;
|
json data;
|
||||||
|
|
|
||||||
56
events.hpp
56
events.hpp
|
|
@ -1,17 +1,47 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
namespace Events {
|
namespace game {
|
||||||
enum GUI {
|
enum Event {
|
||||||
START, COMBAT, DEATH, STAIRS_UP, STAIRS_DOWN, TRAP,
|
AIM_CLICK=__LINE__,
|
||||||
COMBAT_START, NO_NEIGHBORS, HP_STATUS,
|
ATTACK=__LINE__,
|
||||||
ATTACK, NEW_RITUAL,
|
BOSS_END=__LINE__,
|
||||||
UPDATE_SPRITE, ENTITY_SPAWN, NOOP,
|
BOSS_START=__LINE__,
|
||||||
LOOT_ITEM, LOOT_CONTAINER,
|
CLOSE=__LINE__,
|
||||||
LOOT_CLOSE, LOOT_SELECT, INV_SELECT, AIM_CLICK
|
COMBAT=__LINE__,
|
||||||
};
|
COMBAT_START=__LINE__,
|
||||||
|
COMBAT_STOP=__LINE__,
|
||||||
struct Combat {
|
DEATH=__LINE__,
|
||||||
int player_did;
|
ENTITY_SPAWN=__LINE__,
|
||||||
int enemy_did;
|
HP_STATUS=__LINE__,
|
||||||
|
INV_SELECT=__LINE__,
|
||||||
|
KEY_PRESS=__LINE__,
|
||||||
|
LOOT_CLOSE=__LINE__,
|
||||||
|
LOOT_CONTAINER=__LINE__,
|
||||||
|
LOOT_ITEM=__LINE__,
|
||||||
|
LOOT_OPEN=__LINE__,
|
||||||
|
LOOT_SELECT=__LINE__,
|
||||||
|
MAP_OPEN=__LINE__,
|
||||||
|
MOUSE_CLICK=__LINE__,
|
||||||
|
MOUSE_DRAG=__LINE__,
|
||||||
|
MOUSE_DRAG_START=__LINE__,
|
||||||
|
MOUSE_DROP=__LINE__,
|
||||||
|
MOUSE_MOVE=__LINE__,
|
||||||
|
MOVE_BACK=__LINE__,
|
||||||
|
MOVE_FORWARD=__LINE__,
|
||||||
|
MOVE_LEFT=__LINE__,
|
||||||
|
MOVE_RIGHT=__LINE__,
|
||||||
|
NEW_RITUAL=__LINE__,
|
||||||
|
NOOP=__LINE__,
|
||||||
|
NO_NEIGHBORS=__LINE__,
|
||||||
|
QUIT=__LINE__,
|
||||||
|
ROTATE_LEFT=__LINE__,
|
||||||
|
ROTATE_RIGHT=__LINE__,
|
||||||
|
STAIRS_DOWN=__LINE__,
|
||||||
|
STAIRS_UP=__LINE__,
|
||||||
|
START=__LINE__,
|
||||||
|
TICK=__LINE__,
|
||||||
|
TRAP=__LINE__,
|
||||||
|
UPDATE_SPRITE=__LINE__,
|
||||||
|
USE_ITEM=__LINE__,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ namespace gui {
|
||||||
|
|
||||||
guecs::Entity CombatUI::make_button(
|
guecs::Entity CombatUI::make_button(
|
||||||
guecs::Entity button,
|
guecs::Entity button,
|
||||||
Events::GUI event,
|
game::Event event,
|
||||||
int action,
|
int action,
|
||||||
const std::string &icon_name,
|
const std::string &icon_name,
|
||||||
const std::string &sound,
|
const std::string &sound,
|
||||||
|
|
@ -62,15 +62,15 @@ namespace gui {
|
||||||
|
|
||||||
switch(ritual.element) {
|
switch(ritual.element) {
|
||||||
case FIRE:
|
case FIRE:
|
||||||
make_button(button, Events::GUI::ATTACK,
|
make_button(button, game::Event::ATTACK,
|
||||||
slot, "broken_yoyo", "fireball_01", "flame");
|
slot, "broken_yoyo", "fireball_01", "flame");
|
||||||
break;
|
break;
|
||||||
case LIGHTNING:
|
case LIGHTNING:
|
||||||
make_button(button, Events::GUI::ATTACK,
|
make_button(button, game::Event::ATTACK,
|
||||||
slot, "pocket_watch", "electric_shock_01", "lightning");
|
slot, "pocket_watch", "electric_shock_01", "lightning");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
make_button(button, Events::GUI::ATTACK,
|
make_button(button, game::Event::ATTACK,
|
||||||
slot, "severed_finger", "punch_cartoony", "ui_shader");
|
slot, "severed_finger", "punch_cartoony", "ui_shader");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -80,7 +80,7 @@ namespace gui {
|
||||||
auto hp_gauge = $gui.entity("hp_gauge");
|
auto hp_gauge = $gui.entity("hp_gauge");
|
||||||
$gui.set<Sprite>(hp_gauge, {"stone_doll_cursed"});
|
$gui.set<Sprite>(hp_gauge, {"stone_doll_cursed"});
|
||||||
$gui.set<Clickable>(hp_gauge,
|
$gui.set<Clickable>(hp_gauge,
|
||||||
guecs::make_action(hp_gauge, Events::GUI::HP_STATUS, {}));
|
guecs::make_action(hp_gauge, game::Event::HP_STATUS, {}));
|
||||||
}
|
}
|
||||||
|
|
||||||
$gui.init();
|
$gui.init();
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ namespace gui {
|
||||||
void render(sf::RenderWindow& window);
|
void render(sf::RenderWindow& window);
|
||||||
void update_level();
|
void update_level();
|
||||||
bool mouse(float x, float y, guecs::Modifiers mods);
|
bool mouse(float x, float y, guecs::Modifiers mods);
|
||||||
guecs::Entity make_button(guecs::Entity button, Events::GUI event,
|
guecs::Entity make_button(guecs::Entity button, game::Event event,
|
||||||
int action, const std::string &icon_name,
|
int action, const std::string &icon_name,
|
||||||
const std::string &sound, const std::string &effect_name);
|
const std::string &sound, const std::string &effect_name);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ namespace gui {
|
||||||
dbc::log("THIS FUNCTION NEEDS A REWRITE");
|
dbc::log("THIS FUNCTION NEEDS A REWRITE");
|
||||||
// auto ent = $level_mgr.spawn_enemy(enemy_key);
|
// auto ent = $level_mgr.spawn_enemy(enemy_key);
|
||||||
// auto& level = $level_mgr.current();
|
// auto& level = $level_mgr.current();
|
||||||
// level.world->send<Events::GUI>(Events::GUI::ENTITY_SPAWN, ent, {});
|
// level.world->send<game::Event>(game::Event::ENTITY_SPAWN, ent, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugUI::render(sf::RenderWindow& window) {
|
void DebugUI::render(sf::RenderWindow& window) {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#include "gui/dnd_loot.hpp"
|
#include "gui/dnd_loot.hpp"
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
|
using Event = game::Event;
|
||||||
|
|
||||||
DNDLoot::DNDLoot(StatusUI& status_ui, LootUI& loot_ui, sf::RenderWindow &window, routing::Router& router) :
|
DNDLoot::DNDLoot(StatusUI& status_ui, LootUI& loot_ui, sf::RenderWindow &window, routing::Router& router) :
|
||||||
$status_ui(status_ui),
|
$status_ui(status_ui),
|
||||||
|
|
@ -9,7 +10,7 @@ namespace gui {
|
||||||
$window(window),
|
$window(window),
|
||||||
$router(router)
|
$router(router)
|
||||||
{
|
{
|
||||||
event(Event::STARTED);
|
event(Event::START);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DNDLoot::event(Event ev, std::any data) {
|
bool DNDLoot::event(Event ev, std::any data) {
|
||||||
|
|
@ -30,7 +31,7 @@ namespace gui {
|
||||||
|
|
||||||
void DNDLoot::START(Event ev) {
|
void DNDLoot::START(Event ev) {
|
||||||
using enum Event;
|
using enum Event;
|
||||||
dbc::check(ev == STARTED, "START not given a STARTED event.");
|
dbc::check(ev == START, "START not given a STARTED event.");
|
||||||
END(CLOSE);
|
END(CLOSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include "gui/status_ui.hpp"
|
#include "gui/status_ui.hpp"
|
||||||
#include "gui/loot_ui.hpp"
|
#include "gui/loot_ui.hpp"
|
||||||
#include "gui/event_router.hpp"
|
#include "gui/event_router.hpp"
|
||||||
|
#include "events.hpp"
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
enum class DNDState {
|
enum class DNDState {
|
||||||
|
|
@ -16,7 +17,7 @@ namespace gui {
|
||||||
END=106
|
END=106
|
||||||
};
|
};
|
||||||
|
|
||||||
class DNDLoot : public DeadSimpleFSM<DNDState, Event> {
|
class DNDLoot : public DeadSimpleFSM<DNDState, game::Event> {
|
||||||
public:
|
public:
|
||||||
std::optional<guecs::Entity> $grab_source = std::nullopt;
|
std::optional<guecs::Entity> $grab_source = std::nullopt;
|
||||||
std::shared_ptr<sf::Sprite> $grab_sprite = nullptr;
|
std::shared_ptr<sf::Sprite> $grab_sprite = nullptr;
|
||||||
|
|
@ -29,17 +30,17 @@ namespace gui {
|
||||||
LootUI& loot_ui, sf::RenderWindow& window,
|
LootUI& loot_ui, sf::RenderWindow& window,
|
||||||
routing::Router& router);
|
routing::Router& router);
|
||||||
|
|
||||||
bool event(Event ev, std::any data={});
|
bool event(game::Event ev, std::any data={});
|
||||||
|
|
||||||
void START(Event ev);
|
void START(game::Event ev);
|
||||||
void LOOTING(Event ev, std::any data);
|
void LOOTING(game::Event ev, std::any data);
|
||||||
void LOOT_GRAB(Event ev, std::any data);
|
void LOOT_GRAB(game::Event ev, std::any data);
|
||||||
void INV_GRAB(Event ev, std::any data);
|
void INV_GRAB(game::Event ev, std::any data);
|
||||||
void END(Event ev, std::any data={});
|
void END(game::Event ev, std::any data={});
|
||||||
void ITEM_PICKUP(Event ev, std::any data);
|
void ITEM_PICKUP(game::Event ev, std::any data);
|
||||||
void INV_PICKUP(Event ev, std::any data);
|
void INV_PICKUP(game::Event ev, std::any data);
|
||||||
|
|
||||||
void handle_mouse(Event ev, guecs::UI& gui);
|
void handle_mouse(game::Event ev, guecs::UI& gui);
|
||||||
void render();
|
void render();
|
||||||
void open();
|
void open();
|
||||||
void close();
|
void close();
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@ namespace gui {
|
||||||
using enum Event;
|
using enum Event;
|
||||||
using enum State;
|
using enum State;
|
||||||
|
|
||||||
gui::Event Router::process_event(std::optional<sf::Event> ev) {
|
game::Event Router::process_event(std::optional<sf::Event> ev) {
|
||||||
$next_event = gui::Event::TICK;
|
$next_event = game::Event::TICK;
|
||||||
|
|
||||||
if(ev->is<sf::Event::Closed>()) {
|
if(ev->is<sf::Event::Closed>()) {
|
||||||
return gui::Event::QUIT;
|
return game::Event::QUIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(const auto* mouse = ev->getIf<sf::Event::MouseButtonPressed>()) {
|
if(const auto* mouse = ev->getIf<sf::Event::MouseButtonPressed>()) {
|
||||||
|
|
@ -58,18 +58,18 @@ namespace gui {
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
case MOUSE_DOWN:
|
case MOUSE_DOWN:
|
||||||
move_count=0;
|
move_count=0;
|
||||||
set_event(gui::Event::TICK);
|
set_event(game::Event::TICK);
|
||||||
state(State::MOUSE_ACTIVE);
|
state(State::MOUSE_ACTIVE);
|
||||||
break;
|
break;
|
||||||
case MOUSE_UP:
|
case MOUSE_UP:
|
||||||
set_event(gui::Event::MOUSE_CLICK);
|
set_event(game::Event::MOUSE_CLICK);
|
||||||
state(State::IDLE);
|
state(State::IDLE);
|
||||||
break;
|
break;
|
||||||
case MOUSE_MOVE:
|
case MOUSE_MOVE:
|
||||||
set_event(gui::Event::MOUSE_MOVE);
|
set_event(game::Event::MOUSE_MOVE);
|
||||||
break;
|
break;
|
||||||
case KEY_PRESS:
|
case KEY_PRESS:
|
||||||
set_event(gui::Event::KEY_PRESS);
|
set_event(game::Event::KEY_PRESS);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dbc::sentinel(fmt::format("invalid event: {}", int(ev)));
|
dbc::sentinel(fmt::format("invalid event: {}", int(ev)));
|
||||||
|
|
@ -79,16 +79,16 @@ namespace gui {
|
||||||
void Router::MOUSE_ACTIVE(Event ev) {
|
void Router::MOUSE_ACTIVE(Event ev) {
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
case MOUSE_UP:
|
case MOUSE_UP:
|
||||||
set_event(gui::Event::MOUSE_CLICK);
|
set_event(game::Event::MOUSE_CLICK);
|
||||||
state(State::IDLE);
|
state(State::IDLE);
|
||||||
break;
|
break;
|
||||||
case MOUSE_MOVE:
|
case MOUSE_MOVE:
|
||||||
move_count++;
|
move_count++;
|
||||||
set_event(gui::Event::MOUSE_DRAG);
|
set_event(game::Event::MOUSE_DRAG);
|
||||||
state(State::MOUSE_MOVING);
|
state(State::MOUSE_MOVING);
|
||||||
break;
|
break;
|
||||||
case KEY_PRESS:
|
case KEY_PRESS:
|
||||||
set_event(gui::Event::KEY_PRESS);
|
set_event(game::Event::KEY_PRESS);
|
||||||
state(State::IDLE);
|
state(State::IDLE);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
@ -100,21 +100,21 @@ namespace gui {
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
case MOUSE_UP: {
|
case MOUSE_UP: {
|
||||||
dbc::check(move_count < $drag_tolerance, "mouse up but not in dragging state");
|
dbc::check(move_count < $drag_tolerance, "mouse up but not in dragging state");
|
||||||
set_event(gui::Event::MOUSE_CLICK);
|
set_event(game::Event::MOUSE_CLICK);
|
||||||
state(State::IDLE);
|
state(State::IDLE);
|
||||||
} break;
|
} break;
|
||||||
case MOUSE_MOVE:
|
case MOUSE_MOVE:
|
||||||
move_count++;
|
move_count++;
|
||||||
|
|
||||||
if(move_count < $drag_tolerance) {
|
if(move_count < $drag_tolerance) {
|
||||||
set_event(gui::Event::MOUSE_DRAG);
|
set_event(game::Event::MOUSE_DRAG);
|
||||||
} else {
|
} else {
|
||||||
set_event(gui::Event::MOUSE_DRAG_START);
|
set_event(game::Event::MOUSE_DRAG_START);
|
||||||
state(State::MOUSE_DRAGGING);
|
state(State::MOUSE_DRAGGING);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case KEY_PRESS:
|
case KEY_PRESS:
|
||||||
set_event(gui::Event::KEY_PRESS);
|
set_event(game::Event::KEY_PRESS);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dbc::sentinel("invalid event");
|
dbc::sentinel("invalid event");
|
||||||
|
|
@ -125,15 +125,15 @@ namespace gui {
|
||||||
void Router::MOUSE_DRAGGING(Event ev) {
|
void Router::MOUSE_DRAGGING(Event ev) {
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
case MOUSE_UP:
|
case MOUSE_UP:
|
||||||
set_event(gui::Event::MOUSE_DROP);
|
set_event(game::Event::MOUSE_DROP);
|
||||||
state(State::IDLE);
|
state(State::IDLE);
|
||||||
break;
|
break;
|
||||||
case MOUSE_MOVE:
|
case MOUSE_MOVE:
|
||||||
move_count++;
|
move_count++;
|
||||||
set_event(gui::Event::MOUSE_DRAG);
|
set_event(game::Event::MOUSE_DRAG);
|
||||||
break;
|
break;
|
||||||
case KEY_PRESS:
|
case KEY_PRESS:
|
||||||
set_event(gui::Event::KEY_PRESS);
|
set_event(game::Event::KEY_PRESS);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dbc::sentinel("invalid events");
|
dbc::sentinel("invalid events");
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "events.hpp"
|
#include "events.hpp"
|
||||||
#include "gui/fsm_events.hpp"
|
#include "events.hpp"
|
||||||
#include "simplefsm.hpp"
|
#include "simplefsm.hpp"
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
|
|
@ -26,7 +26,7 @@ namespace gui {
|
||||||
public:
|
public:
|
||||||
sf::Vector2i position;
|
sf::Vector2i position;
|
||||||
sf::Keyboard::Scancode scancode;
|
sf::Keyboard::Scancode scancode;
|
||||||
gui::Event $next_event = gui::Event::TICK;
|
game::Event $next_event = game::Event::TICK;
|
||||||
int move_count = 0;
|
int move_count = 0;
|
||||||
bool left_button = true;
|
bool left_button = true;
|
||||||
int $drag_tolerance = 4;
|
int $drag_tolerance = 4;
|
||||||
|
|
@ -39,9 +39,9 @@ namespace gui {
|
||||||
void MOUSE_MOVING(Event ev);
|
void MOUSE_MOVING(Event ev);
|
||||||
void MOUSE_DRAGGING(Event ev);
|
void MOUSE_DRAGGING(Event ev);
|
||||||
|
|
||||||
gui::Event process_event(std::optional<sf::Event> ev);
|
game::Event process_event(std::optional<sf::Event> ev);
|
||||||
|
|
||||||
void set_event(gui::Event ev) {
|
void set_event(game::Event ev) {
|
||||||
$next_event = ev;
|
$next_event = ev;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
20
gui/fsm.cpp
20
gui/fsm.cpp
|
|
@ -6,7 +6,6 @@
|
||||||
#include "components.hpp"
|
#include "components.hpp"
|
||||||
#include <numbers>
|
#include <numbers>
|
||||||
#include "systems.hpp"
|
#include "systems.hpp"
|
||||||
#include "gui/fsm_events.hpp"
|
|
||||||
#include "events.hpp"
|
#include "events.hpp"
|
||||||
#include "sound.hpp"
|
#include "sound.hpp"
|
||||||
#include "shaders.hpp"
|
#include "shaders.hpp"
|
||||||
|
|
@ -17,6 +16,7 @@
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
using namespace components;
|
using namespace components;
|
||||||
|
using game::Event;
|
||||||
|
|
||||||
FSM::FSM() :
|
FSM::FSM() :
|
||||||
$window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Zed's Raycaster Thing"),
|
$window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Zed's Raycaster Thing"),
|
||||||
|
|
@ -83,7 +83,7 @@ namespace gui {
|
||||||
run_systems();
|
run_systems();
|
||||||
state(State::IN_COMBAT);
|
state(State::IN_COMBAT);
|
||||||
} break;
|
} break;
|
||||||
case STOP_COMBAT:
|
case COMBAT_STOP:
|
||||||
state(State::IDLE);
|
state(State::IDLE);
|
||||||
break;
|
break;
|
||||||
case ATTACK: {
|
case ATTACK: {
|
||||||
|
|
@ -165,7 +165,7 @@ namespace gui {
|
||||||
case ATTACK:
|
case ATTACK:
|
||||||
state(State::ATTACKING);
|
state(State::ATTACKING);
|
||||||
break;
|
break;
|
||||||
case START_COMBAT:
|
case COMBAT_START:
|
||||||
$map_open = false;
|
$map_open = false;
|
||||||
state(State::IN_COMBAT);
|
state(State::IN_COMBAT);
|
||||||
break;
|
break;
|
||||||
|
|
@ -215,7 +215,7 @@ namespace gui {
|
||||||
dbc::check($boss_fight != nullptr, "$boss_fight not initialized");
|
dbc::check($boss_fight != nullptr, "$boss_fight not initialized");
|
||||||
|
|
||||||
if($boss_scene->playing()) {
|
if($boss_scene->playing()) {
|
||||||
if(ev == gui::Event::MOUSE_CLICK) {
|
if(ev == game::Event::MOUSE_CLICK) {
|
||||||
$boss_scene->mouse(0,0, 0);
|
$boss_scene->mouse(0,0, 0);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
@ -223,7 +223,7 @@ namespace gui {
|
||||||
|
|
||||||
$boss_fight->mouse_pos = mouse_position();
|
$boss_fight->mouse_pos = mouse_position();
|
||||||
|
|
||||||
if(ev == gui::Event::QUIT) {
|
if(ev == game::Event::QUIT) {
|
||||||
// just epsilon straight to the exit
|
// just epsilon straight to the exit
|
||||||
IDLE(ev, data);
|
IDLE(ev, data);
|
||||||
} if($boss_fight->event(ev, data)) {
|
} if($boss_fight->event(ev, data)) {
|
||||||
|
|
@ -260,7 +260,7 @@ namespace gui {
|
||||||
$main_ui.plan_rotate(1, DEFAULT_ROTATE);
|
$main_ui.plan_rotate(1, DEFAULT_ROTATE);
|
||||||
state(State::COMBAT_ROTATE);
|
state(State::COMBAT_ROTATE);
|
||||||
break;
|
break;
|
||||||
case STOP_COMBAT:
|
case COMBAT_STOP:
|
||||||
$main_ui.$overlay_ui.close_sprite("top_right");
|
$main_ui.$overlay_ui.close_sprite("top_right");
|
||||||
state(State::IDLE);
|
state(State::IDLE);
|
||||||
break;
|
break;
|
||||||
|
|
@ -436,7 +436,7 @@ namespace gui {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FSM::handle_world_events() {
|
void FSM::handle_world_events() {
|
||||||
using eGUI = Events::GUI;
|
using eGUI = game::Event;
|
||||||
auto world = GameDB::current_world();
|
auto world = GameDB::current_world();
|
||||||
|
|
||||||
while(world->has_event<eGUI>()) {
|
while(world->has_event<eGUI>()) {
|
||||||
|
|
@ -447,7 +447,7 @@ namespace gui {
|
||||||
|
|
||||||
switch(evt) {
|
switch(evt) {
|
||||||
case eGUI::COMBAT: {
|
case eGUI::COMBAT: {
|
||||||
auto &damage = std::any_cast<Events::Combat&>(data);
|
auto &damage = std::any_cast<components::CombatResult&>(data);
|
||||||
|
|
||||||
if(damage.enemy_did > 0) {
|
if(damage.enemy_did > 0) {
|
||||||
$map_ui.log(fmt::format(L"Enemy HIT YOU for {} damage!", damage.enemy_did));
|
$map_ui.log(fmt::format(L"Enemy HIT YOU for {} damage!", damage.enemy_did));
|
||||||
|
|
@ -463,7 +463,7 @@ namespace gui {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case eGUI::COMBAT_START:
|
case eGUI::COMBAT_START:
|
||||||
event(Event::START_COMBAT);
|
event(Event::COMBAT_START);
|
||||||
break;
|
break;
|
||||||
case eGUI::ENTITY_SPAWN: {
|
case eGUI::ENTITY_SPAWN: {
|
||||||
auto& sprite = world->get<components::Sprite>(entity);
|
auto& sprite = world->get<components::Sprite>(entity);
|
||||||
|
|
@ -472,7 +472,7 @@ namespace gui {
|
||||||
run_systems();
|
run_systems();
|
||||||
} break;
|
} break;
|
||||||
case eGUI::NO_NEIGHBORS:
|
case eGUI::NO_NEIGHBORS:
|
||||||
event(Event::STOP_COMBAT);
|
event(Event::COMBAT_STOP);
|
||||||
break;
|
break;
|
||||||
case eGUI::LOOT_CLOSE:
|
case eGUI::LOOT_CLOSE:
|
||||||
// BUG: need to resolve GUI events vs. FSM events better
|
// BUG: need to resolve GUI events vs. FSM events better
|
||||||
|
|
|
||||||
27
gui/fsm.hpp
27
gui/fsm.hpp
|
|
@ -13,6 +13,7 @@
|
||||||
#include "gui/event_router.hpp"
|
#include "gui/event_router.hpp"
|
||||||
#include "gui/dnd_loot.hpp"
|
#include "gui/dnd_loot.hpp"
|
||||||
#include "storyboard/ui.hpp"
|
#include "storyboard/ui.hpp"
|
||||||
|
#include "events.hpp"
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
enum class State {
|
enum class State {
|
||||||
|
|
@ -28,7 +29,7 @@ namespace gui {
|
||||||
END=9
|
END=9
|
||||||
};
|
};
|
||||||
|
|
||||||
class FSM : public DeadSimpleFSM<State, Event> {
|
class FSM : public DeadSimpleFSM<State, game::Event> {
|
||||||
public:
|
public:
|
||||||
sf::RenderWindow $window;
|
sf::RenderWindow $window;
|
||||||
bool $draw_stats = false;
|
bool $draw_stats = false;
|
||||||
|
|
@ -48,21 +49,21 @@ namespace gui {
|
||||||
|
|
||||||
FSM();
|
FSM();
|
||||||
|
|
||||||
void event(Event ev, std::any data={});
|
void event(game::Event ev, std::any data={});
|
||||||
void autowalk();
|
void autowalk();
|
||||||
void start_autowalk(double rot_speed);
|
void start_autowalk(double rot_speed);
|
||||||
|
|
||||||
void START(Event ev);
|
void START(game::Event ev);
|
||||||
void MOVING(Event ev);
|
void MOVING(game::Event ev);
|
||||||
void ATTACKING(Event ev, std::any data);
|
void ATTACKING(game::Event ev, std::any data);
|
||||||
void MAPPING(Event ev);
|
void MAPPING(game::Event ev);
|
||||||
void ROTATING(Event ev);
|
void ROTATING(game::Event ev);
|
||||||
void IDLE(Event ev, std::any data);
|
void IDLE(game::Event ev, std::any data);
|
||||||
void IN_COMBAT(Event ev);
|
void IN_COMBAT(game::Event ev);
|
||||||
void COMBAT_ROTATE(Event ev);
|
void COMBAT_ROTATE(game::Event ev);
|
||||||
void BOSS_FIGHT(Event ev, std::any data);
|
void BOSS_FIGHT(game::Event ev, std::any data);
|
||||||
void LOOTING(Event ev, std::any data);
|
void LOOTING(game::Event ev, std::any data);
|
||||||
void END(Event ev);
|
void END(game::Event ev);
|
||||||
|
|
||||||
void try_move(int dir, bool strafe);
|
void try_move(int dir, bool strafe);
|
||||||
sf::Vector2f mouse_position();
|
sf::Vector2f mouse_position();
|
||||||
|
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
namespace gui {
|
|
||||||
enum class Event {
|
|
||||||
STARTED=0,
|
|
||||||
TICK=1,
|
|
||||||
MOVE_FORWARD = 2,
|
|
||||||
MOVE_BACK = 3,
|
|
||||||
MOVE_LEFT = 4,
|
|
||||||
MOVE_RIGHT = 5,
|
|
||||||
MAP_OPEN = 6,
|
|
||||||
CLOSE = 7,
|
|
||||||
ROTATE_LEFT = 8,
|
|
||||||
ROTATE_RIGHT = 9,
|
|
||||||
ATTACK = 10,
|
|
||||||
START_COMBAT = 11,
|
|
||||||
STOP_COMBAT = 12,
|
|
||||||
BOSS_START = 13,
|
|
||||||
BOSS_END = 14,
|
|
||||||
LOOT_OPEN=15,
|
|
||||||
LOOT_ITEM=16,
|
|
||||||
LOOT_SELECT=17,
|
|
||||||
INV_SELECT=18,
|
|
||||||
USE_ITEM=19,
|
|
||||||
QUIT = 20,
|
|
||||||
MOUSE_CLICK=21,
|
|
||||||
MOUSE_MOVE=22,
|
|
||||||
MOUSE_DRAG=23,
|
|
||||||
MOUSE_DRAG_START=24,
|
|
||||||
MOUSE_DROP=25,
|
|
||||||
KEY_PRESS=26,
|
|
||||||
AIM_CLICK=27,
|
|
||||||
COMBAT=28
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
@ -3,17 +3,17 @@
|
||||||
|
|
||||||
namespace guecs {
|
namespace guecs {
|
||||||
|
|
||||||
Clickable make_action(guecs::Entity gui_id, Events::GUI event) {
|
Clickable make_action(guecs::Entity gui_id, game::Event event) {
|
||||||
return {[&, gui_id, event](auto){
|
return {[&, gui_id, event](auto){
|
||||||
auto world = GameDB::current_world();
|
auto world = GameDB::current_world();
|
||||||
world->send<Events::GUI>(event, gui_id, {});
|
world->send<game::Event>(event, gui_id, {});
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
Clickable make_action(guecs::Entity gui_id, Events::GUI event, std::any data) {
|
Clickable make_action(guecs::Entity gui_id, game::Event event, std::any data) {
|
||||||
return {[&, event, data](auto){
|
return {[&, event, data](auto){
|
||||||
auto world = GameDB::current_world();
|
auto world = GameDB::current_world();
|
||||||
world->send<Events::GUI>(event, gui_id, data);
|
world->send<game::Event>(event, gui_id, data);
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
#include "textures.hpp"
|
#include "textures.hpp"
|
||||||
|
|
||||||
namespace guecs {
|
namespace guecs {
|
||||||
Clickable make_action(guecs::Entity gui_id, Events::GUI event);
|
Clickable make_action(guecs::Entity gui_id, game::Event event);
|
||||||
Clickable make_action(guecs::Entity gui_id, Events::GUI event, std::any data);
|
Clickable make_action(guecs::Entity gui_id, game::Event event, std::any data);
|
||||||
|
|
||||||
struct GrabSource {
|
struct GrabSource {
|
||||||
DinkyECS::Entity world_entity;
|
DinkyECS::Entity world_entity;
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ namespace gui {
|
||||||
world->make_constant($temp_loot);
|
world->make_constant($temp_loot);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LootUI::make_button(const std::string &name, const std::wstring& label, Events::GUI event) {
|
void LootUI::make_button(const std::string &name, const std::wstring& label, game::Event event) {
|
||||||
|
|
||||||
auto button = $gui.entity(name);
|
auto button = $gui.entity(name);
|
||||||
$gui.set<guecs::Rectangle>(button, {});
|
$gui.set<guecs::Rectangle>(button, {});
|
||||||
|
|
@ -41,9 +41,9 @@ namespace gui {
|
||||||
bg_color.a = 140;
|
bg_color.a = 140;
|
||||||
$gui.set<Background>($gui.MAIN, {$gui.$parser, bg_color});
|
$gui.set<Background>($gui.MAIN, {$gui.$parser, bg_color});
|
||||||
|
|
||||||
make_button("close", L"CLOSE", Events::GUI::LOOT_CLOSE);
|
make_button("close", L"CLOSE", game::Event::LOOT_CLOSE);
|
||||||
make_button("take_all", L"TAKE ALL", Events::GUI::LOOT_CLOSE);
|
make_button("take_all", L"TAKE ALL", game::Event::LOOT_CLOSE);
|
||||||
make_button("destroy", L"DESTROY", Events::GUI::LOOT_CLOSE);
|
make_button("destroy", L"DESTROY", game::Event::LOOT_CLOSE);
|
||||||
|
|
||||||
for(int i = 0; i < INV_SLOTS; i++) {
|
for(int i = 0; i < INV_SLOTS; i++) {
|
||||||
auto name = fmt::format("item_{}", i);
|
auto name = fmt::format("item_{}", i);
|
||||||
|
|
@ -53,7 +53,7 @@ namespace gui {
|
||||||
THEME.TRANSPARENT, THEME.LIGHT_MID });
|
THEME.TRANSPARENT, THEME.LIGHT_MID });
|
||||||
$gui.set<guecs::Effect>(id, {0.4f, "ui_shader"});
|
$gui.set<guecs::Effect>(id, {0.4f, "ui_shader"});
|
||||||
$gui.set<guecs::Clickable>(id, {
|
$gui.set<guecs::Clickable>(id, {
|
||||||
guecs::make_action(id, Events::GUI::LOOT_SELECT, {id})
|
guecs::make_action(id, game::Event::LOOT_SELECT, {id})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ namespace gui {
|
||||||
void render(sf::RenderWindow& window);
|
void render(sf::RenderWindow& window);
|
||||||
void update_level();
|
void update_level();
|
||||||
bool mouse(float x, float y, guecs::Modifiers mods);
|
bool mouse(float x, float y, guecs::Modifiers mods);
|
||||||
void make_button(const std::string &name, const std::wstring& label, Events::GUI event);
|
void make_button(const std::string &name, const std::wstring& label, game::Event event);
|
||||||
|
|
||||||
void remove_slot(guecs::Entity slot_id);
|
void remove_slot(guecs::Entity slot_id);
|
||||||
bool place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity);
|
bool place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity);
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ namespace gui {
|
||||||
gui.set<Clickable>(area, {
|
gui.set<Clickable>(area, {
|
||||||
[&](auto) {
|
[&](auto) {
|
||||||
auto world = GameDB::current_world();
|
auto world = GameDB::current_world();
|
||||||
world->send<Events::GUI>(Events::GUI::AIM_CLICK, area, {});
|
world->send<game::Event>(game::Event::AIM_CLICK, area, {});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -191,7 +191,7 @@ namespace gui {
|
||||||
auto ritual = $ritual_engine.finalize($craft_state);
|
auto ritual = $ritual_engine.finalize($craft_state);
|
||||||
auto& belt = world->get_the<::ritual::Belt>();
|
auto& belt = world->get_the<::ritual::Belt>();
|
||||||
belt.equip(belt.next(), ritual);
|
belt.equip(belt.next(), ritual);
|
||||||
world->send<Events::GUI>(Events::GUI::NEW_RITUAL, player, {});
|
world->send<game::Event>(game::Event::NEW_RITUAL, player, {});
|
||||||
blanket().consume_crafting();
|
blanket().consume_crafting();
|
||||||
clear_craft_result();
|
clear_craft_result();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ namespace gui {
|
||||||
} else {
|
} else {
|
||||||
$gui.set<Text>(gui_id, {guecs::to_wstring(name)});
|
$gui.set<Text>(gui_id, {guecs::to_wstring(name)});
|
||||||
$gui.set<Clickable>(gui_id, {
|
$gui.set<Clickable>(gui_id, {
|
||||||
guecs::make_action(gui_id, Events::GUI::INV_SELECT, {gui_id})
|
guecs::make_action(gui_id, game::Event::INV_SELECT, {gui_id})
|
||||||
});
|
});
|
||||||
$gui.set<DropTarget>(gui_id, {
|
$gui.set<DropTarget>(gui_id, {
|
||||||
.commit=[&, gui_id](DinkyECS::Entity world_target) -> bool {
|
.commit=[&, gui_id](DinkyECS::Entity world_target) -> bool {
|
||||||
|
|
|
||||||
4
main.cpp
4
main.cpp
|
|
@ -23,7 +23,7 @@ int main(int argc, char* argv[]) {
|
||||||
sound::mute(true);
|
sound::mute(true);
|
||||||
|
|
||||||
gui::FSM main;
|
gui::FSM main;
|
||||||
main.event(gui::Event::STARTED);
|
main.event(game::Event::START);
|
||||||
Autowalker walker(main);
|
Autowalker walker(main);
|
||||||
|
|
||||||
sound::play("ambient_1", true);
|
sound::play("ambient_1", true);
|
||||||
|
|
@ -47,7 +47,7 @@ int main(int argc, char* argv[]) {
|
||||||
main.handle_keyboard_mouse();
|
main.handle_keyboard_mouse();
|
||||||
}
|
}
|
||||||
} else{
|
} else{
|
||||||
main.event(gui::Event::TICK);
|
main.event(game::Event::TICK);
|
||||||
}
|
}
|
||||||
|
|
||||||
main.handle_world_events();
|
main.handle_world_events();
|
||||||
|
|
|
||||||
30
systems.cpp
30
systems.cpp
|
|
@ -17,7 +17,7 @@
|
||||||
#include "shaders.hpp"
|
#include "shaders.hpp"
|
||||||
#include "inventory.hpp"
|
#include "inventory.hpp"
|
||||||
#include "game_level.hpp"
|
#include "game_level.hpp"
|
||||||
#include "gui/fsm_events.hpp"
|
#include "events.hpp"
|
||||||
#include "animation.hpp"
|
#include "animation.hpp"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
@ -180,7 +180,7 @@ void System::distribute_loot(Position target_pos) {
|
||||||
}
|
}
|
||||||
|
|
||||||
set_position(world, *level.collision, loot_entity, target_pos);
|
set_position(world, *level.collision, loot_entity, target_pos);
|
||||||
level.world->send<Events::GUI>(Events::GUI::ENTITY_SPAWN, loot_entity, {});
|
level.world->send<game::Event>(game::Event::ENTITY_SPAWN, loot_entity, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
void System::death() {
|
void System::death() {
|
||||||
|
|
@ -198,7 +198,7 @@ void System::death() {
|
||||||
dead_things.push_back(ent);
|
dead_things.push_back(ent);
|
||||||
}
|
}
|
||||||
// we need to send this event for everything that dies
|
// we need to send this event for everything that dies
|
||||||
world.send<Events::GUI>(Events::GUI::DEATH, ent, {});
|
world.send<game::Event>(game::Event::DEATH, ent, {});
|
||||||
} else if(float(combat.hp) / float(combat.max_hp) < 0.5f) {
|
} else if(float(combat.hp) / float(combat.max_hp) < 0.5f) {
|
||||||
// if enemies are below 50% health they are marked with bad health
|
// if enemies are below 50% health they are marked with bad health
|
||||||
if(world.has<ai::EntityAI>(ent)) {
|
if(world.has<ai::EntityAI>(ent)) {
|
||||||
|
|
@ -262,7 +262,7 @@ void System::combat(int attack_id) {
|
||||||
while(auto act = battle.next()) {
|
while(auto act = battle.next()) {
|
||||||
auto [enemy, enemy_action, cost, host_state] = *act;
|
auto [enemy, enemy_action, cost, host_state] = *act;
|
||||||
|
|
||||||
Events::Combat result {
|
components::CombatResult result {
|
||||||
player_combat.attack(*enemy.combat), 0
|
player_combat.attack(*enemy.combat), 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -275,7 +275,7 @@ void System::combat(int attack_id) {
|
||||||
animation::animate_entity(world, enemy.entity);
|
animation::animate_entity(world, enemy.entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
world.send<Events::GUI>(Events::GUI::COMBAT, enemy.entity, result);
|
world.send<game::Event>(game::Event::COMBAT, enemy.entity, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -296,7 +296,7 @@ void System::collision() {
|
||||||
auto combat = world.get<Combat>(entity);
|
auto combat = world.get<Combat>(entity);
|
||||||
if(!combat.dead) {
|
if(!combat.dead) {
|
||||||
combat_count++;
|
combat_count++;
|
||||||
world.send<Events::GUI>(Events::GUI::COMBAT_START, entity, entity);
|
world.send<game::Event>(game::Event::COMBAT_START, entity, entity);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dbc::log(fmt::format("UNKNOWN COLLISION TYPE {}", entity));
|
dbc::log(fmt::format("UNKNOWN COLLISION TYPE {}", entity));
|
||||||
|
|
@ -305,7 +305,7 @@ void System::collision() {
|
||||||
|
|
||||||
if(combat_count == 0) {
|
if(combat_count == 0) {
|
||||||
// BUG: this is probably how we get stuck in combat
|
// BUG: this is probably how we get stuck in combat
|
||||||
world.send<Events::GUI>(Events::GUI::NO_NEIGHBORS, level.player, level.player);
|
world.send<game::Event>(game::Event::NO_NEIGHBORS, level.player, level.player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -357,7 +357,7 @@ void System::pickup() {
|
||||||
// NOTE: chests are different from say a torch, maybe 2 events or the
|
// NOTE: chests are different from say a torch, maybe 2 events or the
|
||||||
// GUI figures out which it is, then when you click either pick it up
|
// GUI figures out which it is, then when you click either pick it up
|
||||||
// and move it or show the loot container UI
|
// and move it or show the loot container UI
|
||||||
world.send<Events::GUI>(Events::GUI::LOOT_ITEM, entity, entity);
|
world.send<game::Event>(game::Event::LOOT_ITEM, entity, entity);
|
||||||
}
|
}
|
||||||
} else if(world.has<Device>(entity)) {
|
} else if(world.has<Device>(entity)) {
|
||||||
System::device(world, level.player, entity);
|
System::device(world, level.player, entity);
|
||||||
|
|
@ -372,13 +372,13 @@ void System::device(World &world, Entity actor, Entity item) {
|
||||||
|
|
||||||
for(auto event : device.events) {
|
for(auto event : device.events) {
|
||||||
if(event == "STAIRS_DOWN") {
|
if(event == "STAIRS_DOWN") {
|
||||||
world.send<Events::GUI>(Events::GUI::STAIRS_DOWN, actor, device);
|
world.send<game::Event>(game::Event::STAIRS_DOWN, actor, device);
|
||||||
} else if(event == "STAIRS_UP") {
|
} else if(event == "STAIRS_UP") {
|
||||||
world.send<Events::GUI>(Events::GUI::STAIRS_UP, actor, device);
|
world.send<game::Event>(game::Event::STAIRS_UP, actor, device);
|
||||||
} else if(event == "TRAP") {
|
} else if(event == "TRAP") {
|
||||||
world.send<Events::GUI>(Events::GUI::TRAP, actor, device);
|
world.send<game::Event>(game::Event::TRAP, actor, device);
|
||||||
} else if(event == "LOOT_CONTAINER") {
|
} else if(event == "LOOT_CONTAINER") {
|
||||||
world.send<Events::GUI>(Events::GUI::LOOT_CONTAINER, actor, device);
|
world.send<game::Event>(game::Event::LOOT_CONTAINER, actor, device);
|
||||||
} else {
|
} else {
|
||||||
dbc::log(fmt::format(
|
dbc::log(fmt::format(
|
||||||
"INVALID EVENT {} for device {}",
|
"INVALID EVENT {} for device {}",
|
||||||
|
|
@ -457,7 +457,7 @@ void System::drop_item(Entity item) {
|
||||||
set_position(world, *level.collision, item, drop_spot);
|
set_position(world, *level.collision, item, drop_spot);
|
||||||
|
|
||||||
level.world->not_constant(item);
|
level.world->not_constant(item);
|
||||||
level.world->send<Events::GUI>(Events::GUI::ENTITY_SPAWN, item, {});
|
level.world->send<game::Event>(game::Event::ENTITY_SPAWN, item, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: I think pickup and this need to be different
|
// NOTE: I think pickup and this need to be different
|
||||||
|
|
@ -628,7 +628,7 @@ bool System::use_item(const string& slot_name) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gui::Event System::shortest_rotate(Point player_at, Point aiming_at, Point target) {
|
game::Event System::shortest_rotate(Point player_at, Point aiming_at, Point target) {
|
||||||
dbc::check(aiming_at != target, "you're already pointing there.");
|
dbc::check(aiming_at != target, "you're already pointing there.");
|
||||||
dbc::check(player_at != target, "you can't turn on yourself");
|
dbc::check(player_at != target, "you can't turn on yourself");
|
||||||
|
|
||||||
|
|
@ -643,7 +643,7 @@ gui::Event System::shortest_rotate(Point player_at, Point aiming_at, Point targe
|
||||||
float diff = target_angle - aiming_angle;
|
float diff = target_angle - aiming_angle;
|
||||||
double normalized = fmod(diff + 360.0, 360.0);
|
double normalized = fmod(diff + 360.0, 360.0);
|
||||||
|
|
||||||
return normalized < 180.0 ? gui::Event::ROTATE_LEFT : gui::Event::ROTATE_RIGHT;
|
return normalized < 180.0 ? game::Event::ROTATE_LEFT : game::Event::ROTATE_RIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void System::clear_attack() {
|
void System::clear_attack() {
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,6 @@
|
||||||
#include "spatialmap.hpp"
|
#include "spatialmap.hpp"
|
||||||
#include "game_level.hpp"
|
#include "game_level.hpp"
|
||||||
|
|
||||||
namespace gui {
|
|
||||||
enum class Event;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace System {
|
namespace System {
|
||||||
using namespace components;
|
using namespace components;
|
||||||
using namespace DinkyECS;
|
using namespace DinkyECS;
|
||||||
|
|
@ -49,7 +45,7 @@ namespace System {
|
||||||
void set_position(DinkyECS::World& world, SpatialMap& collision, Entity entity, Position pos);
|
void set_position(DinkyECS::World& world, SpatialMap& collision, Entity entity, Position pos);
|
||||||
bool use_item(const std::string& slot_name);
|
bool use_item(const std::string& slot_name);
|
||||||
|
|
||||||
gui::Event shortest_rotate(Point player_at, Point aiming_at, Point turning_to);
|
game::Event shortest_rotate(Point player_at, Point aiming_at, Point turning_to);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void multi_path(GameDB::Level& level, Pathing& paths, Matrix& walls) {
|
void multi_path(GameDB::Level& level, Pathing& paths, Matrix& walls) {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@
|
||||||
#include "backend.hpp"
|
#include "backend.hpp"
|
||||||
#include "game_level.hpp"
|
#include "game_level.hpp"
|
||||||
#include "boss/system.hpp"
|
#include "boss/system.hpp"
|
||||||
#include "gui/fsm_events.hpp"
|
|
||||||
#include "events.hpp"
|
#include "events.hpp"
|
||||||
#include "constants.hpp"
|
#include "constants.hpp"
|
||||||
#include "gui/event_router.hpp"
|
#include "gui/event_router.hpp"
|
||||||
|
|
@ -55,16 +54,16 @@ int main(int, char*[]) {
|
||||||
while(const auto ev = window.pollEvent()) {
|
while(const auto ev = window.pollEvent()) {
|
||||||
auto gui_ev = router.process_event(ev);
|
auto gui_ev = router.process_event(ev);
|
||||||
|
|
||||||
if(gui_ev == gui::Event::QUIT || main->event(gui_ev, {})) {
|
if(gui_ev == game::Event::QUIT || main->event(gui_ev, {})) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
main->event(gui::Event::TICK, {});
|
main->event(game::Event::TICK, {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(main->$world->has_event<Events::GUI>()) {
|
if(main->$world->has_event<game::Event>()) {
|
||||||
main->handle_world_events();
|
main->handle_world_events();
|
||||||
dbc::check(!main->$world->has_event<Events::GUI>(), "You didn't eat all the events.");
|
dbc::check(!main->$world->has_event<game::Event>(), "You didn't eat all the events.");
|
||||||
}
|
}
|
||||||
|
|
||||||
main->render(window);
|
main->render(window);
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,9 @@ int main(int, char*[]) {
|
||||||
auto gui_ev = router.process_event(ev);
|
auto gui_ev = router.process_event(ev);
|
||||||
auto mouse_pos = window.mapPixelToCoords(router.position);
|
auto mouse_pos = window.mapPixelToCoords(router.position);
|
||||||
|
|
||||||
if(gui_ev == gui::Event::QUIT) {
|
if(gui_ev == game::Event::QUIT) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if(gui_ev == gui::Event::MOUSE_CLICK) {
|
} else if(gui_ev == game::Event::MOUSE_CLICK) {
|
||||||
main.mouse(mouse_pos.x, mouse_pos.y, guecs::NO_MODS);
|
main.mouse(mouse_pos.x, mouse_pos.y, guecs::NO_MODS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue