mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-08 19:13:25 -08:00
[Refactor] Move card item creation out of game logic (#7436)
* [Refactor] Move card item creation out of game logic * [Game] Rename signal to createCardRequested per review * [Game] Move attachment bookkeeping onto CardState CardState::setAttachedTo now maintains the attachedCards graph, resets the grid point and emits the zone events itself, so game logic no longer needs to reach into the CardItem graphics item. CardItem::setAttachedTo delegates to the state and keeps only the view teardown (deleteLater). --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
7ca23430cd
commit
78964779c6
20 changed files with 159 additions and 137 deletions
|
|
@ -89,14 +89,18 @@ 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);
|
||||
const QList<CardState *> &attachedStates = state->getAttachedCards();
|
||||
while (!attachedStates.isEmpty()) {
|
||||
auto *attachedItem = qobject_cast<CardItem *>(attachedStates.first()->parent());
|
||||
if (attachedItem == nullptr) {
|
||||
break;
|
||||
}
|
||||
attachedItem->setZone(nullptr); // so that it won't try to call reorganizeCards()
|
||||
attachedItem->setAttachedTo(nullptr);
|
||||
}
|
||||
|
||||
if (state->getAttachedTo() != nullptr) {
|
||||
state->getAttachedTo()->removeAttachedCard(this);
|
||||
state->getAttachedTo()->removeAttachedCard(state);
|
||||
state->setAttachedTo(nullptr);
|
||||
}
|
||||
}
|
||||
|
|
@ -225,36 +229,13 @@ void CardItem::setPT(const QString &_pt)
|
|||
|
||||
void CardItem::setAttachedTo(CardItem *_attachedTo)
|
||||
{
|
||||
if (state->getAttachedTo() != nullptr) {
|
||||
state->getAttachedTo()->removeAttachedCard(this);
|
||||
}
|
||||
CardState *newParent = _attachedTo == nullptr ? nullptr : _attachedTo->getState();
|
||||
state->setAttachedTo(newParent);
|
||||
|
||||
state->setGridPoint(QPoint(-1, state->getGridPoint().y()));
|
||||
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
|
||||
if (state->getAttachedTo()->getZone() == nullptr) {
|
||||
deleteLater();
|
||||
} else {
|
||||
emit state->getAttachedTo()->getZone()->cardAdded(state);
|
||||
state->getAttachedTo()->addAttachedCard(this);
|
||||
if (state->getZone() != state->getAttachedTo()->getZone()) {
|
||||
state->getAttachedTo()->getZone()->reorganizeCards();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 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
|
||||
if (state->getZone() == nullptr) {
|
||||
deleteLater();
|
||||
} else {
|
||||
emit state->getZone()->cardAdded(state);
|
||||
}
|
||||
}
|
||||
|
||||
if (state->getZone() != nullptr) {
|
||||
state->getZone()->reorganizeCards();
|
||||
// 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
|
||||
if (newParent != nullptr ? newParent->getZone() == nullptr : state->getZone() == nullptr) {
|
||||
deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue