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.
This commit is contained in:
parent
8defc0bedf
commit
e63a8dd920
8 changed files with 46 additions and 45 deletions
25
devices.cpp
25
devices.cpp
|
@ -1,19 +1,22 @@
|
|||
#include "devices.hpp"
|
||||
#include "events.hpp"
|
||||
#include "dbc.hpp"
|
||||
|
||||
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, {});
|
||||
}
|
||||
|
||||
void Device::hit(DinkyECS::Entity ent, DinkyECS::World &world) {
|
||||
for(auto& action : actions) {
|
||||
action(ent, config, world);
|
||||
/*
|
||||
* 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue