diff --git a/Userland/Games/GameOfLife/BoardWidget.cpp b/Userland/Games/GameOfLife/BoardWidget.cpp index b3ff7997c4..48d635fea6 100644 --- a/Userland/Games/GameOfLife/BoardWidget.cpp +++ b/Userland/Games/GameOfLife/BoardWidget.cpp @@ -167,9 +167,9 @@ void BoardWidget::paint_event(GUI::PaintEvent& event) if (m_selected_pattern != nullptr) { int y_offset = 0; - for (auto line : m_selected_pattern->pattern()) { + for (auto const& line : m_selected_pattern->pattern()) { int x_offset = 0; - for (auto c : line) { + for (auto c : line.bytes_as_string_view()) { if (c == 'O' && (m_last_cell_hovered.row + y_offset) < m_board->rows() && (m_last_cell_hovered.column + x_offset) < m_board->columns() && row == (m_last_cell_hovered.row + y_offset) && column == (m_last_cell_hovered.column + x_offset)) fill_color = Color::Green; @@ -258,9 +258,9 @@ Optional BoardWidget::get_row_and_column_for_point(int x, i void BoardWidget::place_pattern(size_t row, size_t column) { int y_offset = 0; - for (auto line : m_selected_pattern->pattern()) { + for (auto const& line : m_selected_pattern->pattern()) { int x_offset = 0; - for (auto c : line) { + for (auto c : line.bytes_as_string_view()) { if (c == 'O' && (row + y_offset) < m_board->rows() && (column + x_offset) < m_board->columns()) toggle_cell(row + y_offset, column + x_offset); x_offset++; @@ -276,122 +276,122 @@ void BoardWidget::place_pattern(size_t row, size_t column) void BoardWidget::setup_patterns() { - auto add_pattern = [&](DeprecatedString name, NonnullOwnPtr pattern) { - auto action = GUI::Action::create(move(name), [this, pattern = pattern.ptr()](const GUI::Action&) { + auto add_pattern = [&](auto name, NonnullOwnPtr pattern) { + auto action = GUI::Action::create(name, [this, pattern = pattern.ptr()](const GUI::Action&) { on_pattern_selection(pattern); }); pattern->set_action(action); m_patterns.append(move(pattern)); }; - Vector blinker = { - "OOO" + Vector blinker = { + "OOO"_string }; - Vector toad = { - ".OOO", - "OOO." + Vector toad = { + ".OOO"_string, + "OOO."_string }; - Vector glider = { - ".O.", - "..O", - "OOO", + Vector glider = { + ".O."_string, + "..O"_string, + "OOO"_string, }; - Vector lightweight_spaceship = { - ".OO..", - "OOOO.", - "OO.OO", - "..OO." + Vector lightweight_spaceship = { + ".OO.."_string, + "OOOO."_string, + "OO.OO"_string, + "..OO."_string }; - Vector middleweight_spaceship = { - ".OOOOO", - "O....O", - ".....O", - "O...O.", - "..O..." + Vector middleweight_spaceship = { + ".OOOOO"_string, + "O....O"_string, + ".....O"_string, + "O...O."_string, + "..O..."_string }; - Vector heavyweight_spaceship = { - "..OO...", - "O....O.", - "......O", - "O.....O", - ".OOOOOO" + Vector heavyweight_spaceship = { + "..OO..."_string, + "O....O."_string, + "......O"_string, + "O.....O"_string, + ".OOOOOO"_string }; - Vector infinite_1 = { "OOOOOOOO.OOOOO...OOO......OOOOOOO.OOOOO" }; + Vector infinite_1 = { "OOOOOOOO.OOOOO...OOO......OOOOOOO.OOOOO"_string }; - Vector infinite_2 = { - "......O.", - "....O.OO", - "....O.O.", - "....O...", - "..O.....", - "O.O....." + Vector infinite_2 = { + "......O."_string, + "....O.OO"_string, + "....O.O."_string, + "....O..."_string, + "..O....."_string, + "O.O....."_string }; - Vector infinite_3 = { - "OOO.O", - "O....", - "...OO", - ".OO.O", - "O.O.O" + Vector infinite_3 = { + "OOO.O"_string, + "O...."_string, + "...OO"_string, + ".OO.O"_string, + "O.O.O"_string }; - Vector simkin_glider_gun = { - "OO.....OO........................", - "OO.....OO........................", - ".................................", - "....OO...........................", - "....OO...........................", - ".................................", - ".................................", - ".................................", - ".................................", - "......................OO.OO......", - ".....................O.....O.....", - ".....................O......O..OO", - ".....................OOO...O...OO", - "..........................O......", - ".................................", - ".................................", - ".................................", - "....................OO...........", - "....................O............", - ".....................OOO.........", - ".......................O........." + Vector simkin_glider_gun = { + "OO.....OO........................"_string, + "OO.....OO........................"_string, + "................................."_string, + "....OO..........................."_string, + "....OO..........................."_string, + "................................."_string, + "................................."_string, + "................................."_string, + "................................."_string, + "......................OO.OO......"_string, + ".....................O.....O....."_string, + ".....................O......O..OO"_string, + ".....................OOO...O...OO"_string, + "..........................O......"_string, + "................................."_string, + "................................."_string, + "................................."_string, + "....................OO..........."_string, + "....................O............"_string, + ".....................OOO........."_string, + ".......................O........."_string }; - Vector gosper_glider_gun = { - "........................O...........", - "......................O.O...........", - "............OO......OO............OO", - "...........O...O....OO............OO", - "OO........O.....O...OO..............", - "OO........O...O.OO....O.O...........", - "..........O.....O.......O...........", - "...........O...O....................", - "............OO......................" + Vector gosper_glider_gun = { + "........................O..........."_string, + "......................O.O..........."_string, + "............OO......OO............OO"_string, + "...........O...O....OO............OO"_string, + "OO........O.....O...OO.............."_string, + "OO........O...O.OO....O.O..........."_string, + "..........O.....O.......O..........."_string, + "...........O...O...................."_string, + "............OO......................"_string }; - Vector r_pentomino = { - ".OO", - "OO.", - ".O." + Vector r_pentomino = { + ".OO"_string, + "OO."_string, + ".O."_string }; - Vector diehard = { - "......O.", - "OO......", - ".O...OOO" + Vector diehard = { + "......O."_string, + "OO......"_string, + ".O...OOO"_string }; - Vector acorn = { - ".O.....", - "...O...", - "OO..OOO" + Vector acorn = { + ".O....."_string, + "...O..."_string, + "OO..OOO"_string }; add_pattern("Blinker", make(move(blinker))); diff --git a/Userland/Games/GameOfLife/Pattern.cpp b/Userland/Games/GameOfLife/Pattern.cpp index 10b4f8f88e..5aef45ba50 100644 --- a/Userland/Games/GameOfLife/Pattern.cpp +++ b/Userland/Games/GameOfLife/Pattern.cpp @@ -6,15 +6,14 @@ */ #include "Pattern.h" -#include #include #include #include #include -Pattern::Pattern(Vector pattern) +Pattern::Pattern(Vector&& pattern) + : m_pattern(move(pattern)) { - m_pattern = move(pattern); } void Pattern::set_action(GUI::Action* action) @@ -24,13 +23,13 @@ void Pattern::set_action(GUI::Action* action) void Pattern::rotate_clockwise() { - Vector rotated; - for (size_t i = 0; i < m_pattern.first().length(); i++) { + Vector rotated; + for (size_t i = 0; i < m_pattern.first().bytes_as_string_view().length(); i++) { StringBuilder builder; for (int j = m_pattern.size() - 1; j >= 0; j--) { - builder.append(m_pattern.at(j).substring(i, 1)); + builder.append(m_pattern.at(j).bytes_as_string_view().substring_view(i, 1)); } - rotated.append(builder.to_deprecated_string()); + rotated.append(MUST(builder.to_string())); } m_pattern = move(rotated); } diff --git a/Userland/Games/GameOfLife/Pattern.h b/Userland/Games/GameOfLife/Pattern.h index e603d1dde2..5f7aa90b97 100644 --- a/Userland/Games/GameOfLife/Pattern.h +++ b/Userland/Games/GameOfLife/Pattern.h @@ -14,13 +14,13 @@ class Pattern final { public: - Pattern(Vector); - Vector pattern() { return m_pattern; } + Pattern(Vector&&); + Vector pattern() const { return m_pattern; } GUI::Action* action() { return m_action; } void set_action(GUI::Action*); void rotate_clockwise(); private: RefPtr m_action; - Vector m_pattern; + Vector m_pattern; };