mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-09 03:23:24 -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
|
|
@ -24,6 +24,7 @@ CardZone::CardZone(CardZoneLogic *_logic, QGraphicsItem *parent)
|
|||
connect(logic, &CardZoneLogic::cardCountChanged, this, &CardZone::invalidateItems);
|
||||
connect(logic, &CardZoneLogic::reorganizeCards, this, &CardZone::invalidateItems);
|
||||
connect(logic, &CardZoneLogic::cardAdded, this, &CardZone::onCardAdded);
|
||||
connect(logic, &CardZoneLogic::createCardRequested, this, &CardZone::onCreateCardRequested);
|
||||
connect(logic, &CardZoneLogic::setGraphicsVisibility, this, [this](bool v) { this->setVisible(v); });
|
||||
connect(logic, &CardZoneLogic::updateGraphics, this, [this]() { update(); });
|
||||
connect(logic, &CardZoneLogic::reorganizeCards, this, &CardZone::reorganizeCards);
|
||||
|
|
@ -59,6 +60,14 @@ void CardZone::onCardAdded(CardState *addedCard)
|
|||
addedItem->update();
|
||||
}
|
||||
|
||||
void CardZone::onCreateCardRequested(const ServerInfo_Card &cardInfo, bool reorganize)
|
||||
{
|
||||
CardRef cardRef = {QString::fromStdString(cardInfo.name()), QString::fromStdString(cardInfo.provider_id())};
|
||||
auto *card = new CardItem(getLogic()->getPlayer(), nullptr, cardRef, cardInfo.id());
|
||||
card->processCardInfo(cardInfo);
|
||||
getLogic()->addCard(card->getState(), reorganize, cardInfo.x(), cardInfo.y());
|
||||
}
|
||||
|
||||
void CardZone::retranslateUi()
|
||||
{
|
||||
for (auto *card : cardItems()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue