[Refactor] Move the attachment graph and card view teardown onto CardState (#7428)

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2026-10-31 18:44:13 +01:00 • committed by GitHub
parent 47c90cda10
commit 2335e064ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 54 additions and 19 deletions

View file

@ -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