62 lines
2.2 KiB
C++
62 lines
2.2 KiB
C++
#ifndef __PATHMOVEMENTSWITCHSYSTEM_H__
|
|
#define __PATHMOVEMENTSWITCHSYSTEM_H__
|
|
|
|
#include <GLFW/glfw3.h>
|
|
#include <glad/glad.h>
|
|
|
|
#include <iostream>
|
|
|
|
#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<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__
|