From fb080f6fb911b1831c176a06259e384772541dd5 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 2 May 2022 22:36:21 +0200 Subject: refactor: seperate statusline related concerns --- src/bootstrap.cpp | 50 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) (limited to 'src/bootstrap.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 + #include #include +#include #include +#include auto bootstrap() noexcept -> yacppdic::Container { @@ -56,11 +62,14 @@ auto bootstrap() noexcept -> yacppdic::Container std::shared_ptr statusline = container.get()(cursor_controller, window); + std::shared_ptr status_manager = + container.get()(statusline); + std::shared_ptr generation_tracker = container.get()(true); - std::shared_ptr status_updater = - container.get()(statusline, generation_tracker); + auto vector2_statusline_subscriber_adapter_factory = + container.get>(); return std::make_unique( 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().to_factory( - [](const std::shared_ptr &statusline, - const std::shared_ptr &generation_tracker) + container.bind().to_factory( + [](const std::shared_ptr &statusline) { - return std::make_unique(statusline, generation_tracker); + return std::make_unique(statusline); + } + ); + + container.bind>().to_factory( + [](const std::shared_ptr &status_manager, + std::vector sections) + { + return std::make_unique>( + 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 + ); } ); -- cgit v1.2.3-18-g5258