aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces')
-rw-r--r--src/interfaces/command.hpp9
-rw-r--r--src/interfaces/game.hpp11
-rw-r--r--src/interfaces/input.hpp8
-rw-r--r--src/interfaces/observable.hpp8
4 files changed, 31 insertions, 5 deletions
diff --git a/src/interfaces/command.hpp b/src/interfaces/command.hpp
new file mode 100644
index 0000000..245bdd6
--- /dev/null
+++ b/src/interfaces/command.hpp
@@ -0,0 +1,9 @@
+#pragma once
+
+class ICommand
+{
+public:
+ virtual ~ICommand() = default;
+
+ virtual void execute() noexcept = 0;
+};
diff --git a/src/interfaces/game.hpp b/src/interfaces/game.hpp
index 3f9d735..cfff8c5 100644
--- a/src/interfaces/game.hpp
+++ b/src/interfaces/game.hpp
@@ -1,6 +1,12 @@
#pragma once
+#include "interfaces/command.hpp"
+#include "interfaces/cursor.hpp"
+#include "interfaces/scene.hpp"
+#include "interfaces/window.hpp"
+
#include <memory>
+#include <unordered_map>
class IGame
{
@@ -8,6 +14,11 @@ public:
virtual ~IGame() = default;
virtual void run() = 0;
+
+ [[nodiscard]] virtual std::unordered_map<char, std::shared_ptr<ICommand>>
+ get_input_config(
+ const std::shared_ptr<IWindow> &window, const std::shared_ptr<IScene> &scene,
+ const std::shared_ptr<ICursorController> &cursor_controller) const noexcept = 0;
};
using IGameFactory = std::shared_ptr<IGame> (*)();
diff --git a/src/interfaces/input.hpp b/src/interfaces/input.hpp
index b243a16..82ad57c 100644
--- a/src/interfaces/input.hpp
+++ b/src/interfaces/input.hpp
@@ -1,7 +1,10 @@
#pragma once
+#include "interfaces/command.hpp"
#include "interfaces/observable.hpp"
+#include <memory>
+
class IInputHandler : public IObservable<char>
{
public:
@@ -9,9 +12,10 @@ public:
void listen() const noexcept override = 0;
- void attach(const char &event, Callback callback) noexcept override = 0;
+ void attach(const char &key,
+ const std::shared_ptr<ICommand> &command) noexcept override = 0;
- void notify(const char &event) const noexcept override = 0;
+ void notify(const char &key) const noexcept override = 0;
virtual void enter_raw_mode() noexcept = 0;
diff --git a/src/interfaces/observable.hpp b/src/interfaces/observable.hpp
index 1777b7d..21fed76 100644
--- a/src/interfaces/observable.hpp
+++ b/src/interfaces/observable.hpp
@@ -1,8 +1,9 @@
#pragma once
-#include <functional>
+#include "interfaces/command.hpp"
-using Callback = std::function<void()>;
+#include <functional>
+#include <memory>
template <typename Event>
class IObservable
@@ -12,7 +13,8 @@ public:
virtual void listen() const noexcept = 0;
- virtual void attach(const Event &event, Callback callback) noexcept = 0;
+ virtual void attach(const char &event,
+ const std::shared_ptr<ICommand> &command) noexcept = 0;
virtual void notify(const Event &event) const noexcept = 0;
};