[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:
BruebachL 2026-10-31 18:44:15 +01:00 • committed by GitHub
parent 7ca23430cd
commit 78964779c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 159 additions and 137 deletions

View file

@ -1,5 +1,7 @@
#include "card_state.h"
#include "../zones/card_zone_logic.h"
#include <QSharedPointer>
#include <libcockatrice/card/card_info.h>
#include <libcockatrice/card/database/card_database_manager.h>
@ -206,7 +208,33 @@ void CardState::setAttachedTo(CardState *_attachedTo)
if (attachedTo == _attachedTo) {
return;
}
if (attachedTo != nullptr) {
attachedTo->removeAttachedCard(this);
}
setGridPoint(QPoint(-1, getGridPoint().y()));
attachedTo = _attachedTo;
emit attachedToChanged(_attachedTo);
emit stateChanged();
if (attachedTo != 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. The graphics item that owns this state handles the teardown in that case.
CardZoneLogic *parentZone = attachedTo->getZone();
if (parentZone == nullptr) {
return;
}
emit parentZone->cardAdded(this);
attachedTo->addAttachedCard(this);
if (getZone() != parentZone) {
parentZone->reorganizeCards();
}
} else if (getZone() != nullptr) {
emit getZone() -> cardAdded(this);
}
if (getZone() != nullptr) {
getZone()->reorganizeCards();
}
}