aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-03-20 20:37:43 +0100
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:57 +0200
commit1972939ebde39a3e90a50b021b2322d028f344de (patch)
tree9ee0a7c78f082bec084189906f28dc679a20d339 /src/interfaces
parente6644d6b235005de9ba1b9884472fa5f5d8d6074 (diff)
refactor: move updating status from the move cursor command
Diffstat (limited to 'src/interfaces')
-rw-r--r--src/interfaces/command.hpp2
-rw-r--r--src/interfaces/cursor.hpp25
-rw-r--r--src/interfaces/subscriber.hpp2
3 files changed, 25 insertions, 4 deletions
diff --git a/src/interfaces/command.hpp b/src/interfaces/command.hpp
index 62d7a59..6220af1 100644
--- a/src/interfaces/command.hpp
+++ b/src/interfaces/command.hpp
@@ -7,7 +7,7 @@
class ICommand : public ISubscriber<std::nullptr_t>
{
public:
- virtual ~ICommand() = default;
+ ~ICommand() override = default;
virtual void execute() noexcept = 0;
diff --git a/src/interfaces/cursor.hpp b/src/interfaces/cursor.hpp
index 77c5096..ec2f60c 100644
--- a/src/interfaces/cursor.hpp
+++ b/src/interfaces/cursor.hpp
@@ -1,17 +1,30 @@
#pragma once
+#include "interfaces/publisher.hpp"
+#include "interfaces/subscriber.hpp"
+
#include "engine/data/vector2.hpp"
#include <memory>
-class ICursorController
+enum CursorEvent
+{
+ POSITION_CHANGE
+};
+
+class ICursorController : public IPublisher<CursorEvent, Vector2>
{
public:
- virtual ~ICursorController() noexcept = default;
+ using Event = CursorEvent;
+ using Context = Vector2;
+ using Subscriber = std::shared_ptr<ISubscriber<Context>>;
+
+ ~ICursorController() noexcept override = default;
virtual void move(const Vector2 &direction, const uint32_t &amount) noexcept = 0;
- virtual void move_to(const Vector2 &position) noexcept = 0;
+ // NOLINTNEXTLINE(google-default-arguments)
+ virtual void move_to(const Vector2 &position, bool silent = false) noexcept = 0;
[[nodiscard]] virtual Vector2 where() const noexcept = 0;
@@ -20,4 +33,10 @@ public:
static void hide() noexcept;
static void show() noexcept;
+
+ void subscribe(const Event &event,
+ const Subscriber &subscriber) noexcept override = 0;
+
+ void notify_subscribers(const Event &event,
+ const Context &context) const noexcept override = 0;
};
diff --git a/src/interfaces/subscriber.hpp b/src/interfaces/subscriber.hpp
index 17d87ef..6641be7 100644
--- a/src/interfaces/subscriber.hpp
+++ b/src/interfaces/subscriber.hpp
@@ -4,5 +4,7 @@ template <typename Context>
class ISubscriber
{
public:
+ virtual ~ISubscriber() = default;
+
virtual void update(const Context &context) noexcept = 0;
};