Event system now accepts any data and the GUI receives simpler events with data for them.
This commit is contained in:
parent
0e79288afc
commit
ed9d0de8e0
7 changed files with 45 additions and 57 deletions
|
@ -5,9 +5,10 @@
|
|||
|
||||
using namespace fmt;
|
||||
using DinkyECS::Entity;
|
||||
using std::string;
|
||||
|
||||
struct Player {
|
||||
std::string name;
|
||||
string name;
|
||||
Entity eid;
|
||||
};
|
||||
|
||||
|
@ -129,22 +130,18 @@ enum GUIEvent {
|
|||
|
||||
TEST_CASE("confirm that the event system works", "[ecs]") {
|
||||
DinkyECS::World world;
|
||||
DinkyECS::Entity gui_ent = world.entity();
|
||||
DinkyECS::Entity player = world.entity();
|
||||
GUIEvent gui{GUIEvent::HIT};
|
||||
|
||||
world.set<GUIEvent>(gui_ent, gui);
|
||||
auto &gui_test = world.get<GUIEvent>(gui_ent);
|
||||
REQUIRE(gui == gui_test);
|
||||
|
||||
world.send<GUIEvent>(GUIEvent::HIT, player);
|
||||
world.send<GUIEvent>(GUIEvent::HIT, player, string{"hello"});
|
||||
|
||||
bool ready = world.has_event<GUIEvent>();
|
||||
REQUIRE(ready == true);
|
||||
|
||||
auto [event, entity] = world.recv<GUIEvent>();
|
||||
auto [event, entity, data] = world.recv<GUIEvent>();
|
||||
REQUIRE(event == GUIEvent::HIT);
|
||||
REQUIRE(entity == player);
|
||||
auto &str_data = std::any_cast<string&>(data);
|
||||
REQUIRE(string{"hello"} == str_data);
|
||||
|
||||
ready = world.has_event<GUIEvent>();
|
||||
REQUIRE(ready == false);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue