summaryrefslogtreecommitdiff
path: root/Userland/Games/Spider
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2023-03-06 14:17:01 +0100
committerAndreas Kling <kling@serenityos.org>2023-03-06 23:46:35 +0100
commit8a48246ed1a93983668a25f5b9b0af0e745e3f04 (patch)
treedd98425d119f79e0160bf19951f96a4a30276cbb /Userland/Games/Spider
parent104be6c8ace8d56f66a89b570cdd615e74d22aa8 (diff)
downloadserenity-8a48246ed1a93983668a25f5b9b0af0e745e3f04.zip
Everywhere: Stop using NonnullRefPtrVector
This class had slightly confusing semantics and the added weirdness doesn't seem worth it just so we can say "." instead of "->" when iterating over a vector of NNRPs. This patch replaces NonnullRefPtrVector<T> with Vector<NNRP<T>>.
Diffstat (limited to 'Userland/Games/Spider')
-rw-r--r--Userland/Games/Spider/Game.cpp42
-rw-r--r--Userland/Games/Spider/Game.h2
2 files changed, 22 insertions, 22 deletions
diff --git a/Userland/Games/Spider/Game.cpp b/Userland/Games/Spider/Game.cpp
index 0c624db7bd..d474186e43 100644
--- a/Userland/Games/Spider/Game.cpp
+++ b/Userland/Games/Spider/Game.cpp
@@ -50,7 +50,7 @@ void Game::setup(Mode mode)
on_game_end(GameOverReason::NewGame, m_score);
for (auto& stack : stacks())
- stack.clear();
+ stack->clear();
m_new_game_animation_pile = 0;
@@ -91,7 +91,7 @@ void Game::perform_undo()
if (!m_last_move.was_visible)
m_last_move.from->peek().set_upside_down(true);
- NonnullRefPtrVector<Card> cards;
+ Vector<NonnullRefPtr<Card>> cards;
for (size_t i = 0; i < m_last_move.card_count; i++)
cards.append(m_last_move.to->pop());
for (ssize_t i = m_last_move.card_count - 1; i >= 0; i--)
@@ -146,18 +146,18 @@ void Game::detect_full_stacks()
Color color;
for (size_t i = current_pile.stack().size(); i > 0; i--) {
auto& card = current_pile.stack().at(i - 1);
- if (card.is_upside_down())
+ if (card->is_upside_down())
break;
if (!started) {
- if (card.rank() != Cards::Rank::Ace)
+ if (card->rank() != Cards::Rank::Ace)
break;
started = true;
- color = card.color();
- } else if (to_underlying(card.rank()) != last_value + 1 || card.color() != color) {
+ color = card->color();
+ } else if (to_underlying(card->rank()) != last_value + 1 || card->color() != color) {
break;
- } else if (card.rank() == Cards::Rank::King) {
+ } else if (card->rank() == Cards::Rank::King) {
// we have a full set
auto original_current_rect = current_pile.bounding_box();
@@ -177,7 +177,7 @@ void Game::detect_full_stacks()
on_undo_availability_change(false);
}
- last_value = to_underlying(card.rank());
+ last_value = to_underlying(card->rank());
}
}
@@ -212,24 +212,24 @@ void Game::paint_event(GUI::PaintEvent& event)
if (is_moving_cards()) {
for (auto& card : moving_cards())
- card.clear(painter, background_color);
+ card->clear(painter, background_color);
}
for (auto& stack : stacks()) {
- stack.paint(painter, background_color);
+ stack->paint(painter, background_color);
}
if (is_moving_cards()) {
for (auto& card : moving_cards()) {
- card.paint(painter);
- card.save_old_position();
+ card->paint(painter);
+ card->save_old_position();
}
}
if (!m_mouse_down) {
if (is_moving_cards()) {
for (auto& card : moving_cards())
- card.set_moving(false);
+ card->set_moving(false);
}
clear_moving_cards();
}
@@ -255,15 +255,15 @@ void Game::mousedown_event(GUI::MouseEvent& event)
auto click_location = event.position();
for (auto& to_check : stacks()) {
- if (to_check.type() == CardStack::Type::Waste)
+ if (to_check->type() == CardStack::Type::Waste)
continue;
- if (to_check.bounding_box().contains(click_location)) {
- if (to_check.type() == CardStack::Type::Stock) {
+ if (to_check->bounding_box().contains(click_location)) {
+ if (to_check->type() == CardStack::Type::Stock) {
start_timer_if_necessary();
draw_cards();
- } else if (!to_check.is_empty()) {
- auto& top_card = to_check.peek();
+ } else if (!to_check->is_empty()) {
+ auto& top_card = to_check->peek();
if (top_card.is_upside_down()) {
if (top_card.rect().contains(click_location)) {
@@ -312,7 +312,7 @@ void Game::mouseup_event(GUI::MouseEvent& event)
if (stack == moving_cards_source_stack())
continue;
- if (stack.is_allowed_to_push(moving_cards().at(0), moving_cards().size(), Cards::CardStack::MovementRule::Any) && !stack.is_empty()) {
+ if (stack->is_allowed_to_push(moving_cards().at(0), moving_cards().size(), Cards::CardStack::MovementRule::Any) && !stack->is_empty()) {
move_focused_cards(stack);
rebound = false;
@@ -361,8 +361,8 @@ void Game::mousemove_event(GUI::MouseEvent& event)
for (auto& to_intersect : moving_cards()) {
mark_intersecting_stacks_dirty(to_intersect);
- to_intersect.rect().translate_by(dx, dy);
- update(to_intersect.rect());
+ to_intersect->rect().translate_by(dx, dy);
+ update(to_intersect->rect());
}
m_mouse_down_location = click_location;
diff --git a/Userland/Games/Spider/Game.h b/Userland/Games/Spider/Game.h
index cdf6d9bd61..9223e9eff9 100644
--- a/Userland/Games/Spider/Game.h
+++ b/Userland/Games/Spider/Game.h
@@ -104,7 +104,7 @@ private:
Mode m_mode { Mode::SingleSuit };
LastMove m_last_move;
- NonnullRefPtrVector<Card> m_new_deck;
+ Vector<NonnullRefPtr<Card>> m_new_deck;
Gfx::IntPoint m_mouse_down_location;
bool m_mouse_down { false };