feat: add Activateable in Lightkeeper
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
#ifndef LIGHTKEEPER_ACTIVATABLE_H
|
||||
#define LIGHTKEEPER_ACTIVATABLE_H
|
||||
|
||||
#include <destrum/Event.h>
|
||||
#include <destrum/ObjectModel/Component.h>
|
||||
|
||||
class Activatable : public Component {
|
||||
public:
|
||||
void Activate(GameObject& instigator);
|
||||
|
||||
Event<GameObject&> OnActivated;
|
||||
|
||||
protected:
|
||||
Activatable(GameObject& parent, const std::string& name)
|
||||
: Component(parent, name) {}
|
||||
|
||||
virtual void OnActivate(GameObject& instigator) = 0;
|
||||
};
|
||||
|
||||
#endif // LIGHTKEEPER_ACTIVATABLE_H
|
||||
@@ -0,0 +1,50 @@
|
||||
#ifndef LIGHTKEEPER_DOOR_H
|
||||
#define LIGHTKEEPER_DOOR_H
|
||||
|
||||
#include <components/Activatable.h>
|
||||
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
class Door final : public Activatable {
|
||||
public:
|
||||
explicit Door(GameObject& parent);
|
||||
|
||||
std::string GetTypeName() const override { return "Door"; }
|
||||
|
||||
void Start() override;
|
||||
void Update(float dt) override;
|
||||
|
||||
nlohmann::json Serialize() const override;
|
||||
void Deserialize(const nlohmann::json& data) override;
|
||||
void ImGuiInspector() override;
|
||||
|
||||
void Open() { m_IsOpen = true; }
|
||||
void Close() { m_IsOpen = false; }
|
||||
void Toggle() { m_IsOpen = !m_IsOpen; }
|
||||
|
||||
[[nodiscard]] bool IsOpen() const { return m_IsOpen; }
|
||||
[[nodiscard]] float GetOpenAmount() const { return m_OpenAmount; }
|
||||
|
||||
void SetOpenOffset(const glm::vec3& offset) { m_OpenOffset = offset; }
|
||||
void SetOpenDuration(float seconds) { m_OpenDuration = seconds; }
|
||||
void SetToggleable(bool toggleable) { m_Toggleable = toggleable; }
|
||||
|
||||
protected:
|
||||
void OnActivate(GameObject& instigator) override;
|
||||
|
||||
private:
|
||||
[[nodiscard]] glm::vec3 GetOffsetFor(float openAmount) const;
|
||||
void ApplyPosition();
|
||||
|
||||
glm::vec3 m_OpenOffset{0.0f, -2.4f, 0.0f};
|
||||
float m_OpenDuration{1.0f};
|
||||
bool m_Toggleable{true};
|
||||
|
||||
bool m_IsOpen{false};
|
||||
float m_OpenAmount{0.0f};
|
||||
|
||||
glm::vec3 m_ClosedPosition{0.0f};
|
||||
bool m_Started{false};
|
||||
};
|
||||
|
||||
#endif // LIGHTKEEPER_DOOR_H
|
||||
@@ -1,12 +1,14 @@
|
||||
#ifndef LIGHTKEEPER_GAMECOMPONENTLIST_H
|
||||
#define LIGHTKEEPER_GAMECOMPONENTLIST_H
|
||||
|
||||
#include <components/Door.h>
|
||||
#include <components/FirstPersonController.h>
|
||||
#include <components/InteractableButton.h>
|
||||
#include <components/PrintComponent.h>
|
||||
#include <components/TriggerLoggerComponent.h>
|
||||
|
||||
#define LIGHTKEEPER_GAME_COMPONENTS(X) \
|
||||
X(Door) \
|
||||
X(FirstPersonController) \
|
||||
X(InteractableButton) \
|
||||
X(PrintComponent) \
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
#include <components/Interactable.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
#include <destrum/ObjectModel/ObjectId.h>
|
||||
|
||||
class InteractableButton final : public Interactable {
|
||||
public:
|
||||
@@ -21,11 +24,19 @@ public:
|
||||
[[nodiscard]] std::size_t GetColorIndex() const { return m_ColorIndex; }
|
||||
[[nodiscard]] int GetPressCount() const { return m_PressCount; }
|
||||
|
||||
// Every Activatable on a target object is activated when the button is pressed
|
||||
void AddTarget(const GameObject& target);
|
||||
void RemoveTarget(ObjectId target);
|
||||
[[nodiscard]] const std::vector<ObjectId>& GetTargets() const { return m_Targets; }
|
||||
|
||||
private:
|
||||
void ApplyColor();
|
||||
void ActivateTargets(GameObject& interactor);
|
||||
void DrawTargetsInspector();
|
||||
|
||||
std::size_t m_ColorIndex{0};
|
||||
int m_PressCount{0};
|
||||
std::vector<ObjectId> m_Targets;
|
||||
};
|
||||
|
||||
#endif // LIGHTKEEPER_INTERACTABLEBUTTON_H
|
||||
|
||||
Reference in New Issue
Block a user