The PathMovementSwitchSystem was repurposed to a general InteractivePathSystem for this. It handles switching and adding points, as both seem like sensible possibilities for such entities to have.
59 lines
2.1 KiB
C++
59 lines
2.1 KiB
C++
#ifndef __PATHMOVEMENTSWITCHSYSTEM_H__
|
|
#define __PATHMOVEMENTSWITCHSYSTEM_H__
|
|
|
|
#include <glad/glad.h>
|
|
#include <GLFW/glfw3.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include "../ECS.h"
|
|
#include "../Components/PathMove.h"
|
|
#include "../Events/InputEvent.h"
|
|
#include "../Components/Movement.h"
|
|
#include "../Components/MouseLook.h"
|
|
|
|
using namespace ECS;
|
|
|
|
class InteractivePathSystem : public EntitySystem, public EventSubscriber<InputEvent> {
|
|
void configure(World *pWorld) override {
|
|
myWorld = pWorld;
|
|
|
|
myWorld->subscribe<InputEvent>(this);
|
|
}
|
|
|
|
void receive(World *pWorld, const InputEvent &event) override {
|
|
if (event.key == GLFW_KEY_P) {
|
|
myWorld->each<PathMove, Movement, MouseLook>([&](Entity *ent, ComponentHandle<PathMove> pathmove, ComponentHandle<Movement> movement, ComponentHandle<MouseLook> 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<PathMove, Movement, MouseLook, Transform>([&](Entity *ent, ComponentHandle<PathMove> pathmove, ComponentHandle<Movement> movement, ComponentHandle<MouseLook> mouselook, ComponentHandle<Transform> 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__
|