From 78f5d8cf644383adf20933ad64c160c07c2c54fb Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 20 Mar 2022 13:17:16 +0100 Subject: refactor: improve input configuring structure --- src/interfaces/command.hpp | 9 +++++++++ src/interfaces/game.hpp | 11 +++++++++++ src/interfaces/input.hpp | 8 ++++++-- src/interfaces/observable.hpp | 8 +++++--- 4 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 src/interfaces/command.hpp (limited to 'src/interfaces') 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 +#include class IGame { @@ -8,6 +14,11 @@ public: virtual ~IGame() = default; virtual void run() = 0; + + [[nodiscard]] virtual std::unordered_map> + get_input_config( + const std::shared_ptr &window, const std::shared_ptr &scene, + const std::shared_ptr &cursor_controller) const noexcept = 0; }; using IGameFactory = std::shared_ptr (*)(); 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 + class IInputHandler : public IObservable { 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 &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 +#include "interfaces/command.hpp" -using Callback = std::function; +#include +#include template 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 &command) noexcept = 0; virtual void notify(const Event &event) const noexcept = 0; }; -- cgit v1.2.3-18-g5258