mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-08 02:53:25 -08:00
[Refactor] Move the attachment graph and card view teardown onto CardState
This commit is contained in:
parent
cea80b0898
commit
dd04eed6d2
7 changed files with 54 additions and 19 deletions
|
|
@ -65,12 +65,13 @@ CardItem::CardItem(PlayerLogic *_owner,
|
|||
});
|
||||
|
||||
connect(state, &CardState::stateReset, this, [this] {
|
||||
attachedCards.clear();
|
||||
if (scene()) {
|
||||
static_cast<GameScene *>(scene())->unregisterAnimationItem(this);
|
||||
}
|
||||
update();
|
||||
});
|
||||
|
||||
connect(state, &CardState::viewDeleteRequested, this, &CardItem::deleteLater);
|
||||
}
|
||||
|
||||
void CardItem::prepareDelete()
|
||||
|
|
@ -84,6 +85,7 @@ void CardItem::prepareDelete()
|
|||
owner = nullptr;
|
||||
}
|
||||
|
||||
const QList<CardItem *> &attachedCards = state->getAttachedCards();
|
||||
while (!attachedCards.isEmpty()) {
|
||||
attachedCards.first()->setZone(nullptr); // so that it won't try to call reorganizeCards()
|
||||
attachedCards.first()->setAttachedTo(nullptr);
|
||||
|
|
@ -224,7 +226,7 @@ void CardItem::setAttachedTo(CardItem *_attachedTo)
|
|||
}
|
||||
|
||||
state->setGridPoint(QPoint(-1, state->getGridPoint().y()));
|
||||
state->setAttachedTo(_attachedTo);
|
||||
state->setAttachedTo(_attachedTo == nullptr ? nullptr : _attachedTo->getState());
|
||||
if (state->getAttachedTo() != nullptr) {
|
||||
// If the zone is being torn down, it might already be null by the time a card tries to un-attach all its
|
||||
// attached cards
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ class CardItem : public AbstractCardItem
|
|||
Q_OBJECT
|
||||
private:
|
||||
CardDragItem *dragItem;
|
||||
QList<CardItem *> attachedCards;
|
||||
|
||||
void prepareDelete();
|
||||
void handleClickedToPlay(bool shiftHeld);
|
||||
|
|
@ -116,22 +115,22 @@ public:
|
|||
{
|
||||
state->setDestroyOnZoneChange(_destroy);
|
||||
}
|
||||
[[nodiscard]] CardItem *getAttachedTo() const
|
||||
[[nodiscard]] CardState *getAttachedTo() const
|
||||
{
|
||||
return state->getAttachedTo();
|
||||
}
|
||||
void setAttachedTo(CardItem *_attachedTo);
|
||||
void addAttachedCard(CardItem *card)
|
||||
{
|
||||
attachedCards.append(card);
|
||||
state->addAttachedCard(card);
|
||||
}
|
||||
void removeAttachedCard(CardItem *card)
|
||||
{
|
||||
attachedCards.removeOne(card);
|
||||
state->removeAttachedCard(card);
|
||||
}
|
||||
[[nodiscard]] const QList<CardItem *> &getAttachedCards() const
|
||||
{
|
||||
return attachedCards;
|
||||
return state->getAttachedCards();
|
||||
}
|
||||
void resetState(bool keepAnnotations = false);
|
||||
void processCardInfo(const ServerInfo_Card &_info);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue