From b74611d2b20fc071b8a699f2ce25e61f60118d6e Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 22 May 2022 23:13:29 +0200 Subject: refactor: improve input handling & remove commands --- src/interfaces/game.hpp | 8 +++----- src/interfaces/input.hpp | 20 ++++++-------------- src/interfaces/statusline.hpp | 3 ++- 3 files changed, 11 insertions(+), 20 deletions(-) (limited to 'src/interfaces') diff --git a/src/interfaces/game.hpp b/src/interfaces/game.hpp index a54782a..3aac6a9 100644 --- a/src/interfaces/game.hpp +++ b/src/interfaces/game.hpp @@ -2,12 +2,12 @@ #include "interfaces/command.hpp" #include "interfaces/cursor.hpp" +#include "interfaces/input.hpp" #include "interfaces/scene.hpp" #include #include -#include // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) class IGame @@ -20,11 +20,9 @@ public: virtual void on_update() noexcept = 0; virtual void on_exit() const noexcept = 0; - - [[nodiscard]] virtual auto get_input_config() const noexcept - -> std::unordered_map> = 0; }; using IGameFactory = yacppdic::Factory( const std::shared_ptr &scene, - const std::shared_ptr &cursor_controller)>; + const std::shared_ptr &cursor_controller, + const std::shared_ptr user_input_observer)>; diff --git a/src/interfaces/input.hpp b/src/interfaces/input.hpp index f93a8e2..8239e48 100644 --- a/src/interfaces/input.hpp +++ b/src/interfaces/input.hpp @@ -7,24 +7,16 @@ #include // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) -class IInputHandler : public IPublisher +class IUserInputObserver { public: - using Event = char; - using Context = std::nullptr_t; + using Key = char; - ~IInputHandler() noexcept override = default; + virtual ~IUserInputObserver() noexcept = default; - virtual void listen() const noexcept = 0; + virtual void listen() noexcept = 0; - void subscribe( - const Event &event, - const std::shared_ptr> &subscriber) noexcept override = 0; + virtual bool is_key_pressed(Key key) noexcept = 0; - void notify_subscribers(const Event &event, const Context &context) - const noexcept override = 0; - - virtual void enter_raw_mode() noexcept = 0; - - virtual void leave_raw_mode() noexcept = 0; + virtual void clear_currently_pressed() noexcept = 0; }; diff --git a/src/interfaces/statusline.hpp b/src/interfaces/statusline.hpp index 2e97ed6..c66a2d3 100644 --- a/src/interfaces/statusline.hpp +++ b/src/interfaces/statusline.hpp @@ -14,7 +14,8 @@ enum StatusLineSection C = 2, D = 3, E = 4, - F = 5 + F = 5, + G = 6 }; // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) -- cgit v1.2.3-18-g5258