aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/bootstrap.cpp50
-rw-r--r--src/commands/toggle_pause.cpp13
-rw-r--r--src/commands/toggle_pause.hpp6
-rw-r--r--src/game/game.cpp101
-rw-r--r--src/game/game.hpp11
-rw-r--r--src/game/status_manager.cpp43
-rw-r--r--src/game/status_manager.hpp32
-rw-r--r--src/game/status_updater.cpp30
-rw-r--r--src/game/status_updater.hpp25
-rw-r--r--src/game/statusline.cpp55
-rw-r--r--src/game/statusline.hpp14
-rw-r--r--src/game/statusline_subscriber_adapter.hpp30
-rw-r--r--src/game/statusline_subscriber_adapter.tpp31
-rw-r--r--src/interfaces/status_manager.hpp28
-rw-r--r--src/interfaces/status_updater.hpp23
-rw-r--r--src/interfaces/statusline.hpp16
-rw-r--r--src/interfaces/statusline_subscriber_adapter.hpp17
18 files changed, 364 insertions, 163 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 92ce76b..3a75269 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -15,7 +15,7 @@ file(GLOB SOURCES
argument_parser.cpp
util/color.cpp
game/game.cpp
- game/status_updater.cpp
+ game/status_manager.cpp
game/generation_tracker.cpp
game/statusline.cpp
engine/engine.cpp
diff --git a/src/bootstrap.cpp b/src/bootstrap.cpp
index 52d4ab8..70407a2 100644
--- a/src/bootstrap.cpp
+++ b/src/bootstrap.cpp
@@ -10,8 +10,9 @@
#include "interfaces/matrix.hpp"
#include "interfaces/randomization.hpp"
#include "interfaces/scene.hpp"
-#include "interfaces/status_updater.hpp"
+#include "interfaces/status_manager.hpp"
#include "interfaces/statusline.hpp"
+#include "interfaces/statusline_subscriber_adapter.hpp"
#include "interfaces/window.hpp"
// Implementations
@@ -26,14 +27,19 @@
#include "engine/user/input.hpp"
#include "game/game.hpp"
#include "game/generation_tracker.hpp"
-#include "game/status_updater.hpp"
+#include "game/status_manager.hpp"
#include "game/statusline.hpp"
+#include "game/statusline_subscriber_adapter.hpp"
#include "randomization/generator.hpp"
#include "randomization/seed_generator.hpp"
+#include <fmt/core.h>
+
#include <memory>
#include <random>
+#include <string>
#include <string_view>
+#include <vector>
auto bootstrap() noexcept -> yacppdic::Container
{
@@ -56,11 +62,14 @@ auto bootstrap() noexcept -> yacppdic::Container
std::shared_ptr<IStatusLine> statusline =
container.get<IStatusLineFactory>()(cursor_controller, window);
+ std::shared_ptr<IStatusManager> status_manager =
+ container.get<IStatusManagerFactory>()(statusline);
+
std::shared_ptr<IGenerationTracker> generation_tracker =
container.get<IGenerationTrackerFactory>()(true);
- std::shared_ptr<IStatusUpdater> status_updater =
- container.get<IStatusUpdaterFactory>()(statusline, generation_tracker);
+ auto vector2_statusline_subscriber_adapter_factory =
+ container.get<IStatusLineSubscriberAdapterFactory<Vector2>>();
return std::make_unique<Game>(
window,
@@ -68,7 +77,8 @@ auto bootstrap() noexcept -> yacppdic::Container
cursor_controller,
statusline,
generation_tracker,
- status_updater
+ status_manager,
+ vector2_statusline_subscriber_adapter_factory
);
}
);
@@ -107,11 +117,33 @@ auto bootstrap() noexcept -> yacppdic::Container
}
);
- container.bind<IStatusUpdaterFactory>().to_factory(
- [](const std::shared_ptr<IStatusLine> &statusline,
- const std::shared_ptr<IGenerationTracker> &generation_tracker)
+ container.bind<IStatusManagerFactory>().to_factory(
+ [](const std::shared_ptr<IStatusLine> &statusline)
{
- return std::make_unique<StatusUpdater>(statusline, generation_tracker);
+ return std::make_unique<StatusManager>(statusline);
+ }
+ );
+
+ container.bind<IStatusLineSubscriberAdapterFactory<Vector2>>().to_factory(
+ [](const std::shared_ptr<IStatusManager> &status_manager,
+ std::vector<StatusLineSection> sections)
+ {
+ return std::make_unique<StatusLineSubscriberAdapter<Vector2>>(
+ status_manager,
+ [](std::size_t section_index, const Vector2 &position)
+ {
+ switch (section_index)
+ {
+ case 0:
+ return fmt::format("{}", position.get_x());
+ case 1:
+ return fmt::format("{}", position.get_y());
+ default:
+ return std::string("");
+ }
+ },
+ sections
+ );
}
);
diff --git a/src/commands/toggle_pause.cpp b/src/commands/toggle_pause.cpp
index 434330e..54682c6 100644
--- a/src/commands/toggle_pause.cpp
+++ b/src/commands/toggle_pause.cpp
@@ -5,10 +5,10 @@
TogglePauseCommand::TogglePauseCommand(
std::shared_ptr<IGenerationTracker> generation_tracker,
- std::shared_ptr<IStatusLine> statusline
+ std::shared_ptr<IStatusManager> status_manager
) noexcept
: _generation_tracker(std::move(generation_tracker)),
- _statusline(std::move(statusline))
+ _status_manager(std::move(status_manager))
{
}
@@ -18,12 +18,5 @@ void TogglePauseCommand::execute() noexcept
_generation_tracker->set_is_paused(onoff);
- _statusline->set_status(
- StatusLineSection::B,
- fmt::format(
- "Paused: {} Generation: {}",
- _generation_tracker->get_is_paused() ? "yes" : "no",
- _generation_tracker->get_current_generation()
- )
- );
+ _status_manager->set_section_body(StatusLineSection::D, onoff ? "yes" : "no");
}
diff --git a/src/commands/toggle_pause.hpp b/src/commands/toggle_pause.hpp
index e243cc3..43502f8 100644
--- a/src/commands/toggle_pause.hpp
+++ b/src/commands/toggle_pause.hpp
@@ -2,7 +2,7 @@
#include "interfaces/command.hpp"
#include "interfaces/generation_tracker.hpp"
-#include "interfaces/statusline.hpp"
+#include "interfaces/status_manager.hpp"
#include <memory>
@@ -11,12 +11,12 @@ class TogglePauseCommand : public ICommand
public:
explicit TogglePauseCommand(
std::shared_ptr<IGenerationTracker> generation_tracker,
- std::shared_ptr<IStatusLine> statusline
+ std::shared_ptr<IStatusManager> status_manager
) noexcept;
void execute() noexcept override;
private:
std::shared_ptr<IGenerationTracker> _generation_tracker;
- std::shared_ptr<IStatusLine> _statusline;
+ std::shared_ptr<IStatusManager> _status_manager;
};
diff --git a/src/game/game.cpp b/src/game/game.cpp
index 1a69e2e..02a0f65 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -15,14 +15,19 @@ Game::Game(
std::shared_ptr<ICursorController> cursor_controller,
std::shared_ptr<IStatusLine> statusline,
std::shared_ptr<IGenerationTracker> generation_tracker,
- std::shared_ptr<IStatusUpdater> status_updater
+ std::shared_ptr<IStatusManager> status_manager,
+ IStatusLineSubscriberAdapterFactory<Vector2>
+ vector2_statusline_subscriber_adapter_factory
) noexcept
: _window(std::move(window)),
_scene(std::move(scene)),
_cursor_controller(std::move(cursor_controller)),
_statusline(std::move(statusline)),
_generation_tracker(std::move(generation_tracker)),
- _status_updater(std::move(status_updater))
+ _status_manager(std::move(status_manager)),
+ _vector2_statusline_subscriber_adapter_factory(
+ vector2_statusline_subscriber_adapter_factory
+ )
{
}
@@ -30,7 +35,22 @@ void Game::on_start() noexcept
{
_statusline->initialize_background();
- _cursor_controller->subscribe(CursorEvent::POSITION_CHANGE, _status_updater);
+ _status_manager->set_section_title(StatusLineSection::A, "");
+ _status_manager->set_section_title(StatusLineSection::B, "X: ");
+ _status_manager->set_section_title(StatusLineSection::C, "Y: ");
+ _status_manager->set_section_title(StatusLineSection::D, "Paused: ");
+ _status_manager->set_section_title(StatusLineSection::E, "Generation: ");
+
+ 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 window_size = _window->size();
@@ -40,7 +60,22 @@ void Game::on_start() noexcept
_cursor_controller->move_to(center_position);
- _status_updater->update(center_position);
+ _status_manager->set_section_body(
+ StatusLineSection::B,
+ fmt::format("{}", center_position.get_x())
+ );
+
+ _status_manager->set_section_body(
+ StatusLineSection::C,
+ fmt::format("{}", center_position.get_y())
+ );
+
+ _status_manager->set_section_body(
+ StatusLineSection::D,
+ _generation_tracker->get_is_paused() ? "yes" : "no"
+ );
+
+ _status_manager->set_section_body(StatusLineSection::E, "0");
}
void Game::on_update() noexcept {}
@@ -63,32 +98,34 @@ void Game::on_exit() const noexcept
auto Game::get_input_config() const noexcept
-> std::unordered_map<char, std::shared_ptr<ICommand>>
{
- return { { 'q', std::make_shared<QuitCommand>() },
- { 'i', std::make_shared<InsertCellCommand>(_cursor_controller, _scene) },
- { 'p',
- std::make_shared<TogglePauseCommand>(_generation_tracker, _statusline) },
- { 'k',
- std::make_shared<MoveCursorCommand>(
- Vector2::up(),
- _cursor_controller,
- _window
- ) },
- { 'j',
- std::make_shared<MoveCursorCommand>(
- Vector2::down(),
- _cursor_controller,
- _window
- ) },
- { 'h',
- std::make_shared<MoveCursorCommand>(
- Vector2::left(),
- _cursor_controller,
- _window
- ) },
- { 'l',
- std::make_shared<MoveCursorCommand>(
- Vector2::right(),
- _cursor_controller,
- _window
- ) } };
+ return {
+ { 'q', std::make_shared<QuitCommand>() },
+ { 'i', std::make_shared<InsertCellCommand>(_cursor_controller, _scene) },
+ { 'p',
+ std::make_shared<TogglePauseCommand>(_generation_tracker, _status_manager) },
+ { 'k',
+ std::make_shared<MoveCursorCommand>(
+ Vector2::up(),
+ _cursor_controller,
+ _window
+ ) },
+ { 'j',
+ std::make_shared<MoveCursorCommand>(
+ Vector2::down(),
+ _cursor_controller,
+ _window
+ ) },
+ { 'h',
+ std::make_shared<MoveCursorCommand>(
+ Vector2::left(),
+ _cursor_controller,
+ _window
+ ) },
+ { 'l',
+ std::make_shared<MoveCursorCommand>(
+ Vector2::right(),
+ _cursor_controller,
+ _window
+ ) }
+ };
}
diff --git a/src/game/game.hpp b/src/game/game.hpp
index 9f08158..9689215 100644
--- a/src/game/game.hpp
+++ b/src/game/game.hpp
@@ -4,8 +4,9 @@
#include "interfaces/game.hpp"
#include "interfaces/generation_tracker.hpp"
#include "interfaces/scene.hpp"
-#include "interfaces/status_updater.hpp"
+#include "interfaces/status_manager.hpp"
#include "interfaces/statusline.hpp"
+#include "interfaces/statusline_subscriber_adapter.hpp"
#include "interfaces/window.hpp"
#include <memory>
@@ -19,7 +20,9 @@ public:
std::shared_ptr<ICursorController> cursor_controller,
std::shared_ptr<IStatusLine> statusline,
std::shared_ptr<IGenerationTracker> generation_tracker,
- std::shared_ptr<IStatusUpdater> status_updater
+ std::shared_ptr<IStatusManager> status_manager,
+ IStatusLineSubscriberAdapterFactory<Vector2>
+ vector2_statusline_subscriber_adapter_factory
) noexcept;
void on_start() noexcept override;
@@ -37,5 +40,7 @@ private:
std::shared_ptr<ICursorController> _cursor_controller;
std::shared_ptr<IStatusLine> _statusline;
std::shared_ptr<IGenerationTracker> _generation_tracker;
- std::shared_ptr<IStatusUpdater> _status_updater;
+ std::shared_ptr<IStatusManager> _status_manager;
+ IStatusLineSubscriberAdapterFactory<Vector2>
+ _vector2_statusline_subscriber_adapter_factory;
};
diff --git a/src/game/status_manager.cpp b/src/game/status_manager.cpp
new file mode 100644
index 0000000..727452c
--- /dev/null
+++ b/src/game/status_manager.cpp
@@ -0,0 +1,43 @@
+#include "status_manager.hpp"
+
+#include <fmt/core.h>
+
+#include <utility>
+
+StatusManager::StatusManager(std::shared_ptr<IStatusLine> statusline) noexcept
+ : _statusline(std::move(statusline))
+
+{
+ _statusline->set_section_length(StatusLineSection::A, 5U);
+ _statusline->set_section_length(StatusLineSection::B, 15U);
+ _statusline->set_section_length(StatusLineSection::C, 15U);
+ _statusline->set_section_length(StatusLineSection::D, 20U);
+ _statusline->set_section_length(StatusLineSection::E, 15U);
+ _statusline->set_section_length(StatusLineSection::F, 15U);
+}
+
+void StatusManager::set_section_title(
+ const StatusLineSection &section,
+ const std::string_view &title
+) noexcept
+{
+ if (_title_lengths.count(section) != 0)
+ {
+ fmt::print(stderr, "Error: can't set statusbar section title more than once");
+ return;
+ }
+
+ _statusline->set_status(section, title);
+
+ _title_lengths[section] = title.length();
+}
+
+void StatusManager::set_section_body(
+ const StatusLineSection &section,
+ const std::string_view &body
+) noexcept
+{
+ auto section_title_length = _title_lengths[section];
+
+ _statusline->set_status(section, body, section_title_length + 1);
+}
diff --git a/src/game/status_manager.hpp b/src/game/status_manager.hpp
new file mode 100644
index 0000000..62b5bc7
--- /dev/null
+++ b/src/game/status_manager.hpp
@@ -0,0 +1,32 @@
+#pragma once
+
+#include "interfaces/generation_tracker.hpp"
+#include "interfaces/status_manager.hpp"
+#include "interfaces/statusline.hpp"
+#include "interfaces/subscriber.hpp"
+
+#include "engine/data/vector2.hpp"
+
+#include <memory>
+#include <unordered_map>
+
+class StatusManager : public IStatusManager
+{
+public:
+ explicit StatusManager(std::shared_ptr<IStatusLine> statusline) noexcept;
+
+ void set_section_title(
+ const StatusLineSection &section,
+ const std::string_view &title
+ ) noexcept override;
+
+ void set_section_body(
+ const StatusLineSection &section,
+ const std::string_view &body
+ ) noexcept override;
+
+private:
+ std::shared_ptr<IStatusLine> _statusline;
+
+ std::unordered_map<StatusLineSection, std::size_t> _title_lengths;
+};
diff --git a/src/game/status_updater.cpp b/src/game/status_updater.cpp
deleted file mode 100644
index 1cfd1d2..0000000
--- a/src/game/status_updater.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-#include "status_updater.hpp"
-
-#include <fmt/core.h>
-#include <utility>
-
-StatusUpdater::StatusUpdater(
- std::shared_ptr<IStatusLine> statusline,
- std::shared_ptr<IGenerationTracker> generation_tracker
-) noexcept
- : _statusline(std::move(statusline)),
- _generation_tracker(std::move(generation_tracker))
-{
-}
-
-void StatusUpdater::update(const Vector2 &context) noexcept
-{
- _statusline->set_status(
- StatusLineSection::A,
- fmt::format("X: {} Y {}", context.get_x(), context.get_y())
- );
-
- _statusline->set_status(
- StatusLineSection::B,
- fmt::format(
- "Paused: {} Generation: {}",
- _generation_tracker->get_is_paused() ? "yes" : "no",
- _generation_tracker->get_current_generation()
- )
- );
-}
diff --git a/src/game/status_updater.hpp b/src/game/status_updater.hpp
deleted file mode 100644
index 0fd38a7..0000000
--- a/src/game/status_updater.hpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#pragma once
-
-#include "interfaces/generation_tracker.hpp"
-#include "interfaces/status_updater.hpp"
-#include "interfaces/statusline.hpp"
-#include "interfaces/subscriber.hpp"
-
-#include "engine/data/vector2.hpp"
-
-#include <memory>
-
-class StatusUpdater : public IStatusUpdater
-{
-public:
- explicit StatusUpdater(
- std::shared_ptr<IStatusLine> statusline,
- std::shared_ptr<IGenerationTracker> generation_tracker
- ) noexcept;
-
- void update(const Vector2 &context) noexcept override;
-
-private:
- std::shared_ptr<IStatusLine> _statusline;
- std::shared_ptr<IGenerationTracker> _generation_tracker;
-};
diff --git a/src/game/statusline.cpp b/src/game/statusline.cpp
index d764d60..58a317b 100644
--- a/src/game/statusline.cpp
+++ b/src/game/statusline.cpp
@@ -3,9 +3,13 @@
#include "engine/escape.hpp"
#include "util/color.hpp"
+#include <algorithm>
#include <iostream>
+#include <numeric>
+#include <ranges>
#include <string>
#include <utility>
+#include <vector>
StatusLine::StatusLine(
std::shared_ptr<ICursorController> cursor_controller,
@@ -13,11 +17,6 @@ StatusLine::StatusLine(
) noexcept
: _cursor_controller(std::move(cursor_controller)), _window(std::move(window))
{
- constexpr uint32_t SECTION_A_LENGTH = 20;
- constexpr uint32_t SECTION_B_LENGTH = 30;
-
- _sections_lengths[StatusLineSection::A] = SECTION_A_LENGTH;
- _sections_lengths[StatusLineSection::B] = SECTION_B_LENGTH;
}
void StatusLine::initialize_background() noexcept
@@ -33,23 +32,27 @@ void StatusLine::initialize_background() noexcept
}
void StatusLine::set_status(
- StatusLineSection section,
- const std::string_view &statusline_str
+ const StatusLineSection &section,
+ const std::string_view &status,
+ std::size_t start
) noexcept
{
- _clear_section(section);
+ _clear_section(section, start);
- int32_t section_start = _get_section_start_x(section);
+ auto section_start = _get_section_start_x(section);
- const auto previous_position = _move_to_statusline(section_start);
+ const auto previous_position =
+ _move_to_statusline(section_start + static_cast<int32_t>(start));
auto background_color = get_background_esc_seq(STATUSBAR_COLOR);
auto section_length = _sections_lengths[section];
- auto status = statusline_str.length() > section_length
- ? statusline_str.substr(0, section_length)
- : statusline_str;
+ /*
+ auto status = status.length() > section_length
+ ? status_str.substr(0, section_length)
+ : status_str;
+ */
fmt::print("{}{}", background_color, status);
fmt::print(RESET_ALL_MODES, fmt::arg("esc", ESC));
@@ -57,6 +60,14 @@ void StatusLine::set_status(
_move_back(previous_position);
}
+void StatusLine::set_section_length(
+ const StatusLineSection &section,
+ uint32_t length
+) noexcept
+{
+ _sections_lengths[section] = length;
+}
+
auto StatusLine::_move_to_statusline(int32_t x) noexcept -> Vector2
{
const auto previous_position = _cursor_controller->where();
@@ -78,7 +89,8 @@ void StatusLine::_move_back(Vector2 previous_position) noexcept
_cursor_controller->show();
}
-auto StatusLine::_get_section_start_x(StatusLineSection section) const noexcept -> int32_t
+auto StatusLine::_get_section_start_x(const StatusLineSection &section) const noexcept
+ -> int32_t
{
int32_t section_start = 0;
@@ -96,17 +108,24 @@ auto StatusLine::_get_section_start_x(StatusLineSection section) const noexcept
return section_start;
}
-void StatusLine::_clear_section(StatusLineSection section) noexcept
+void StatusLine::_clear_section(
+ const StatusLineSection &section,
+ std::size_t start
+) noexcept
{
auto section_start = _get_section_start_x(section);
- const auto previous_position = _move_to_statusline(section_start);
+ auto start_int32 = static_cast<int32_t>(start);
+
+ const auto previous_position = _move_to_statusline(section_start + start_int32);
auto background_color = get_background_esc_seq(STATUSBAR_COLOR);
- auto section_length = _sections_lengths.at(section);
+ auto section_length = _sections_lengths[section];
+
+ auto start_uint32 = static_cast<uint32_t>(start);
- fmt::print("{}{}", background_color, std::string(section_length, ' '));
+ fmt::print("{}{}", background_color, std::string(section_length - start_uint32, ' '));
fmt::print(RESET_ALL_MODES, fmt::arg("esc", ESC));
_move_back(previous_position);
diff --git a/src/game/statusline.hpp b/src/game/statusline.hpp
index 66ce2c4..7883051 100644
--- a/src/game/statusline.hpp
+++ b/src/game/statusline.hpp
@@ -25,10 +25,14 @@ public:
void initialize_background() noexcept override;
void set_status(
- StatusLineSection section,
- const std::string_view &status_str
+ const StatusLineSection &section,
+ const std::string_view &status,
+ std::size_t start
) noexcept override;
+ void set_section_length(const StatusLineSection &section, uint32_t length) noexcept
+ override;
+
private:
std::unordered_map<StatusLineSection, uint32_t> _sections_lengths;
@@ -39,8 +43,8 @@ private:
void _move_back(Vector2 previous_position) noexcept;
- [[nodiscard]] auto _get_section_start_x(StatusLineSection section) const noexcept
- -> int32_t;
+ [[nodiscard]] auto _get_section_start_x(const StatusLineSection &section
+ ) const noexcept -> int32_t;
- void _clear_section(StatusLineSection section) noexcept;
+ void _clear_section(const StatusLineSection &section, std::size_t start) noexcept;
};
diff --git a/src/game/statusline_subscriber_adapter.hpp b/src/game/statusline_subscriber_adapter.hpp
new file mode 100644
index 0000000..d53ae04
--- /dev/null
+++ b/src/game/statusline_subscriber_adapter.hpp
@@ -0,0 +1,30 @@
+#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
new file mode 100644
index 0000000..1de459c
--- /dev/null
+++ b/src/game/statusline_subscriber_adapter.tpp
@@ -0,0 +1,31 @@
+#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++;
+ }
+}
diff --git a/src/interfaces/status_manager.hpp b/src/interfaces/status_manager.hpp
new file mode 100644
index 0000000..afc8416
--- /dev/null
+++ b/src/interfaces/status_manager.hpp
@@ -0,0 +1,28 @@
+#pragma once
+
+#include "interfaces/statusline.hpp"
+
+#include <yacppdic/factory.hpp>
+
+#include <memory>
+#include <string_view>
+
+// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions)
+class IStatusManager
+{
+public:
+ virtual ~IStatusManager() = default;
+
+ virtual void set_section_title(
+ const StatusLineSection &section,
+ const std::string_view &title
+ ) noexcept = 0;
+
+ virtual void set_section_body(
+ const StatusLineSection &section,
+ const std::string_view &body
+ ) noexcept = 0;
+};
+
+using IStatusManagerFactory = yacppdic::Factory<
+ std::unique_ptr<IStatusManager>(const std::shared_ptr<IStatusLine> &statusline)>;
diff --git a/src/interfaces/status_updater.hpp b/src/interfaces/status_updater.hpp
deleted file mode 100644
index 4b2ceb1..0000000
--- a/src/interfaces/status_updater.hpp
+++ /dev/null
@@ -1,23 +0,0 @@
-#pragma once
-
-#include "interfaces/generation_tracker.hpp"
-#include "interfaces/statusline.hpp"
-#include "interfaces/subscriber.hpp"
-
-#include "engine/data/vector2.hpp"
-
-#include <yacppdic/factory.hpp>
-
-#include <memory>
-
-// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions)
-class IStatusUpdater : public ISubscriber<Vector2>
-{
-public:
- void update(const Vector2 &context) noexcept override = 0;
-};
-
-using IStatusUpdaterFactory = yacppdic::Factory<std::unique_ptr<IStatusUpdater>(
- const std::shared_ptr<IStatusLine> &statusline,
- const std::shared_ptr<IGenerationTracker> &generation_tracker
-)>;
diff --git a/src/interfaces/statusline.hpp b/src/interfaces/statusline.hpp
index 0da295e..2b61d24 100644
--- a/src/interfaces/statusline.hpp
+++ b/src/interfaces/statusline.hpp
@@ -9,8 +9,12 @@
enum StatusLineSection
{
- A,
- B
+ A = 0,
+ B = 1,
+ C = 2,
+ D = 3,
+ E = 4,
+ F = 5
};
// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions)
@@ -22,9 +26,13 @@ public:
virtual void initialize_background() noexcept = 0;
virtual void set_status(
- StatusLineSection section,
- const std::string_view &status_str
+ const StatusLineSection &section,
+ const std::string_view &status,
+ std::size_t start = 1UL
) noexcept = 0;
+
+ virtual void
+ set_section_length(const StatusLineSection &section, uint32_t length) noexcept = 0;
};
using IStatusLineFactory = yacppdic::Factory<std::unique_ptr<IStatusLine>(
diff --git a/src/interfaces/statusline_subscriber_adapter.hpp b/src/interfaces/statusline_subscriber_adapter.hpp
new file mode 100644
index 0000000..53543f7
--- /dev/null
+++ b/src/interfaces/statusline_subscriber_adapter.hpp
@@ -0,0 +1,17 @@
+#pragma once
+
+#include "interfaces/status_manager.hpp"
+#include "interfaces/statusline.hpp"
+#include "interfaces/subscriber.hpp"
+
+#include <yacppdic/factory.hpp>
+
+#include <memory>
+#include <vector>
+
+template <typename Context>
+using IStatusLineSubscriberAdapterFactory =
+ yacppdic::Factory<std::unique_ptr<ISubscriber<Context>>(
+ const std::shared_ptr<IStatusManager> &status_manager,
+ std::vector<StatusLineSection> sections
+ )>;