aboutsummaryrefslogtreecommitdiff
path: root/src/engine/engine.cpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-03-20 13:17:16 +0100
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:56 +0200
commit78f5d8cf644383adf20933ad64c160c07c2c54fb (patch)
tree2a348d90f8f150665c379bf2f3741731999dd679 /src/engine/engine.cpp
parentb6061eff99907495de282f611e8389e6468a1fb0 (diff)
refactor: improve input configuring structure
Diffstat (limited to 'src/engine/engine.cpp')
-rw-r--r--src/engine/engine.cpp37
1 files changed, 7 insertions, 30 deletions
diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp
index afa5924..b2add9c 100644
--- a/src/engine/engine.cpp
+++ b/src/engine/engine.cpp
@@ -1,6 +1,5 @@
#include "engine.hpp"
-#include "input_actions.hpp"
#include "strings.hpp"
#include "util/function.hpp"
@@ -58,45 +57,23 @@ void CLIGameEngine::start() noexcept
std::cout.flush();
}));
- const std::unordered_map<char, Callback> input_config = {
- {'q', InputActions::exit_success},
- {'i',
- [this, scene]()
- {
- const auto position = _cursor_controller->where();
-
- std::cout.put('x');
- std::cout.flush();
-
- _cursor_controller->move_to(position);
-
- auto matrix = scene->get_matrix();
-
- matrix->set(position - Vector2({.x = 0U, .y = 1U}), "#");
- }},
- {'k',
- InputActions::move_cursor(Vector2::up(), _cursor_controller, scene, _window)},
- {'j',
- InputActions::move_cursor(Vector2::down(), _cursor_controller, scene, _window)},
- {'h',
- InputActions::move_cursor(Vector2::left(), _cursor_controller, scene, _window)},
- {'l', InputActions::move_cursor(Vector2::right(), _cursor_controller, scene,
- _window)}};
+ auto game = _game_factory();
- _configure_input(input_config);
+ _configure_input(game->get_input_config(_window, scene, _cursor_controller));
_input_handler->listen();
- auto game = _game_factory();
-
game->run();
}
void CLIGameEngine::_configure_input(
- const std::unordered_map<char, Callback> &input_config) noexcept
+ const std::unordered_map<char, std::shared_ptr<ICommand>> &input_config) noexcept
{
for (const auto &config_pair : input_config)
{
- _input_handler->attach(config_pair.first, config_pair.second);
+ auto key = config_pair.first;
+ auto command = config_pair.second;
+
+ _input_handler->attach(key, command);
}
}