mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 10:01:13 +09:00
LibCards+Spider: Move ensure_top_card_is_visible()
logic to CardStack
This commit is contained in:
parent
b26383bc6c
commit
12612703f9
Notes:
sideshowbarker
2024-07-17 06:05:58 +09:00
Author: https://github.com/AtkinsSJ
Commit: 12612703f9
Pull-request: https://github.com/SerenityOS/serenity/pull/15388
4 changed files with 19 additions and 15 deletions
|
@ -115,18 +115,6 @@ void Game::mark_intersecting_stacks_dirty(Card& intersecting_card)
|
||||||
update(intersecting_card.rect());
|
update(intersecting_card.rect());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::ensure_top_card_is_visible(NonnullRefPtr<CardStack> stack)
|
|
||||||
{
|
|
||||||
if (stack->is_empty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
auto& top_card = stack->peek();
|
|
||||||
if (top_card.is_upside_down()) {
|
|
||||||
top_card.set_upside_down(false);
|
|
||||||
update(top_card.rect());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Game::detect_full_stacks()
|
void Game::detect_full_stacks()
|
||||||
{
|
{
|
||||||
auto& completed_stack = stack_at_location(Completed);
|
auto& completed_stack = stack_at_location(Completed);
|
||||||
|
@ -160,7 +148,8 @@ void Game::detect_full_stacks()
|
||||||
update(original_current_rect);
|
update(original_current_rect);
|
||||||
update(completed_stack.bounding_box());
|
update(completed_stack.bounding_box());
|
||||||
|
|
||||||
ensure_top_card_is_visible(current_pile);
|
if (current_pile.make_top_card_visible())
|
||||||
|
update(current_pile.peek().rect());
|
||||||
|
|
||||||
update_score(101);
|
update_score(101);
|
||||||
}
|
}
|
||||||
|
@ -283,7 +272,8 @@ void Game::move_focused_cards(CardStack& stack)
|
||||||
|
|
||||||
detect_full_stacks();
|
detect_full_stacks();
|
||||||
|
|
||||||
ensure_top_card_is_visible(*m_focused_stack);
|
if (m_focused_stack->make_top_card_visible())
|
||||||
|
update(m_focused_stack->peek().rect());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::mouseup_event(GUI::MouseEvent& event)
|
void Game::mouseup_event(GUI::MouseEvent& event)
|
||||||
|
|
|
@ -71,7 +71,6 @@ private:
|
||||||
void update_score(int delta);
|
void update_score(int delta);
|
||||||
void draw_cards();
|
void draw_cards();
|
||||||
void mark_intersecting_stacks_dirty(Card& intersecting_card);
|
void mark_intersecting_stacks_dirty(Card& intersecting_card);
|
||||||
void ensure_top_card_is_visible(NonnullRefPtr<CardStack> stack);
|
|
||||||
void detect_full_stacks();
|
void detect_full_stacks();
|
||||||
void detect_victory();
|
void detect_victory();
|
||||||
void move_focused_cards(CardStack& stack);
|
void move_focused_cards(CardStack& stack);
|
||||||
|
|
|
@ -227,6 +227,20 @@ bool CardStack::is_allowed_to_push(Card const& card, size_t stack_size, Movement
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CardStack::make_top_card_visible()
|
||||||
|
{
|
||||||
|
if (is_empty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
auto& top_card = peek();
|
||||||
|
if (top_card.is_upside_down()) {
|
||||||
|
top_card.set_upside_down(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void CardStack::push(NonnullRefPtr<Card> card)
|
void CardStack::push(NonnullRefPtr<Card> card)
|
||||||
{
|
{
|
||||||
auto top_most_position = m_stack_positions.is_empty() ? m_position : m_stack_positions.last();
|
auto top_most_position = m_stack_positions.is_empty() ? m_position : m_stack_positions.last();
|
||||||
|
|
|
@ -43,6 +43,7 @@ public:
|
||||||
Gfx::IntRect const& bounding_box() const { return m_bounding_box; }
|
Gfx::IntRect const& bounding_box() const { return m_bounding_box; }
|
||||||
|
|
||||||
void set_focused(bool focused) { m_focused = focused; }
|
void set_focused(bool focused) { m_focused = focused; }
|
||||||
|
bool make_top_card_visible(); // Returns true if the card was flipped.
|
||||||
|
|
||||||
void push(NonnullRefPtr<Card> card);
|
void push(NonnullRefPtr<Card> card);
|
||||||
NonnullRefPtr<Card> pop();
|
NonnullRefPtr<Card> pop();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue