mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 14:27:35 +00:00
LibCards+Games: Return ErrorOr from CardStack::add_all_grabbed_cards()
...and CardGame::pick_up_cards_from_stack() which is its only caller.
This commit is contained in:
parent
c7c4d70f6e
commit
ccabc8e930
6 changed files with 16 additions and 13 deletions
|
@ -52,10 +52,11 @@ Gfx::IntRect CardGame::moving_cards_bounds() const
|
|||
return m_moving_cards.first().rect().united(m_moving_cards.last().rect());
|
||||
}
|
||||
|
||||
void CardGame::pick_up_cards_from_stack(Cards::CardStack& stack, Gfx::IntPoint click_location, CardStack::MovementRule movement_rule)
|
||||
ErrorOr<void> CardGame::pick_up_cards_from_stack(Cards::CardStack& stack, Gfx::IntPoint click_location, CardStack::MovementRule movement_rule)
|
||||
{
|
||||
stack.add_all_grabbed_cards(click_location, m_moving_cards, movement_rule);
|
||||
TRY(stack.add_all_grabbed_cards(click_location, m_moving_cards, movement_rule));
|
||||
m_moving_cards_source_stack = stack;
|
||||
return {};
|
||||
}
|
||||
|
||||
RefPtr<CardStack> CardGame::find_stack_to_drop_on(CardStack::MovementRule movement_rule) const
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
NonnullRefPtrVector<Card> const& moving_cards() const { return m_moving_cards; }
|
||||
Gfx::IntRect moving_cards_bounds() const;
|
||||
RefPtr<CardStack> moving_cards_source_stack() const { return m_moving_cards_source_stack; }
|
||||
void pick_up_cards_from_stack(CardStack&, Gfx::IntPoint click_location, CardStack::MovementRule);
|
||||
ErrorOr<void> pick_up_cards_from_stack(CardStack&, Gfx::IntPoint click_location, CardStack::MovementRule);
|
||||
RefPtr<CardStack> find_stack_to_drop_on(CardStack::MovementRule) const;
|
||||
ErrorOr<void> drop_cards_on_stack(CardStack&, CardStack::MovementRule);
|
||||
void clear_moving_cards();
|
||||
|
|
|
@ -121,7 +121,7 @@ void CardStack::rebound_cards()
|
|||
card.set_position(m_stack_positions.at(card_index++));
|
||||
}
|
||||
|
||||
void CardStack::add_all_grabbed_cards(Gfx::IntPoint click_location, NonnullRefPtrVector<Card>& grabbed, MovementRule movement_rule)
|
||||
ErrorOr<void> CardStack::add_all_grabbed_cards(Gfx::IntPoint click_location, NonnullRefPtrVector<Card>& grabbed, MovementRule movement_rule)
|
||||
{
|
||||
VERIFY(grabbed.is_empty());
|
||||
|
||||
|
@ -129,9 +129,9 @@ void CardStack::add_all_grabbed_cards(Gfx::IntPoint click_location, NonnullRefPt
|
|||
auto& top_card = peek();
|
||||
if (top_card.rect().contains(click_location)) {
|
||||
top_card.set_moving(true);
|
||||
grabbed.append(top_card);
|
||||
TRY(grabbed.try_append(top_card));
|
||||
}
|
||||
return;
|
||||
return {};
|
||||
}
|
||||
|
||||
RefPtr<Card> last_intersect;
|
||||
|
@ -144,22 +144,22 @@ void CardStack::add_all_grabbed_cards(Gfx::IntPoint click_location, NonnullRefPt
|
|||
last_intersect = card;
|
||||
} else if (!last_intersect.is_null()) {
|
||||
if (grabbed.is_empty()) {
|
||||
grabbed.append(*last_intersect);
|
||||
TRY(grabbed.try_append(*last_intersect));
|
||||
last_intersect->set_moving(true);
|
||||
}
|
||||
|
||||
if (card.is_upside_down()) {
|
||||
grabbed.clear();
|
||||
return;
|
||||
return {};
|
||||
}
|
||||
|
||||
card.set_moving(true);
|
||||
grabbed.append(card);
|
||||
TRY(grabbed.try_append(card));
|
||||
}
|
||||
}
|
||||
|
||||
if (grabbed.is_empty() && !last_intersect.is_null()) {
|
||||
grabbed.append(*last_intersect);
|
||||
TRY(grabbed.try_append(*last_intersect));
|
||||
last_intersect->set_moving(true);
|
||||
}
|
||||
|
||||
|
@ -198,6 +198,8 @@ void CardStack::add_all_grabbed_cards(Gfx::IntPoint click_location, NonnullRefPt
|
|||
}
|
||||
grabbed.clear();
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
bool CardStack::is_allowed_to_push(Card const& card, size_t stack_size, MovementRule movement_rule) const
|
||||
|
|
|
@ -49,7 +49,7 @@ public:
|
|||
void rebound_cards();
|
||||
|
||||
bool is_allowed_to_push(Card const&, size_t stack_size = 1, MovementRule movement_rule = MovementRule::Alternating) const;
|
||||
void add_all_grabbed_cards(Gfx::IntPoint click_location, NonnullRefPtrVector<Card>& grabbed, MovementRule movement_rule = MovementRule::Alternating);
|
||||
ErrorOr<void> add_all_grabbed_cards(Gfx::IntPoint click_location, NonnullRefPtrVector<Card>& grabbed, MovementRule movement_rule = MovementRule::Alternating);
|
||||
|
||||
bool preview_card(Gfx::IntPoint click_location);
|
||||
void clear_card_preview();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue