mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-21 18:02:14 -07:00
DeckList now tries to assign reasonable defaults for UUID and collectorNumber if none are found in loaded DeckLists.
Rename overloaded DeckListModel findChild() function to findCardChildByNameAndUUID() for clarity.
This commit is contained in:
parent
963ff64cb6
commit
edbc57edc7
3 changed files with 43 additions and 11 deletions
|
|
@ -1,5 +1,7 @@
|
|||
#include "decklist.h"
|
||||
|
||||
#include "../cockatrice/src/game/cards/card_database_manager.h"
|
||||
|
||||
#include <QCryptographicHash>
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
|
|
@ -88,8 +90,8 @@ int AbstractDecklistNode::depth() const
|
|||
}
|
||||
|
||||
InnerDecklistNode::InnerDecklistNode(InnerDecklistNode *other, InnerDecklistNode *_parent)
|
||||
: AbstractDecklistNode(_parent), name(other->getName()), cardSetCode(other->getCardUuid()),
|
||||
cardCollectorNumber(other->getCardCollectorNumber())
|
||||
: 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));
|
||||
|
|
@ -140,8 +142,8 @@ void InnerDecklistNode::clearTree()
|
|||
}
|
||||
|
||||
DecklistCardNode::DecklistCardNode(DecklistCardNode *other, InnerDecklistNode *_parent)
|
||||
: AbstractDecklistCardNode(_parent), name(other->getName()), number(other->getNumber()),
|
||||
cardSetName(other->getCardUuid()), cardSetNumber(other->getCardCollectorNumber())
|
||||
: AbstractDecklistCardNode(_parent), name(other->getName()), number(other->getNumber()),
|
||||
cardSetName(other->getCardUuid()), cardSetNumber(other->getCardCollectorNumber())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -155,7 +157,7 @@ AbstractDecklistNode *InnerDecklistNode::findChild(const QString &_name)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
AbstractDecklistNode *InnerDecklistNode::findChild(const QString &_name, const QString &_uuid)
|
||||
AbstractDecklistNode *InnerDecklistNode::findCardChildByNameAndUUID(const QString &_name, const QString &_uuid)
|
||||
{
|
||||
for (int i = 0; i < size(); i++) {
|
||||
if (at(i)->getName() == _name && at(i)->getCardUuid() == _uuid) {
|
||||
|
|
@ -280,10 +282,39 @@ bool InnerDecklistNode::readElement(QXmlStreamReader *xml)
|
|||
InnerDecklistNode *newZone = new InnerDecklistNode(xml->attributes().value("name").toString(), this);
|
||||
newZone->readElement(xml);
|
||||
} else if (childName == "card") {
|
||||
QString uuid = xml->attributes().value("uuid").toString();
|
||||
QString collectorNumber = xml->attributes().value("collectorNumber").toString();
|
||||
if (uuid.isEmpty() || collectorNumber.isEmpty()) {
|
||||
CardInfoPerSet preferredSetForCard = CardDatabaseManager::getInstance()->getPreferredSetForCard(
|
||||
xml->attributes().value("name").toString());
|
||||
|
||||
// If we don't have a UUID and the preferred set has one, we use that as a default.
|
||||
if (!preferredSetForCard.getProperty("uuid").isEmpty() && uuid.isEmpty()) {
|
||||
uuid = preferredSetForCard.getProperty("uuid");
|
||||
}
|
||||
|
||||
// If we don't have a collectorsNumber, the preferred Set has one, AND we've already set the UUID
|
||||
// to the preferred Set, we use the one from the preferred set.
|
||||
if (!preferredSetForCard.getProperty("num").isEmpty() && collectorNumber.isEmpty() &&
|
||||
preferredSetForCard.getProperty("uuid") == uuid) {
|
||||
collectorNumber = preferredSetForCard.getProperty("num");
|
||||
|
||||
// Otherwise check which Set has the UUID we've set or reused and use the collectorNumber from
|
||||
// there.
|
||||
} else if (!preferredSetForCard.getProperty("num").isEmpty() && collectorNumber.isEmpty()) {
|
||||
CardInfoPtr card_by_name_and_uuid = CardDatabaseManager::getInstance()->getCardByNameAndUUID(
|
||||
xml->attributes().value("name").toString(), uuid);
|
||||
for (auto &set : card_by_name_and_uuid->getSets()) {
|
||||
if (set.getProperty("uuid") == uuid) {
|
||||
collectorNumber = set.getProperty("num");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
xml->attributes().value("number").toString().toInt(),
|
||||
this, uuid, collectorNumber);
|
||||
newCard->readElement(xml);
|
||||
}
|
||||
} else if (xml->isEndElement() && (childName == "zone"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue