From f0824fdebc79fbf3843c2053522107c33e3ce2a3 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 7 Mar 2022 20:20:18 +0100 Subject: refactor: move directions to vector2 & make vector2 hashable --- src/game/input_configurator.cpp | 16 ++++++++++++---- src/game/input_configurator.hpp | 7 ++----- src/game/input_configurator.tpp | 17 ----------------- 3 files changed, 14 insertions(+), 26 deletions(-) delete mode 100644 src/game/input_configurator.tpp (limited to 'src/game') diff --git a/src/game/input_configurator.cpp b/src/game/input_configurator.cpp index 4daee21..e8d2fe5 100644 --- a/src/game/input_configurator.cpp +++ b/src/game/input_configurator.cpp @@ -8,6 +8,14 @@ void exit_success() exit(EXIT_SUCCESS); } +auto move_cursor(const Vector2 &direction, const CursorController &cursor_controller) +{ + return [direction, cursor_controller]() + { + cursor_controller.move(direction, 1U); + }; +} + } // namespace InputActions InputConfigurator::InputConfigurator(std::shared_ptr cursor_controller) @@ -20,14 +28,14 @@ void InputConfigurator::configure(IInputHandler &input_handler) input_handler.attach('q', InputActions::exit_success); input_handler.attach('k', - InputActions::move_cursor(*_cursor_controller)); + InputActions::move_cursor(Vector2::up(), *_cursor_controller)); input_handler.attach('j', - InputActions::move_cursor(*_cursor_controller)); + InputActions::move_cursor(Vector2::down(), *_cursor_controller)); input_handler.attach('h', - InputActions::move_cursor(*_cursor_controller)); + InputActions::move_cursor(Vector2::left(), *_cursor_controller)); input_handler.attach( - 'l', InputActions::move_cursor(*_cursor_controller)); + 'l', InputActions::move_cursor(Vector2::right(), *_cursor_controller)); } diff --git a/src/game/input_configurator.hpp b/src/game/input_configurator.hpp index 217c21e..3846d50 100644 --- a/src/game/input_configurator.hpp +++ b/src/game/input_configurator.hpp @@ -1,10 +1,10 @@ #pragma once #include "DI/auto_wirable.hpp" -#include "interfaces/direction.hpp" #include "interfaces/input.hpp" #include "interfaces/input_configurator.hpp" +#include "engine/data/vector2.hpp" #include "engine/user/cursor.hpp" #include @@ -13,8 +13,7 @@ namespace InputActions { -template -auto move_cursor(CursorController cursor_controller); +auto move_cursor(const Vector2 &direction, const CursorController &cursor_controller); void exit_success(); @@ -32,5 +31,3 @@ public: private: std::shared_ptr _cursor_controller; }; - -#include "input_configurator.tpp" diff --git a/src/game/input_configurator.tpp b/src/game/input_configurator.tpp deleted file mode 100644 index f3c9482..0000000 --- a/src/game/input_configurator.tpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "input_configurator.hpp" - -namespace InputActions -{ - -template -auto move_cursor(CursorController cursor_controller) -{ - return [cursor_controller]() - { - cursor_controller.move(1U); - }; -} - -} // namespace InputActions -- cgit v1.2.3-18-g5258