From 3f9004b598fc8006576db9b8d2ae4e080101101b Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 8 Jun 2022 16:06:03 +0200 Subject: refactor: give game responsibility of statusline --- src/game/game.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/game/game.cpp') diff --git a/src/game/game.cpp b/src/game/game.cpp index 8d72324..3127d40 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -1,5 +1,6 @@ #include "game.hpp" +#include "engine/data/bounds.hpp" #include "util/algorithm.hpp" #include @@ -10,13 +11,15 @@ #include Game::Game( + IStatusLineFactory statusline_factory, std::shared_ptr scene, std::shared_ptr cursor_controller, std::shared_ptr generation_tracker, std::shared_ptr status_manager, std::shared_ptr user_input_observer, std::shared_ptr cell_helper) noexcept - : _scene(std::move(scene)), + : _statusline_factory(std::move(statusline_factory)), + _scene(std::move(scene)), _cursor_controller(std::move(cursor_controller)), _generation_tracker(std::move(generation_tracker)), _status_manager(std::move(status_manager)), @@ -27,9 +30,14 @@ Game::Game( void Game::on_start() noexcept { - _scene->register_component(_status_manager->get_statusline(), Vector2({0, 0})); + const auto scene_size = _scene->size(); + + std::shared_ptr statusline = + _statusline_factory(Bounds({.width = scene_size.get_width(), .height = 1})); + + _scene->register_component(statusline, Vector2({0, 0})); - _status_manager->initialize(); + _status_manager->bind(statusline); _status_manager->set_section_title(StatusLineSection::A, ""); _status_manager->set_section_title(StatusLineSection::B, "X: "); @@ -42,8 +50,6 @@ void Game::on_start() noexcept _status_manager->set_section_title(StatusLineSection::G, "Living cells: "); _status_manager->set_section_title(StatusLineSection::H, "Window size: "); - const auto scene_size = _scene->size(); - const auto center_position = Vector2( {.x = static_cast(scene_size.get_width()) / 2, .y = static_cast(scene_size.get_height()) / 2}); -- cgit v1.2.3-18-g5258