aboutsummaryrefslogtreecommitdiff
path: root/src/game/game.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/game.cpp')
-rw-r--r--src/game/game.cpp101
1 files changed, 69 insertions, 32 deletions
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
+ ) }
+ };
}