From 18e1db1fb8692752f64d3912c3b5ff1818be9028 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 23 May 2022 18:12:39 +0200 Subject: refactor: replace last subscriber patterned code --- src/engine/user/cursor.cpp | 37 +------------------------------------ 1 file changed, 1 insertion(+), 36 deletions(-) (limited to 'src/engine/user/cursor.cpp') diff --git a/src/engine/user/cursor.cpp b/src/engine/user/cursor.cpp index 945433b..97e9104 100644 --- a/src/engine/user/cursor.cpp +++ b/src/engine/user/cursor.cpp @@ -18,11 +18,9 @@ void CursorController::move(const Vector2 &direction, const uint32_t &amount) no std::cout.flush(); _position = _position.to_direction(direction, static_cast(amount)); - - notify_subscribers(CursorEvent::POSITION_CHANGE, _position); } -void CursorController::move_to(const Vector2 &position, bool silent) noexcept +void CursorController::move_to(const Vector2 &position) noexcept { fmt::print( MOVE_CURSOR_TO, @@ -32,11 +30,6 @@ void CursorController::move_to(const Vector2 &position, bool silent) noexcept std::cout.flush(); _position = position; - - if (!silent) - { - notify_subscribers(CursorEvent::POSITION_CHANGE, position); - } } auto CursorController::where() const noexcept -> Vector2 @@ -55,8 +48,6 @@ void CursorController::ensure_position() noexcept scanf("\033[%u;%uR", &vector2_options.y, &vector2_options.x); _position = Vector2(vector2_options); - - notify_subscribers(CursorEvent::POSITION_CHANGE, _position); } void CursorController::hide() noexcept @@ -70,29 +61,3 @@ void CursorController::show() noexcept fmt::print(CURSOR_VISIBLE, fmt::arg("esc", ESC)); std::cout.flush(); } - -void CursorController::subscribe( - const Event &event, - const Subscriber &subscriber) noexcept -{ - if (_subscribers.count(event) == 0) - { - _subscribers.insert({event, std::vector()}); - } - - _subscribers.at(event).push_back(subscriber); -} - -void CursorController::notify_subscribers(const Event &event, const Context &context) - const noexcept -{ - if (_subscribers.count(event) == 0) - { - return; - } - - for (const auto &subscriber : _subscribers.at(event)) - { - subscriber->update(context); - } -} -- cgit v1.2.3-18-g5258