mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-21 09:52:16 -07:00
Added Zach's work on storing printing information in the DeckList (#1)
* Change CardInfo's PixmapCacheKey to be the UUID of the preferred set after database loading has finished. Otherwise, and if no UUID of a preferred set is available, default to the card name. * Refactor CardDatabase *db global variable to singleton CardDatabaseManager. This commit refactors the global variable CardDatabase *db into a singleton encapsulated by the DatabaseManager class, accessible via DatabaseManager::getInstance(). This change centralizes access to the database instance, improving code modularity and encapsulation, resolving dependencies on main.h for code that requires access to the database instance. - Added DatabaseManager class with getInstance() method returning a pointer to the singleton CardDatabase. - Removed global db variable and updated references across the codebase. - Thread-safe static initialization for the singleton. Impact: This refactor should have no functional impact on the application, as it maintains the same interface for accessing the CardDatabase instance. However, the codebase now benefits from improved encapsulation, lifetime management, and thread-safety. * fixed db issue an renamed sets to set in picture loader * canibalized zach work and added it to the decklist builder --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
c2ae31b3b8
commit
502c901c06
3 changed files with 96 additions and 15 deletions
|
|
@ -37,6 +37,22 @@ public:
|
|||
{
|
||||
dataNode->setName(_name);
|
||||
}
|
||||
QString getCardUuid() const override
|
||||
{
|
||||
return dataNode->getCardUuid();
|
||||
}
|
||||
void setCardSetCode(const QString &_cardSetName) override
|
||||
{
|
||||
dataNode->setCardSetCode(_cardSetName);
|
||||
}
|
||||
QString getCardCollectorNumber() const override
|
||||
{
|
||||
return dataNode->getCardCollectorNumber();
|
||||
}
|
||||
void setCardCollectorNumber(const QString &_cardSetNumber) override
|
||||
{
|
||||
dataNode->setCardCollectorNumber(_cardSetNumber);
|
||||
}
|
||||
DecklistCardNode *getDataNode() const
|
||||
{
|
||||
return dataNode;
|
||||
|
|
|
|||
|
|
@ -88,7 +88,8 @@ int AbstractDecklistNode::depth() const
|
|||
}
|
||||
|
||||
InnerDecklistNode::InnerDecklistNode(InnerDecklistNode *other, InnerDecklistNode *_parent)
|
||||
: AbstractDecklistNode(_parent), name(other->getName())
|
||||
: AbstractDecklistNode(_parent), name(other->getName()), cardSetCode(other->getCardUuid()),
|
||||
cardCollectorNumber(other->getCardCollectorNumber())
|
||||
{
|
||||
for (int i = 0; i < other->size(); ++i) {
|
||||
auto *inner = dynamic_cast<InnerDecklistNode *>(other->at(i));
|
||||
|
|
@ -139,7 +140,8 @@ void InnerDecklistNode::clearTree()
|
|||
}
|
||||
|
||||
DecklistCardNode::DecklistCardNode(DecklistCardNode *other, InnerDecklistNode *_parent)
|
||||
: AbstractDecklistCardNode(_parent), name(other->getName()), number(other->getNumber())
|
||||
: AbstractDecklistCardNode(_parent), name(other->getName()), number(other->getNumber()),
|
||||
cardSetName(other->getCardUuid()), cardSetNumber(other->getCardCollectorNumber())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -268,9 +270,10 @@ bool InnerDecklistNode::readElement(QXmlStreamReader *xml)
|
|||
InnerDecklistNode *newZone = new InnerDecklistNode(xml->attributes().value("name").toString(), this);
|
||||
newZone->readElement(xml);
|
||||
} else if (childName == "card") {
|
||||
DecklistCardNode *newCard =
|
||||
new DecklistCardNode(xml->attributes().value("name").toString(),
|
||||
xml->attributes().value("number").toString().toInt(), this);
|
||||
DecklistCardNode *newCard = new DecklistCardNode(xml->attributes().value("name").toString(),
|
||||
xml->attributes().value("number").toString().toInt(),
|
||||
this, xml->attributes().value("uuid").toString(),
|
||||
xml->attributes().value("collectorNumber").toString());
|
||||
newCard->readElement(xml);
|
||||
}
|
||||
} else if (xml->isEndElement() && (childName == "zone"))
|
||||
|
|
@ -303,6 +306,13 @@ void AbstractDecklistCardNode::writeElement(QXmlStreamWriter *xml)
|
|||
xml->writeEmptyElement("card");
|
||||
xml->writeAttribute("number", QString::number(getNumber()));
|
||||
xml->writeAttribute("name", getName());
|
||||
|
||||
if (getCardUuid() != "") {
|
||||
xml->writeAttribute("uuid", getCardUuid());
|
||||
if (getCardCollectorNumber() != "") {
|
||||
xml->writeAttribute("collectorNumber", getCardCollectorNumber());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QVector<QPair<int, int>> InnerDecklistNode::sort(Qt::SortOrder order)
|
||||
|
|
@ -740,14 +750,17 @@ int DeckList::getSideboardSize() const
|
|||
return size;
|
||||
}
|
||||
|
||||
DecklistCardNode *DeckList::addCard(const QString &cardName, const QString &zoneName)
|
||||
DecklistCardNode *DeckList::addCard(const QString &cardName,
|
||||
const QString &zoneName,
|
||||
const QString &cardSetName,
|
||||
const QString &cardSetCollectorNumber)
|
||||
{
|
||||
auto *zoneNode = dynamic_cast<InnerDecklistNode *>(root->findChild(zoneName));
|
||||
if (zoneNode == nullptr) {
|
||||
zoneNode = new InnerDecklistNode(zoneName, root);
|
||||
}
|
||||
|
||||
auto *node = new DecklistCardNode(cardName, 1, zoneNode);
|
||||
auto *node = new DecklistCardNode(cardName, 1, zoneNode, cardSetName, cardSetCollectorNumber);
|
||||
updateDeckHash();
|
||||
|
||||
return node;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef DECKLIST_H
|
||||
#define DECKLIST_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
|
|
@ -13,6 +14,7 @@
|
|||
#include <QtCore/QXmlStreamReader>
|
||||
#include <QtCore/QXmlStreamWriter>
|
||||
#include <common/pb/move_card_to_zone.pb.h>
|
||||
#include <utility>
|
||||
|
||||
class CardDatabase;
|
||||
class QIODevice;
|
||||
|
|
@ -68,6 +70,8 @@ public:
|
|||
sortMethod = method;
|
||||
}
|
||||
virtual QString getName() const = 0;
|
||||
virtual QString getCardUuid() const = 0;
|
||||
virtual QString getCardCollectorNumber() const = 0;
|
||||
InnerDecklistNode *getParent() const
|
||||
{
|
||||
return parent;
|
||||
|
|
@ -82,8 +86,9 @@ public:
|
|||
|
||||
class InnerDecklistNode : public AbstractDecklistNode, public QList<AbstractDecklistNode *>
|
||||
{
|
||||
private:
|
||||
QString name;
|
||||
QString cardSetCode;
|
||||
QString cardCollectorNumber;
|
||||
class compareFunctor;
|
||||
|
||||
public:
|
||||
|
|
@ -94,7 +99,7 @@ public:
|
|||
explicit InnerDecklistNode(InnerDecklistNode *other, InnerDecklistNode *_parent = nullptr);
|
||||
~InnerDecklistNode() override;
|
||||
void setSortMethod(DeckSortMethod method) override;
|
||||
QString getName() const override
|
||||
[[nodiscard]] QString getName() const override
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
|
@ -103,7 +108,24 @@ public:
|
|||
name = _name;
|
||||
}
|
||||
static QString visibleNameFromName(const QString &_name);
|
||||
virtual QString getVisibleName() const;
|
||||
[[nodiscard]] virtual QString getVisibleName() const;
|
||||
[[nodiscard]] QString getCardUuid() const override
|
||||
{
|
||||
return cardSetCode;
|
||||
}
|
||||
void setCardSetCode(const QString &_cardSetCode)
|
||||
{
|
||||
cardSetCode = _cardSetCode;
|
||||
}
|
||||
[[nodiscard]] QString getCardCollectorNumber() const override
|
||||
{
|
||||
return cardCollectorNumber;
|
||||
}
|
||||
void setCardCollectorNumber(const QString &_cardCollectorNumber)
|
||||
{
|
||||
cardCollectorNumber = _cardCollectorNumber;
|
||||
}
|
||||
|
||||
void clearTree();
|
||||
AbstractDecklistNode *findChild(const QString &_name);
|
||||
int height() const override;
|
||||
|
|
@ -127,6 +149,10 @@ public:
|
|||
virtual void setNumber(int _number) = 0;
|
||||
QString getName() const override = 0;
|
||||
virtual void setName(const QString &_name) = 0;
|
||||
virtual QString getCardUuid() const override = 0;
|
||||
virtual void setCardSetCode(const QString &_cardSetName) = 0;
|
||||
virtual QString getCardCollectorNumber() const override = 0;
|
||||
virtual void setCardCollectorNumber(const QString &_cardSetNumber) = 0;
|
||||
int height() const override
|
||||
{
|
||||
return 0;
|
||||
|
|
@ -141,14 +167,21 @@ public:
|
|||
|
||||
class DecklistCardNode : public AbstractDecklistCardNode
|
||||
{
|
||||
private:
|
||||
QString name;
|
||||
int number;
|
||||
QString cardSetName;
|
||||
QString cardSetNumber;
|
||||
|
||||
public:
|
||||
explicit DecklistCardNode(QString _name = QString(), int _number = 1, InnerDecklistNode *_parent = nullptr)
|
||||
: AbstractDecklistCardNode(_parent), name(std::move(_name)), number(_number)
|
||||
explicit DecklistCardNode(QString _name = QString(),
|
||||
int _number = 1,
|
||||
InnerDecklistNode *_parent = nullptr,
|
||||
QString _cardSetName = QString(),
|
||||
QString _cardSetNumber = QString())
|
||||
: AbstractDecklistCardNode(_parent), name(std::move(_name)), number(_number),
|
||||
cardSetName(std::move(_cardSetName)), cardSetNumber(std::move(_cardSetNumber))
|
||||
{
|
||||
qDebug() << "Adding" << name << number << cardSetName << cardSetNumber;
|
||||
}
|
||||
explicit DecklistCardNode(DecklistCardNode *other, InnerDecklistNode *_parent);
|
||||
int getNumber() const override
|
||||
|
|
@ -167,6 +200,22 @@ public:
|
|||
{
|
||||
name = _name;
|
||||
}
|
||||
QString getCardUuid() const override
|
||||
{
|
||||
return cardSetName;
|
||||
}
|
||||
void setCardSetCode(const QString &_cardSetName) override
|
||||
{
|
||||
cardSetName = _cardSetName;
|
||||
}
|
||||
QString getCardCollectorNumber() const override
|
||||
{
|
||||
return cardSetNumber;
|
||||
}
|
||||
void setCardCollectorNumber(const QString &_cardSetNumber) override
|
||||
{
|
||||
cardSetNumber = _cardSetNumber;
|
||||
}
|
||||
};
|
||||
|
||||
class DeckList : public QObject
|
||||
|
|
@ -255,7 +304,10 @@ public:
|
|||
{
|
||||
return root;
|
||||
}
|
||||
DecklistCardNode *addCard(const QString &cardName, const QString &zoneName);
|
||||
DecklistCardNode *addCard(const QString &cardName,
|
||||
const QString &zoneName,
|
||||
const QString &cardSetName = QString(),
|
||||
const QString &cardSetCollectorNumber = QString());
|
||||
bool deleteNode(AbstractDecklistNode *node, InnerDecklistNode *rootNode = nullptr);
|
||||
|
||||
/**
|
||||
|
|
@ -277,4 +329,4 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue