diff options
author | HampusM <hampus@hampusmat.com> | 2022-03-08 17:00:18 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:56:55 +0200 |
commit | e0eaff89b5f3f289bf5d560ea64b969c90d32d18 (patch) | |
tree | a6e91afcf89abc91629f2bee545ccadacf9bb673 /src | |
parent | 3359b00178357cb68d14e807c6deef3182532307 (diff) |
refactor: add cursor controller interface
Diffstat (limited to 'src')
-rw-r--r-- | src/bootstrap.cpp | 3 | ||||
-rw-r--r-- | src/engine/user/cursor.hpp | 10 | ||||
-rw-r--r-- | src/game/input_configurator.cpp | 4 | ||||
-rw-r--r-- | src/game/input_configurator.hpp | 10 | ||||
-rw-r--r-- | src/interfaces/cursor.hpp | 17 |
5 files changed, 32 insertions, 12 deletions
diff --git a/src/bootstrap.cpp b/src/bootstrap.cpp index 610945f..2e64986 100644 --- a/src/bootstrap.cpp +++ b/src/bootstrap.cpp @@ -2,6 +2,7 @@ // Interfaces #include "interfaces/argument_parser.hpp" +#include "interfaces/cursor.hpp" #include "interfaces/game.hpp" #include "interfaces/game_initializer.hpp" #include "interfaces/input.hpp" @@ -38,7 +39,7 @@ Container bootstrap() container.bind<IGame>().to<Game>(); container.bind<IScene>().to<Scene>(); container.bind<IInputHandler>().to<InputHandler>(); - container.bind<CursorController>().to<CursorController>(); + container.bind<ICursorController>().to<CursorController>(); container.bind<IGameInitializer>().to<GameInitializer>(); container.bind<IInputConfigurator>().to<InputConfigurator>(); diff --git a/src/engine/user/cursor.hpp b/src/engine/user/cursor.hpp index 50dd028..977bfdf 100644 --- a/src/engine/user/cursor.hpp +++ b/src/engine/user/cursor.hpp @@ -1,6 +1,7 @@ #pragma once #include "DI/auto_wirable.hpp" +#include "interfaces/cursor.hpp" #include "engine/data/vector2.hpp" @@ -28,20 +29,21 @@ const std::unordered_map<Vector2, std::string_view, Vector2Hasher> direction_for {Vector2::left(), MOVE_CURSOR_LEFT}, {Vector2::right(), MOVE_CURSOR_RIGHT}}; -class CursorController : public AutoWirable<CursorController, CursorController> +class CursorController : public ICursorController, + public AutoWirable<ICursorController, CursorController> { public: CursorController(); - void move(const Vector2 &direction, const uint32_t &amount) noexcept; + void move(const Vector2 &direction, const uint32_t &amount) noexcept override; - void move_to(const Vector2 &position) noexcept; + void move_to(const Vector2 &position) noexcept override; static void hide(); static void show(); - [[nodiscard]] Vector2 where() const noexcept; + [[nodiscard]] Vector2 where() const noexcept override; private: Vector2 _position; diff --git a/src/game/input_configurator.cpp b/src/game/input_configurator.cpp index ea1ee75..76e5b66 100644 --- a/src/game/input_configurator.cpp +++ b/src/game/input_configurator.cpp @@ -8,7 +8,7 @@ void exit_success() exit(EXIT_SUCCESS); } -auto move_cursor(const Vector2 &direction, CursorController &cursor_controller) +auto move_cursor(const Vector2 &direction, ICursorController &cursor_controller) { return [direction, &cursor_controller]() { @@ -18,7 +18,7 @@ auto move_cursor(const Vector2 &direction, CursorController &cursor_controller) } // namespace InputActions -InputConfigurator::InputConfigurator(std::shared_ptr<CursorController> cursor_controller) +InputConfigurator::InputConfigurator(std::shared_ptr<ICursorController> cursor_controller) : _cursor_controller(std::move(cursor_controller)) { } diff --git a/src/game/input_configurator.hpp b/src/game/input_configurator.hpp index 8e5b9bf..fa501c7 100644 --- a/src/game/input_configurator.hpp +++ b/src/game/input_configurator.hpp @@ -1,11 +1,11 @@ #pragma once #include "DI/auto_wirable.hpp" +#include "interfaces/cursor.hpp" #include "interfaces/input.hpp" #include "interfaces/input_configurator.hpp" #include "engine/data/vector2.hpp" -#include "engine/user/cursor.hpp" #include <array> #include <memory> @@ -13,7 +13,7 @@ namespace InputActions { -auto move_cursor(const Vector2 &direction, CursorController &cursor_controller); +auto move_cursor(const Vector2 &direction, ICursorController &cursor_controller); void exit_success(); @@ -21,13 +21,13 @@ void exit_success(); class InputConfigurator : public IInputConfigurator, - public AutoWirable<IInputConfigurator, InputConfigurator, CursorController> + public AutoWirable<IInputConfigurator, InputConfigurator, ICursorController> { public: - explicit InputConfigurator(std::shared_ptr<CursorController> cursor_controller); + explicit InputConfigurator(std::shared_ptr<ICursorController> cursor_controller); void configure(IInputHandler &input_handler) override; private: - std::shared_ptr<CursorController> _cursor_controller; + std::shared_ptr<ICursorController> _cursor_controller; }; diff --git a/src/interfaces/cursor.hpp b/src/interfaces/cursor.hpp new file mode 100644 index 0000000..adab524 --- /dev/null +++ b/src/interfaces/cursor.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include "engine/data/vector2.hpp" + +class ICursorController +{ +public: + virtual void move(const Vector2 &direction, const uint32_t &amount) noexcept = 0; + + virtual void move_to(const Vector2 &position) noexcept = 0; + + [[nodiscard]] virtual Vector2 where() const noexcept = 0; + + static void hide(); + + static void show(); +}; |