mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-16 07:22:16 -07:00
Refactor: use ExactCard to represent specific printings (#6049)
* Create new class * Update CardInfo and CardDatabase * Use new class instead of CardInfoPtr * fix cmake
This commit is contained in:
parent
4a2a646943
commit
ae2c55c33b
79 changed files with 715 additions and 642 deletions
|
|
@ -367,36 +367,40 @@ QModelIndex DeckListModel::findCard(const QString &cardName,
|
|||
|
||||
QModelIndex DeckListModel::addPreferredPrintingCard(const QString &cardName, const QString &zoneName, bool abAddAnyway)
|
||||
{
|
||||
return addCard(cardName, CardDatabaseManager::getInstance()->getPreferredPrinting(cardName), zoneName, abAddAnyway);
|
||||
}
|
||||
ExactCard card = CardDatabaseManager::getInstance()->getCard({cardName});
|
||||
|
||||
QModelIndex DeckListModel::addCard(const QString &cardName,
|
||||
const PrintingInfo &printingInfo,
|
||||
const QString &zoneName,
|
||||
bool abAddAnyway)
|
||||
{
|
||||
CardInfoPtr cardInfo = CardDatabaseManager::getInstance()->getCard({cardName, printingInfo.getUuid()});
|
||||
|
||||
if (cardInfo == nullptr) {
|
||||
if (!card) {
|
||||
if (abAddAnyway) {
|
||||
// We need to keep this card added no matter what
|
||||
// This is usually called from tab_deck_editor
|
||||
// So we'll create a new CardInfo with the name
|
||||
// and default values for all fields
|
||||
cardInfo = CardInfo::newInstance(cardName);
|
||||
card = ExactCard(CardInfo::newInstance(cardName));
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
return addCard(card, zoneName);
|
||||
}
|
||||
|
||||
QModelIndex DeckListModel::addCard(const ExactCard &card, const QString &zoneName)
|
||||
{
|
||||
if (!card) {
|
||||
return {};
|
||||
}
|
||||
|
||||
InnerDecklistNode *zoneNode = createNodeIfNeeded(zoneName, root);
|
||||
|
||||
CardInfoPtr cardInfo = card.getCardPtr();
|
||||
PrintingInfo printingInfo = card.getPrinting();
|
||||
|
||||
QString groupCriteria = getGroupCriteriaForCard(cardInfo);
|
||||
InnerDecklistNode *groupNode = createNodeIfNeeded(groupCriteria, zoneNode);
|
||||
|
||||
const QModelIndex parentIndex = nodeToIndex(groupNode);
|
||||
auto *cardNode = dynamic_cast<DecklistModelCardNode *>(groupNode->findCardChildByNameProviderIdAndNumber(
|
||||
cardName, printingInfo.getUuid(), printingInfo.getProperty("num")));
|
||||
card.getName(), printingInfo.getUuid(), printingInfo.getProperty("num")));
|
||||
const auto cardSetName = printingInfo.getSet().isNull() ? "" : printingInfo.getSet()->getCorrectedShortName();
|
||||
|
||||
if (!cardNode) {
|
||||
|
|
@ -538,9 +542,9 @@ void DeckListModel::setDeckList(DeckLoader *_deck)
|
|||
rebuildTree();
|
||||
}
|
||||
|
||||
QList<CardInfoPtr> DeckListModel::getCardsAsCardInfoPtrs() const
|
||||
QList<ExactCard> DeckListModel::getCards() const
|
||||
{
|
||||
QList<CardInfoPtr> cards;
|
||||
QList<ExactCard> cards;
|
||||
DeckList *decklist = getDeckList();
|
||||
if (!decklist) {
|
||||
return cards;
|
||||
|
|
@ -558,9 +562,9 @@ QList<CardInfoPtr> DeckListModel::getCardsAsCardInfoPtrs() const
|
|||
if (!currentCard)
|
||||
continue;
|
||||
for (int k = 0; k < currentCard->getNumber(); ++k) {
|
||||
CardInfoPtr info = CardDatabaseManager::getInstance()->getCard(currentCard->toCardRef());
|
||||
if (info) {
|
||||
cards.append(info);
|
||||
ExactCard card = CardDatabaseManager::getInstance()->getCard(currentCard->toCardRef());
|
||||
if (card) {
|
||||
cards.append(card);
|
||||
} else {
|
||||
qDebug() << "Card not found in database!";
|
||||
}
|
||||
|
|
@ -570,9 +574,9 @@ QList<CardInfoPtr> DeckListModel::getCardsAsCardInfoPtrs() const
|
|||
return cards;
|
||||
}
|
||||
|
||||
QList<CardInfoPtr> DeckListModel::getCardsAsCardInfoPtrsForZone(QString zoneName) const
|
||||
QList<ExactCard> DeckListModel::getCardsForZone(const QString &zoneName) const
|
||||
{
|
||||
QList<CardInfoPtr> cards;
|
||||
QList<ExactCard> cards;
|
||||
DeckList *decklist = getDeckList();
|
||||
if (!decklist) {
|
||||
return cards;
|
||||
|
|
@ -591,9 +595,9 @@ QList<CardInfoPtr> DeckListModel::getCardsAsCardInfoPtrsForZone(QString zoneName
|
|||
if (!currentCard)
|
||||
continue;
|
||||
for (int k = 0; k < currentCard->getNumber(); ++k) {
|
||||
CardInfoPtr info = CardDatabaseManager::getInstance()->getCard(currentCard->toCardRef());
|
||||
if (info) {
|
||||
cards.append(info);
|
||||
ExactCard card = CardDatabaseManager::getInstance()->getCard(currentCard->toCardRef());
|
||||
if (card) {
|
||||
cards.append(card);
|
||||
} else {
|
||||
qDebug() << "Card not found in database!";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef DECKLISTMODEL_H
|
||||
#define DECKLISTMODEL_H
|
||||
|
||||
#include "../game/cards/card_info.h"
|
||||
#include "../game/cards/exact_card.h"
|
||||
#include "decklist.h"
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
|
|
@ -111,10 +111,7 @@ public:
|
|||
const QString &providerId = "",
|
||||
const QString &cardNumber = "") const;
|
||||
QModelIndex addPreferredPrintingCard(const QString &cardName, const QString &zoneName, bool abAddAnyway);
|
||||
QModelIndex addCard(const ::QString &cardName,
|
||||
const PrintingInfo &printingInfo,
|
||||
const QString &zoneName,
|
||||
bool abAddAnyway = false);
|
||||
QModelIndex addCard(const ExactCard &card, const QString &zoneName);
|
||||
int findSortedInsertRow(InnerDecklistNode *parent, CardInfoPtr cardInfo) const;
|
||||
void sort(int column, Qt::SortOrder order) override;
|
||||
void cleanList();
|
||||
|
|
@ -123,8 +120,8 @@ public:
|
|||
return deckList;
|
||||
}
|
||||
void setDeckList(DeckLoader *_deck);
|
||||
QList<CardInfoPtr> getCardsAsCardInfoPtrs() const;
|
||||
QList<CardInfoPtr> getCardsAsCardInfoPtrsForZone(QString zoneName) const;
|
||||
QList<ExactCard> getCards() const;
|
||||
QList<ExactCard> getCardsForZone(const QString &zoneName) const;
|
||||
QList<QString> *getZones() const;
|
||||
void setActiveGroupCriteria(DeckListModelGroupCriteria newCriteria);
|
||||
|
||||
|
|
|
|||
|
|
@ -594,9 +594,9 @@ QString DeckLoader::getCardZoneFromName(QString cardName, QString currentZoneNam
|
|||
QString DeckLoader::getCompleteCardName(const QString &cardName) const
|
||||
{
|
||||
if (CardDatabaseManager::getInstance()) {
|
||||
CardInfoPtr temp = CardDatabaseManager::getInstance()->guessCard({cardName});
|
||||
ExactCard temp = CardDatabaseManager::getInstance()->guessCard({cardName});
|
||||
if (temp) {
|
||||
return temp->getName();
|
||||
return temp.getName();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue