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.cpp132
1 files changed, 68 insertions, 64 deletions
diff --git a/src/game/game.cpp b/src/game/game.cpp
index c1bb162..05b02fd 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -146,70 +146,7 @@ void Game::on_start()
{.option_cnt = 1U,
.function = [this](CommandInfo::Options options)
{
- const auto rle_file_path =
- expand_path_home(std::filesystem::path(options[0]));
-
- std::unique_ptr<IMatrix<char>> rle_matrix;
-
- try
- {
- rle_matrix = _rle_reader->read_RLE_file(rle_file_path);
- }
- catch (const InvalidRLEFileError &error)
- {
- _show_command_error(fmt::format("Error: {}", error.what()));
- return;
- }
- catch (const IOError &error)
- {
- _show_command_error(fmt::format("Error: {}", error.what()));
- return;
- }
-
- if (rle_matrix == nullptr)
- {
- _show_command_error(fmt::format(
- "A unknown error occurred while reading RLE file with path '{}'",
- rle_file_path.string()));
- return;
- }
-
- _return_to_normal_mode();
-
- const auto previous_pos = _cursor_controller->where();
-
- auto scene_matrix = _scene->get_matrix();
-
- for (auto row : *rle_matrix)
- {
- for (auto &col : row)
- {
- const auto col_pos = _cursor_controller->where();
-
- std::cout.put(col);
-
- _cursor_controller->move_to(col_pos);
-
- scene_matrix->set(col_pos, col);
-
- if (!ranges::contains(_living_cell_positions, col_pos))
- {
- _living_cell_positions.push_back(col_pos);
- }
-
- _cursor_controller->move(Vector2::right(), 1U);
- }
-
- fmt::print("\n");
- const auto current_pos = _cursor_controller->where();
-
- _cursor_controller->move_to(
- Vector2({.x = previous_pos.get_x(), .y = current_pos.get_y() - 1}));
- }
-
- std::cout.flush();
-
- _cursor_controller->move_to(previous_pos);
+ this->_open_rle_file(options);
}});
}
@@ -646,3 +583,70 @@ void Game::_process_next_generation() noexcept
}
}
}
+
+void Game::_open_rle_file(CommandInfo::Options options) noexcept
+{
+ const auto rle_file_path = expand_path_home(std::filesystem::path(options[0]));
+
+ std::unique_ptr<IMatrix<char>> rle_matrix;
+
+ try
+ {
+ rle_matrix = _rle_reader->read_RLE_file(rle_file_path);
+ }
+ catch (const InvalidRLEFileError &error)
+ {
+ _show_command_error(fmt::format("Error: {}", error.what()));
+ return;
+ }
+ catch (const IOError &error)
+ {
+ _show_command_error(fmt::format("Error: {}", error.what()));
+ return;
+ }
+
+ if (rle_matrix == nullptr)
+ {
+ _show_command_error(fmt::format(
+ "A unknown error occurred while reading RLE file with path '{}'",
+ rle_file_path.string()));
+ return;
+ }
+
+ _return_to_normal_mode();
+
+ const auto previous_pos = _cursor_controller->where();
+
+ auto scene_matrix = _scene->get_matrix();
+
+ for (auto row : *rle_matrix)
+ {
+ for (auto &col : row)
+ {
+ const auto col_pos = _cursor_controller->where();
+
+ std::cout.put(col);
+
+ _cursor_controller->move_to(col_pos);
+
+ scene_matrix->set(col_pos, col);
+
+ if (!ranges::contains(_living_cell_positions, col_pos))
+ {
+ _living_cell_positions.push_back(col_pos);
+ }
+
+ _cursor_controller->move(Vector2::right(), 1U);
+ }
+
+ fmt::print("\n");
+ const auto current_pos = _cursor_controller->where();
+
+ _cursor_controller->move_to(
+ Vector2({.x = previous_pos.get_x(), .y = current_pos.get_y() - 1}));
+ }
+
+ std::cout.flush();
+
+ _cursor_controller->move_to(previous_pos);
+}