#ifndef __PATHMOVEMENTSWITCHSYSTEM_H__ #define __PATHMOVEMENTSWITCHSYSTEM_H__ #include #include #include #include "../Components/MouseLook.h" #include "../Components/Movement.h" #include "../Components/PathMove.h" #include "../ECS.h" #include "../Events/InputEvent.h" using namespace ECS; class InteractivePathSystem : public EntitySystem, public EventSubscriber { void configure(World *pWorld) override { myWorld = pWorld; myWorld->subscribe(this); } void receive(World *pWorld, const InputEvent &event) override { if (event.key == GLFW_KEY_P) { myWorld->each( [&](Entity *ent, ComponentHandle pathmove, ComponentHandle movement, ComponentHandle mouselook) { if (event.action == GLFW_PRESS) { // Switch between them if (pathmove->is_active) { pathmove->is_active = false; movement->is_active = true; mouselook->is_active = true; } else { pathmove->is_active = true; movement->is_active = false; mouselook->is_active = false; } } }); } else if (event.key == GLFW_KEY_R) { myWorld->each( [&](Entity *ent, ComponentHandle pathmove, ComponentHandle movement, ComponentHandle mouselook, ComponentHandle transform) { if (event.action == GLFW_PRESS) { // Add this point to the path pathmove->path.add_point(transform->origin); pathmove->views.add_view(mouselook->rotation); } }); } } void unconfigure(World *pWorld) override { pWorld->unsubscribeAll(this); } private: World *myWorld; }; #endif // __PATHMOVEMENTSWITCHSYSTEM_H__