aboutsummaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
Diffstat (limited to 'src/game')
-rw-r--r--src/game/game.cpp37
-rw-r--r--src/game/game.hpp7
-rw-r--r--src/game/status_manager.hpp1
-rw-r--r--src/game/statusline_subscriber_adapter.hpp29
-rw-r--r--src/game/statusline_subscriber_adapter.tpp31
5 files changed, 22 insertions, 83 deletions
diff --git a/src/game/game.cpp b/src/game/game.cpp
index 3bd8738..c41364a 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -2,7 +2,6 @@
#include <fmt/core.h>
-#include <chrono>
#include <cstdlib>
#include <iostream>
#include <utility>
@@ -12,16 +11,12 @@ Game::Game(
std::shared_ptr<ICursorController> cursor_controller,
std::shared_ptr<IGenerationTracker> generation_tracker,
std::shared_ptr<IStatusManager> status_manager,
- std::shared_ptr<IUserInputObserver> user_input_observer,
- IStatusLineSubscriberAdapterFactory<Vector2>
- vector2_statusline_subscriber_adapter_factory) noexcept
+ std::shared_ptr<IUserInputObserver> user_input_observer) noexcept
: _scene(std::move(scene)),
_cursor_controller(std::move(cursor_controller)),
_generation_tracker(std::move(generation_tracker)),
_status_manager(std::move(status_manager)),
- _user_input_observer(std::move(user_input_observer)),
- _vector2_statusline_subscriber_adapter_factory(
- vector2_statusline_subscriber_adapter_factory)
+ _user_input_observer(std::move(user_input_observer))
{
}
@@ -36,15 +31,6 @@ void Game::on_start() noexcept
_status_manager->set_section_title(StatusLineSection::E, "Generation: ");
_status_manager->set_section_title(StatusLineSection::F, "Time since last frame: ");
- std::shared_ptr<ISubscriber<Vector2>> vector2_statusline_subscriber_adapter =
- _vector2_statusline_subscriber_adapter_factory(
- _status_manager,
- {StatusLineSection::B, StatusLineSection::C});
-
- _cursor_controller->subscribe(
- CursorEvent::POSITION_CHANGE,
- vector2_statusline_subscriber_adapter);
-
const auto scene_size = _scene->size();
const auto center_position = Vector2(
@@ -95,24 +81,43 @@ void Game::on_update() noexcept
matrix->set(position - pos_offset, "#");
}
+ auto cursor_has_moved = false;
+
if (_user_input_observer->is_key_pressed('h'))
{
_move_cursor(Vector2::left());
+ cursor_has_moved = true;
}
if (_user_input_observer->is_key_pressed('j'))
{
_move_cursor(Vector2::down());
+ cursor_has_moved = true;
}
if (_user_input_observer->is_key_pressed('k'))
{
_move_cursor(Vector2::up());
+ cursor_has_moved = true;
}
if (_user_input_observer->is_key_pressed('l'))
{
_move_cursor(Vector2::right());
+ cursor_has_moved = true;
+ }
+
+ if (cursor_has_moved)
+ {
+ const auto current_pos = _cursor_controller->where();
+
+ _status_manager->set_section_body(
+ StatusLineSection::B,
+ fmt::format("{}", current_pos.get_x()));
+
+ _status_manager->set_section_body(
+ StatusLineSection::C,
+ fmt::format("{}", current_pos.get_y()));
}
if (_user_input_observer->is_key_pressed('p'))
diff --git a/src/game/game.hpp b/src/game/game.hpp
index fb6a5ed..955269c 100644
--- a/src/game/game.hpp
+++ b/src/game/game.hpp
@@ -6,7 +6,6 @@
#include "interfaces/input.hpp"
#include "interfaces/scene.hpp"
#include "interfaces/status_manager.hpp"
-#include "interfaces/statusline_subscriber_adapter.hpp"
#include <chrono>
#include <memory>
@@ -19,9 +18,7 @@ public:
std::shared_ptr<ICursorController> cursor_controller,
std::shared_ptr<IGenerationTracker> generation_tracker,
std::shared_ptr<IStatusManager> status_manager,
- std::shared_ptr<IUserInputObserver> user_input_observer,
- IStatusLineSubscriberAdapterFactory<Vector2>
- vector2_statusline_subscriber_adapter_factory) noexcept;
+ std::shared_ptr<IUserInputObserver> user_input_observer) noexcept;
void on_start() noexcept override;
@@ -35,8 +32,6 @@ private:
std::shared_ptr<IGenerationTracker> _generation_tracker;
std::shared_ptr<IStatusManager> _status_manager;
std::shared_ptr<IUserInputObserver> _user_input_observer;
- IStatusLineSubscriberAdapterFactory<Vector2>
- _vector2_statusline_subscriber_adapter_factory;
std::chrono::system_clock::time_point _last_update_time;
diff --git a/src/game/status_manager.hpp b/src/game/status_manager.hpp
index ea61ff8..7bb4f2f 100644
--- a/src/game/status_manager.hpp
+++ b/src/game/status_manager.hpp
@@ -3,7 +3,6 @@
#include "interfaces/generation_tracker.hpp"
#include "interfaces/status_manager.hpp"
#include "interfaces/statusline.hpp"
-#include "interfaces/subscriber.hpp"
#include "engine/data/vector2.hpp"
diff --git a/src/game/statusline_subscriber_adapter.hpp b/src/game/statusline_subscriber_adapter.hpp
deleted file mode 100644
index c0c5805..0000000
--- a/src/game/statusline_subscriber_adapter.hpp
+++ /dev/null
@@ -1,29 +0,0 @@
-#pragma once
-
-#include "interfaces/statusline.hpp"
-#include "interfaces/statusline_subscriber_adapter.hpp"
-#include "interfaces/subscriber.hpp"
-
-#include <memory>
-#include <string>
-#include <vector>
-
-template <typename Context>
-class StatusLineSubscriberAdapter : public ISubscriber<Context>
-{
-public:
- StatusLineSubscriberAdapter(
- std::shared_ptr<IStatusManager> status_manager,
- std::string (*format_func)(std::size_t section_index, const Context &context),
- const std::vector<StatusLineSection> &sections) noexcept;
-
- void update(const Context &context) noexcept override;
-
-private:
- std::shared_ptr<IStatusManager> _status_manager;
-
- std::string (*_format_func)(std::size_t section_index, const Context &context);
- std::vector<StatusLineSection> _sections;
-};
-
-#include "statusline_subscriber_adapter.tpp"
diff --git a/src/game/statusline_subscriber_adapter.tpp b/src/game/statusline_subscriber_adapter.tpp
deleted file mode 100644
index 9054772..0000000
--- a/src/game/statusline_subscriber_adapter.tpp
+++ /dev/null
@@ -1,31 +0,0 @@
-#pragma once
-
-#include "statusline_subscriber_adapter.hpp"
-
-#include <utility>
-
-template <typename Context>
-StatusLineSubscriberAdapter<Context>::StatusLineSubscriberAdapter(
- std::shared_ptr<IStatusManager> status_manager,
- std::string (*format_func)(std::size_t section_index, const Context &context),
- const std::vector<StatusLineSection> &sections
-
- ) noexcept
- : _status_manager(std::move(status_manager)),
- _format_func(format_func),
- _sections(sections)
-{
-}
-
-template <typename Context>
-void StatusLineSubscriberAdapter<Context>::update(const Context &context) noexcept
-{
- for (std::size_t index = 0; const auto &section : _sections)
- {
- auto status = _format_func(index, context);
-
- _status_manager->set_section_body(_sections[index], status);
-
- index++;
- }
-}