1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:47:35 +00:00

LibCards+Games+GamesSettings: Return ErrorOr from CardStack::push()

Very few of these calls can propagate their errors yet, but one step at
a time. :^)
This commit is contained in:
Sam Atkins 2023-01-20 12:45:02 +00:00 committed by Linus Groh
parent 83687f85df
commit 8b3a94ffbc
6 changed files with 32 additions and 30 deletions

View file

@ -88,7 +88,7 @@ void CardGame::drop_cards_on_stack(Cards::CardStack& stack, CardStack::MovementR
VERIFY(stack.is_allowed_to_push(m_moving_cards.at(0), m_moving_cards.size(), movement_rule));
for (auto& to_intersect : moving_cards()) {
mark_intersecting_stacks_dirty(to_intersect);
stack.push(to_intersect);
stack.push(to_intersect).release_value_but_fixme_should_propagate_errors();
(void)moving_cards_source_stack()->pop();
}

View file

@ -290,7 +290,7 @@ bool CardStack::make_top_card_visible()
return false;
}
void CardStack::push(NonnullRefPtr<Card> card)
ErrorOr<void> CardStack::push(NonnullRefPtr<Card> card)
{
auto top_most_position = m_stack_positions.is_empty() ? m_position : m_stack_positions.last();
@ -306,9 +306,10 @@ void CardStack::push(NonnullRefPtr<Card> card)
card->set_position(top_most_position);
m_stack.append(card);
m_stack_positions.append(top_most_position);
TRY(m_stack.try_append(card));
TRY(m_stack_positions.try_append(top_most_position));
calculate_bounding_box();
return {};
}
NonnullRefPtr<Card> CardStack::pop()
@ -323,15 +324,16 @@ NonnullRefPtr<Card> CardStack::pop()
return card;
}
void CardStack::take_all(CardStack& stack)
ErrorOr<void> CardStack::take_all(CardStack& stack)
{
while (!m_stack.is_empty()) {
auto card = m_stack.take_first();
m_stack_positions.take_first();
stack.push(move(card));
TRY(stack.push(move(card)));
}
calculate_bounding_box();
return {};
}
void CardStack::calculate_bounding_box()

View file

@ -43,9 +43,9 @@ public:
bool make_top_card_visible(); // Returns true if the card was flipped.
void push(NonnullRefPtr<Card> card);
ErrorOr<void> push(NonnullRefPtr<Card>);
NonnullRefPtr<Card> pop();
void take_all(CardStack&);
ErrorOr<void> take_all(CardStack&);
void rebound_cards();
bool is_allowed_to_push(Card const&, size_t stack_size = 1, MovementRule movement_rule = MovementRule::Alternating) const;