aboutsummaryrefslogtreecommitdiff
path: root/src/engine/user/cursor.cpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-03-10 19:12:31 +0100
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:55 +0200
commit38f14606c78c119d452f302f17329455e29a9a6f (patch)
tree03f6dfd9d3576e87260f7cb3bc436ad076b629c5 /src/engine/user/cursor.cpp
parent09848ad31af6a1c70d64fccee711e231afb5a77f (diff)
refactor: rename game initializer & move input config
Diffstat (limited to 'src/engine/user/cursor.cpp')
-rw-r--r--src/engine/user/cursor.cpp39
1 files changed, 12 insertions, 27 deletions
diff --git a/src/engine/user/cursor.cpp b/src/engine/user/cursor.cpp
index 39fef23..663d56a 100644
--- a/src/engine/user/cursor.cpp
+++ b/src/engine/user/cursor.cpp
@@ -5,32 +5,17 @@
#include <cstdlib>
#include <iostream>
-CursorController::CursorController() : _position(_request_position()) {}
+CursorController::CursorController() : _position({.x = 0, .y = 0}) {}
void CursorController::move(const Vector2 &direction, const uint32_t &amount) noexcept
{
- auto format = direction_format_map.at(direction);
+ auto direction_format = direction_format_map.at(direction);
- fmt::print(fmt::runtime(format.data()), fmt::arg("esc", ESC),
+ fmt::print(fmt::runtime(direction_format.data()), fmt::arg("esc", ESC),
fmt::arg("amount", amount));
std::cout.flush();
- if (direction == Vector2::up())
- {
- _position.set_y(_position.get_y() + static_cast<int>(amount));
- }
- else if (direction == Vector2::down())
- {
- _position.set_y(_position.get_y() - static_cast<int>(amount));
- }
- else if (direction == Vector2::left())
- {
- _position.set_x(_position.get_x() - static_cast<int>(amount));
- }
- else if (direction == Vector2::right())
- {
- _position.set_x(_position.get_x() + static_cast<int>(amount));
- }
+ _position = _position.to_direction(direction, static_cast<Vector2::Value>(amount));
}
void CursorController::move_to(const Vector2 &position) noexcept
@@ -53,13 +38,7 @@ void CursorController::hide()
std::cout.flush();
}
-void CursorController::show()
-{
- fmt::print(CURSOR_VISIBLE, fmt::arg("esc", ESC));
- std::cout.flush();
-}
-
-Vector2 CursorController::_request_position() noexcept
+void CursorController::ensure_position() noexcept
{
fmt::print(REQUEST_CURSOR_POSITION, fmt::arg("esc", ESC));
std::cout.flush();
@@ -69,5 +48,11 @@ Vector2 CursorController::_request_position() noexcept
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
scanf("\033[%u;%uR", &vector2_options.y, &vector2_options.x);
- return Vector2(vector2_options);
+ _position = Vector2(vector2_options);
+}
+
+void CursorController::show()
+{
+ fmt::print(CURSOR_VISIBLE, fmt::arg("esc", ESC));
+ std::cout.flush();
}