aboutsummaryrefslogtreecommitdiff
path: root/src/bootstrap.cpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-05-02 22:36:21 +0200
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:58 +0200
commitfb080f6fb911b1831c176a06259e384772541dd5 (patch)
treee18140e700cd974f84a5630f41fcb0b496b7e772 /src/bootstrap.cpp
parent40d02748924aa7c48b04cf948204d8dacdfbbc74 (diff)
refactor: seperate statusline related concerns
Diffstat (limited to 'src/bootstrap.cpp')
-rw-r--r--src/bootstrap.cpp50
1 files changed, 41 insertions, 9 deletions
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
+ );
}
);