Using an event for the device interaction is better. If I get to where there's tons of devices then I'll rethink it but right now this is less convoluted.
parent
8defc0bedf
commit
e63a8dd920
@ -1,19 +1,22 @@ |
|||||||
#include "devices.hpp" |
#include "devices.hpp" |
||||||
#include "events.hpp" |
#include "events.hpp" |
||||||
|
#include "dbc.hpp" |
||||||
|
|
||||||
namespace components { |
namespace components { |
||||||
void StairsDown(DinkyECS::Entity player_ent, json &, DinkyECS::World &world) { |
|
||||||
world.send<Events::GUI>(Events::GUI::STAIRS, player_ent, {}); |
|
||||||
} |
|
||||||
|
|
||||||
void StairsUp(DinkyECS::Entity player_ent, json &, DinkyECS::World &world) { |
|
||||||
|
|
||||||
world.send<Events::GUI>(Events::GUI::STAIRS, player_ent, {}); |
/*
|
||||||
|
* Note: This should go away or at least the event names to |
||||||
|
* numbers should probably be automatically created. |
||||||
|
*/ |
||||||
|
void Device::configure_events(json &event_names) { |
||||||
|
for(string name : event_names) { |
||||||
|
if(name == "Events::GUI::STAIRS_DOWN") { |
||||||
|
events.push_back(Events::GUI::STAIRS_DOWN); |
||||||
|
} else if(name == "Events::GUI::STAIRS_UP") { |
||||||
|
events.push_back(Events::GUI::STAIRS_UP); |
||||||
|
} else { |
||||||
|
dbc::sentinel(fmt::format("Unknown device event {}", name)); |
||||||
} |
} |
||||||
|
|
||||||
void Device::hit(DinkyECS::Entity ent, DinkyECS::World &world) { |
|
||||||
for(auto& action : actions) { |
|
||||||
action(ent, config, world); |
|
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue