[Refactor] Give graphics zones a card item cache and own card placement

This commit is contained in:
Lukas Brübach 2026-10-06 17:47:23 +02:00 • committed by GitHub
parent 8347258075
commit cea80b0898
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 111 additions and 74 deletions

View file

@ -5,9 +5,9 @@ namespace CardZoneAlgorithms
{
/**
* Shared insertion logic for zones where cards become visible on add and follow
* the standard pattern: clamp index, insert, clear identity if contents unknown,
* reset state, show card.
* Shared insertion logic for zones where cards follow the standard pattern:
* clamp index, insert, clear identity if contents unknown, reset state.
* Visibility and parenting are handled by the graphics zone's onCardAdded().
*
* Zones with different post-add behavior (signal connections, positional resets,
* hidden cards, or coordinate-based placement) should NOT use this — implement
@ -18,8 +18,7 @@ namespace CardZoneAlgorithms
*
* @tparam CardList Must provide: size() -> int, insert(int, CardType*),
* getContentsKnown() -> bool
* @tparam CardType Must provide: setId(int), setCardRef(CardRefType),
* resetState(bool), setVisible(bool)
* @tparam CardType Must provide: setId(int), setCardRef(CardRefType), resetState(bool)
* @param keepAnnotations Forwarded to card->resetState(). Stack-like zones preserve
* annotations across zone transitions; hand-like zones clear them.
*/
@ -37,7 +36,6 @@ void addCardToList(CardList &cards, CardType *card, int x, bool keepAnnotations)
}
card->resetState(keepAnnotations);
card->setVisible(true);
}
} // namespace CardZoneAlgorithms

View file

@ -53,6 +53,7 @@ public:
void rawInsertCard(CardItem *card, int index)
{
cards.insert(index, card);
emit cardCountChanged();
}
[[nodiscard]] const CardList &getCards() const
@ -63,6 +64,7 @@ public:
void sortCards(const QList<CardList::SortOption> &options)
{
cards.sortBy(options);
emit cardCountChanged();
}
[[nodiscard]] QString getName() const
{

View file

@ -18,13 +18,12 @@ PileZoneLogic::PileZoneLogic(PlayerLogic *_player,
void PileZoneLogic::addCardImpl(CardItem *card, int x, int /*y*/)
{
connect(card, &CardItem::sigPixmapUpdated, this, &PileZoneLogic::callUpdate);
connect(card->getState(), &CardState::cardPixmapUpdated, this, &PileZoneLogic::callUpdate);
// if x is negative set it to add at end
if (x < 0 || x >= cards.size()) {
x = cards.size();
}
cards.insert(x, card);
card->setPos(0, 0);
if (!contentsKnown()) {
card->setCardRef({});
card->setId(-1);
@ -33,6 +32,5 @@ void PileZoneLogic::addCardImpl(CardItem *card, int x, int /*y*/)
cards.at(x + 1)->setCardRef({});
}
}
card->setVisible(false);
card->resetState();
}

View file

@ -29,7 +29,6 @@ void TableZoneLogic::addCardImpl(CardItem *card, int _x, int _y)
card->setDoesntUntap(true);
}
card->setGridPoint(QPoint(_x, _y));
card->setVisible(true);
}
CardItem *TableZoneLogic::takeCard(int position, int cardId, bool toNewZone)

View file

@ -168,6 +168,7 @@ void ZoneViewZoneLogic::clearCards()
card->deleteLater();
}
cards.clear();
emit cardCountChanged();
}
void ZoneViewZoneLogic::setWriteableRevealZone(bool _writeableRevealZone)