From 8805b1fe27344e8086cebabf869b7a02d2376f05 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 7 Jun 2022 19:45:17 +0200 Subject: refactor: decouple statusline from scene & cursor controller Might be slightly slower than previously though... --- src/game/game.cpp | 2 ++ src/game/status_manager.cpp | 27 +++++++++++++++------------ src/game/status_manager.hpp | 4 +++- 3 files changed, 20 insertions(+), 13 deletions(-) (limited to 'src/game') diff --git a/src/game/game.cpp b/src/game/game.cpp index 064b643..8d72324 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -27,6 +27,8 @@ Game::Game( void Game::on_start() noexcept { + _scene->register_component(_status_manager->get_statusline(), Vector2({0, 0})); + _status_manager->initialize(); _status_manager->set_section_title(StatusLineSection::A, ""); diff --git a/src/game/status_manager.cpp b/src/game/status_manager.cpp index 3f2df01..c7d80e9 100644 --- a/src/game/status_manager.cpp +++ b/src/game/status_manager.cpp @@ -12,23 +12,21 @@ StatusManager::StatusManager(std::shared_ptr statusline) noexcept void StatusManager::initialize() noexcept { - _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, 25U); - _statusline->set_section_length(StatusLineSection::F, 60U); - _statusline->set_section_length(StatusLineSection::G, 30U); - _statusline->set_section_length(StatusLineSection::H, 30U); - - _statusline->initialize_background(); + _statusline->set_section_length(StatusLineSection::A, 5); + _statusline->set_section_length(StatusLineSection::B, 15); + _statusline->set_section_length(StatusLineSection::C, 15); + _statusline->set_section_length(StatusLineSection::D, 20); + _statusline->set_section_length(StatusLineSection::E, 25); + _statusline->set_section_length(StatusLineSection::F, 60); + _statusline->set_section_length(StatusLineSection::G, 30); + _statusline->set_section_length(StatusLineSection::H, 30); } void StatusManager::set_section_title( const StatusLineSection §ion, const std::string_view &title) noexcept { - if (_title_lengths.count(section) != 0) + if (_title_lengths.contains(section)) { fmt::print(stderr, "Error: can't set statusbar section title more than once"); return; @@ -36,7 +34,7 @@ void StatusManager::set_section_title( _statusline->set_status(section, title); - _title_lengths[section] = title.length(); + _title_lengths[section] = static_cast(title.length()); } void StatusManager::set_section_body( @@ -47,3 +45,8 @@ void StatusManager::set_section_body( _statusline->set_status(section, body, section_title_length + 1); } + +auto StatusManager::get_statusline() const noexcept -> std::shared_ptr +{ + return _statusline; +} diff --git a/src/game/status_manager.hpp b/src/game/status_manager.hpp index 7bb4f2f..245e888 100644 --- a/src/game/status_manager.hpp +++ b/src/game/status_manager.hpp @@ -24,8 +24,10 @@ public: const StatusLineSection §ion, const std::string_view &body) noexcept override; + auto get_statusline() const noexcept -> std::shared_ptr override; + private: std::shared_ptr _statusline; - std::unordered_map _title_lengths; + std::unordered_map _title_lengths; }; -- cgit v1.2.3-18-g5258