aboutsummaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-04-24 17:13:52 +0200
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:58 +0200
commitdb6edcd473a684420e9a7611b24462df21165c1b (patch)
tree9646bdb4f5f6e339a0a01873b44e0b185476ce56 /src/game
parentb36d072ad7a7b9c6e30fcb25d6bbb001a8393468 (diff)
style: improve function and brace styling
Diffstat (limited to 'src/game')
-rw-r--r--src/game/game.cpp56
-rw-r--r--src/game/game.hpp13
-rw-r--r--src/game/status_updater.cpp15
-rw-r--r--src/game/status_updater.hpp3
-rw-r--r--src/game/statusline.cpp23
-rw-r--r--src/game/statusline.hpp12
6 files changed, 81 insertions, 41 deletions
diff --git a/src/game/game.cpp b/src/game/game.cpp
index 88b9584..1a69e2e 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -9,11 +9,14 @@
#include <iostream>
#include <utility>
-Game::Game(std::shared_ptr<IWindow> window, std::shared_ptr<IScene> scene,
- std::shared_ptr<ICursorController> cursor_controller,
- std::shared_ptr<IStatusLine> statusline,
- std::shared_ptr<IGenerationTracker> generation_tracker,
- std::shared_ptr<IStatusUpdater> status_updater) noexcept
+Game::Game(
+ std::shared_ptr<IWindow> window,
+ std::shared_ptr<IScene> scene,
+ std::shared_ptr<ICursorController> cursor_controller,
+ std::shared_ptr<IStatusLine> statusline,
+ std::shared_ptr<IGenerationTracker> generation_tracker,
+ std::shared_ptr<IStatusUpdater> status_updater
+) noexcept
: _window(std::move(window)),
_scene(std::move(scene)),
_cursor_controller(std::move(cursor_controller)),
@@ -32,8 +35,8 @@ void Game::on_start() noexcept
const auto window_size = _window->size();
const auto center_position =
- Vector2({.x = static_cast<Vector2::Value>(window_size.get_width()) / 2,
- .y = static_cast<Vector2::Value>(window_size.get_height()) / 2});
+ Vector2({ .x = static_cast<Vector2::Value>(window_size.get_width()) / 2,
+ .y = static_cast<Vector2::Value>(window_size.get_height()) / 2 });
_cursor_controller->move_to(center_position);
@@ -60,15 +63,32 @@ 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, _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
+ ) } };
}
diff --git a/src/game/game.hpp b/src/game/game.hpp
index dfbe619..9f08158 100644
--- a/src/game/game.hpp
+++ b/src/game/game.hpp
@@ -13,11 +13,14 @@
class Game : public IGame
{
public:
- Game(std::shared_ptr<IWindow> window, std::shared_ptr<IScene> scene,
- std::shared_ptr<ICursorController> cursor_controller,
- std::shared_ptr<IStatusLine> statusline,
- std::shared_ptr<IGenerationTracker> generation_tracker,
- std::shared_ptr<IStatusUpdater> status_updater) noexcept;
+ Game(
+ std::shared_ptr<IWindow> window,
+ std::shared_ptr<IScene> scene,
+ std::shared_ptr<ICursorController> cursor_controller,
+ std::shared_ptr<IStatusLine> statusline,
+ std::shared_ptr<IGenerationTracker> generation_tracker,
+ std::shared_ptr<IStatusUpdater> status_updater
+ ) noexcept;
void on_start() noexcept override;
diff --git a/src/game/status_updater.cpp b/src/game/status_updater.cpp
index 18c535e..1cfd1d2 100644
--- a/src/game/status_updater.cpp
+++ b/src/game/status_updater.cpp
@@ -5,7 +5,8 @@
StatusUpdater::StatusUpdater(
std::shared_ptr<IStatusLine> statusline,
- std::shared_ptr<IGenerationTracker> generation_tracker) noexcept
+ std::shared_ptr<IGenerationTracker> generation_tracker
+) noexcept
: _statusline(std::move(statusline)),
_generation_tracker(std::move(generation_tracker))
{
@@ -15,11 +16,15 @@ void StatusUpdater::update(const Vector2 &context) noexcept
{
_statusline->set_status(
StatusLineSection::A,
- fmt::format("X: {} Y {}", context.get_x(), context.get_y()));
+ fmt::format("X: {} Y {}", context.get_x(), context.get_y())
+ );
_statusline->set_status(
StatusLineSection::B,
- fmt::format("Paused: {} Generation: {}",
- _generation_tracker->get_is_paused() ? "yes" : "no",
- _generation_tracker->get_current_generation()));
+ fmt::format(
+ "Paused: {} Generation: {}",
+ _generation_tracker->get_is_paused() ? "yes" : "no",
+ _generation_tracker->get_current_generation()
+ )
+ );
}
diff --git a/src/game/status_updater.hpp b/src/game/status_updater.hpp
index 3b76d3b..0fd38a7 100644
--- a/src/game/status_updater.hpp
+++ b/src/game/status_updater.hpp
@@ -14,7 +14,8 @@ class StatusUpdater : public IStatusUpdater
public:
explicit StatusUpdater(
std::shared_ptr<IStatusLine> statusline,
- std::shared_ptr<IGenerationTracker> generation_tracker) noexcept;
+ std::shared_ptr<IGenerationTracker> generation_tracker
+ ) noexcept;
void update(const Vector2 &context) noexcept override;
diff --git a/src/game/statusline.cpp b/src/game/statusline.cpp
index 6becb38..d764d60 100644
--- a/src/game/statusline.cpp
+++ b/src/game/statusline.cpp
@@ -7,8 +7,10 @@
#include <string>
#include <utility>
-StatusLine::StatusLine(std::shared_ptr<ICursorController> cursor_controller,
- std::shared_ptr<IWindow> window) noexcept
+StatusLine::StatusLine(
+ std::shared_ptr<ICursorController> cursor_controller,
+ std::shared_ptr<IWindow> window
+) noexcept
: _cursor_controller(std::move(cursor_controller)), _window(std::move(window))
{
constexpr uint32_t SECTION_A_LENGTH = 20;
@@ -30,8 +32,10 @@ void StatusLine::initialize_background() noexcept
_move_back(previous_position);
}
-void StatusLine::set_status(StatusLineSection section,
- const std::string_view &str) noexcept
+void StatusLine::set_status(
+ StatusLineSection section,
+ const std::string_view &statusline_str
+) noexcept
{
_clear_section(section);
@@ -43,7 +47,9 @@ void StatusLine::set_status(StatusLineSection section,
auto section_length = _sections_lengths[section];
- auto status = str.length() > section_length ? str.substr(0, section_length) : str;
+ auto status = statusline_str.length() > section_length
+ ? statusline_str.substr(0, section_length)
+ : statusline_str;
fmt::print("{}{}", background_color, status);
fmt::print(RESET_ALL_MODES, fmt::arg("esc", ESC));
@@ -61,7 +67,7 @@ auto StatusLine::_move_to_statusline(int32_t x) noexcept -> Vector2
auto window_height = static_cast<Vector2::Value>(window_size.get_height());
- _cursor_controller->move_to(Vector2({.x = x, .y = window_height}), true);
+ _cursor_controller->move_to(Vector2({ .x = x, .y = window_height }), true);
return previous_position;
}
@@ -80,8 +86,9 @@ auto StatusLine::_get_section_start_x(StatusLineSection section) const noexcept
while (section_index > 0)
{
- section_start += static_cast<int32_t>(
- _sections_lengths.at(StatusLineSection(section_index - 1)));
+ section_start +=
+ static_cast<int32_t>(_sections_lengths.at(StatusLineSection(section_index - 1)
+ ));
section_index--;
}
diff --git a/src/game/statusline.hpp b/src/game/statusline.hpp
index 9e85008..66ce2c4 100644
--- a/src/game/statusline.hpp
+++ b/src/game/statusline.hpp
@@ -17,13 +17,17 @@ constexpr uint32_t STATUSBAR_COLOR = 0x1A1A1AU;
class StatusLine : public IStatusLine
{
public:
- StatusLine(std::shared_ptr<ICursorController> cursor_controller,
- std::shared_ptr<IWindow> window) noexcept;
+ StatusLine(
+ std::shared_ptr<ICursorController> cursor_controller,
+ std::shared_ptr<IWindow> window
+ ) noexcept;
void initialize_background() noexcept override;
- void set_status(StatusLineSection section,
- const std::string_view &str) noexcept override;
+ void set_status(
+ StatusLineSection section,
+ const std::string_view &status_str
+ ) noexcept override;
private:
std::unordered_map<StatusLineSection, uint32_t> _sections_lengths;