diff options
author | HampusM <hampus@hampusmat.com> | 2022-05-22 23:13:29 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:56:59 +0200 |
commit | b74611d2b20fc071b8a699f2ce25e61f60118d6e (patch) | |
tree | 55d4dbf727724f7f527f2acebea83abd34317329 /src/commands | |
parent | b1183c712d94d38f75068bd62df006f73bd3550f (diff) |
refactor: improve input handling & remove commands
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/insert_cell.cpp | 24 | ||||
-rw-r--r-- | src/commands/insert_cell.hpp | 21 | ||||
-rw-r--r-- | src/commands/move_cursor.cpp | 27 | ||||
-rw-r--r-- | src/commands/move_cursor.hpp | 25 | ||||
-rw-r--r-- | src/commands/quit.cpp | 8 | ||||
-rw-r--r-- | src/commands/quit.hpp | 9 | ||||
-rw-r--r-- | src/commands/toggle_pause.cpp | 21 | ||||
-rw-r--r-- | src/commands/toggle_pause.hpp | 21 |
8 files changed, 0 insertions, 156 deletions
diff --git a/src/commands/insert_cell.cpp b/src/commands/insert_cell.cpp deleted file mode 100644 index 86a5a52..0000000 --- a/src/commands/insert_cell.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "insert_cell.hpp" - -#include <iostream> - -InsertCellCommand::InsertCellCommand( - const std::shared_ptr<ICursorController> &cursor_controller, - const std::shared_ptr<IScene> &scene) noexcept - : _cursor_controller(cursor_controller), _scene(scene) -{ -} - -void InsertCellCommand::execute() noexcept -{ - 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}), "#"); -} diff --git a/src/commands/insert_cell.hpp b/src/commands/insert_cell.hpp deleted file mode 100644 index 9d54736..0000000 --- a/src/commands/insert_cell.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "interfaces/command.hpp" -#include "interfaces/cursor.hpp" -#include "interfaces/scene.hpp" - -#include <memory> - -class InsertCellCommand : public ICommand -{ -public: - InsertCellCommand( - const std::shared_ptr<ICursorController> &cursor_controller, - const std::shared_ptr<IScene> &scene) noexcept; - - void execute() noexcept override; - -private: - const std::shared_ptr<ICursorController> &_cursor_controller; - const std::shared_ptr<IScene> &_scene; -}; diff --git a/src/commands/move_cursor.cpp b/src/commands/move_cursor.cpp deleted file mode 100644 index 6bd8eda..0000000 --- a/src/commands/move_cursor.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "move_cursor.hpp" - -MoveCursorCommand::MoveCursorCommand( - const Vector2 &direction, - const std::shared_ptr<ICursorController> &cursor_controller, - const std::shared_ptr<IScene> &scene) noexcept - : _direction(direction), _cursor_controller(cursor_controller), _scene(scene) - -{ -} - -void MoveCursorCommand::execute() noexcept -{ - constexpr int32_t amount = 1; - - const auto new_position = - _cursor_controller->where().to_direction(_direction, amount); - - const auto scene_size = _scene->size(); - - if (scene_size.validate_coords(new_position) != CoordsValidation::VALID) - { - return; - } - - _cursor_controller->move_to(new_position); -} diff --git a/src/commands/move_cursor.hpp b/src/commands/move_cursor.hpp deleted file mode 100644 index dc08c64..0000000 --- a/src/commands/move_cursor.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "interfaces/command.hpp" -#include "interfaces/cursor.hpp" -#include "interfaces/scene.hpp" - -#include "engine/data/vector2.hpp" - -#include <memory> - -class MoveCursorCommand : public ICommand -{ -public: - MoveCursorCommand( - const Vector2 &direction, - const std::shared_ptr<ICursorController> &cursor_controller, - const std::shared_ptr<IScene> &scene) noexcept; - - void execute() noexcept override; - -private: - Vector2 _direction; - const std::shared_ptr<ICursorController> &_cursor_controller; - const std::shared_ptr<IScene> &_scene; -}; diff --git a/src/commands/quit.cpp b/src/commands/quit.cpp deleted file mode 100644 index c2a68e7..0000000 --- a/src/commands/quit.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "quit.hpp" - -#include <cstdlib> - -void QuitCommand::execute() noexcept -{ - exit(EXIT_SUCCESS); -} diff --git a/src/commands/quit.hpp b/src/commands/quit.hpp deleted file mode 100644 index cb1aefd..0000000 --- a/src/commands/quit.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include "interfaces/command.hpp" - -class QuitCommand : public ICommand -{ -public: - void execute() noexcept override; -}; diff --git a/src/commands/toggle_pause.cpp b/src/commands/toggle_pause.cpp deleted file mode 100644 index 852e093..0000000 --- a/src/commands/toggle_pause.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "toggle_pause.hpp" - -#include <fmt/core.h> -#include <utility> - -TogglePauseCommand::TogglePauseCommand( - std::shared_ptr<IGenerationTracker> generation_tracker, - std::shared_ptr<IStatusManager> status_manager) noexcept - : _generation_tracker(std::move(generation_tracker)), - _status_manager(std::move(status_manager)) -{ -} - -void TogglePauseCommand::execute() noexcept -{ - auto onoff = !_generation_tracker->get_is_paused(); - - _generation_tracker->set_is_paused(onoff); - - _status_manager->set_section_body(StatusLineSection::D, onoff ? "yes" : "no"); -} diff --git a/src/commands/toggle_pause.hpp b/src/commands/toggle_pause.hpp deleted file mode 100644 index 41427cc..0000000 --- a/src/commands/toggle_pause.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "interfaces/command.hpp" -#include "interfaces/generation_tracker.hpp" -#include "interfaces/status_manager.hpp" - -#include <memory> - -class TogglePauseCommand : public ICommand -{ -public: - explicit TogglePauseCommand( - std::shared_ptr<IGenerationTracker> generation_tracker, - std::shared_ptr<IStatusManager> status_manager) noexcept; - - void execute() noexcept override; - -private: - std::shared_ptr<IGenerationTracker> _generation_tracker; - std::shared_ptr<IStatusManager> _status_manager; -}; |