mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-18 00:12:15 -07:00
Merge branch 'master' into refactor-replays
This commit is contained in:
commit
c529f73a38
89 changed files with 50581 additions and 30043 deletions
|
|
@ -16,6 +16,7 @@ set(cockatrice_SOURCES
|
|||
src/client/network/replay_timeline_widget.cpp
|
||||
src/client/network/sets_model.cpp
|
||||
src/client/network/spoiler_background_updater.cpp
|
||||
src/client/network/parsers/deck_link_to_api_transformer.cpp
|
||||
src/client/replay_manager.cpp
|
||||
src/client/sound_engine.cpp
|
||||
src/client/tabs/abstract_tab_deck_editor.cpp
|
||||
|
|
@ -166,6 +167,7 @@ set(cockatrice_SOURCES
|
|||
src/dialogs/dlg_forgot_password_reset.cpp
|
||||
src/dialogs/dlg_load_deck.cpp
|
||||
src/dialogs/dlg_load_deck_from_clipboard.cpp
|
||||
src/dialogs/dlg_load_deck_from_website.cpp
|
||||
src/dialogs/dlg_load_remote_deck.cpp
|
||||
src/dialogs/dlg_manage_sets.cpp
|
||||
src/dialogs/dlg_move_top_cards_until.cpp
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
#tab_supervisor = true
|
||||
|
||||
#dlg_edit_avatar = true
|
||||
#dlg_load_deck_from_website = true
|
||||
#dlg_settings = true
|
||||
#dlg_tip_of_the_day = true
|
||||
#dlg_update = true
|
||||
|
|
|
|||
|
|
@ -54,6 +54,9 @@ DeckEditorMenu::DeckEditorMenu(AbstractTabDeckEditor *parent) : QMenu(parent), d
|
|||
aPrintDeck = new QAction(QString(), this);
|
||||
connect(aPrintDeck, &QAction::triggered, deckEditor, &AbstractTabDeckEditor::actPrintDeck);
|
||||
|
||||
aLoadDeckFromWebsite = new QAction(QString(), this);
|
||||
connect(aLoadDeckFromWebsite, &QAction::triggered, deckEditor, &AbstractTabDeckEditor::actLoadDeckFromWebsite);
|
||||
|
||||
aExportDeckDecklist = new QAction(QString(), this);
|
||||
connect(aExportDeckDecklist, &QAction::triggered, deckEditor, &AbstractTabDeckEditor::actExportDeckDecklist);
|
||||
|
||||
|
|
@ -97,6 +100,7 @@ DeckEditorMenu::DeckEditorMenu(AbstractTabDeckEditor *parent) : QMenu(parent), d
|
|||
addMenu(saveDeckToClipboardMenu);
|
||||
addSeparator();
|
||||
addAction(aPrintDeck);
|
||||
addAction(aLoadDeckFromWebsite);
|
||||
addMenu(analyzeDeckMenu);
|
||||
addSeparator();
|
||||
addAction(deckEditor->filterDockWidget->aClearFilterOne);
|
||||
|
|
@ -166,6 +170,7 @@ void DeckEditorMenu::retranslateUi()
|
|||
|
||||
aPrintDeck->setText(tr("&Print deck..."));
|
||||
|
||||
aLoadDeckFromWebsite->setText(tr("Load deck from online service..."));
|
||||
analyzeDeckMenu->setTitle(tr("&Send deck to online service"));
|
||||
aExportDeckDecklist->setText(tr("Create decklist (decklist.org)"));
|
||||
aExportDeckDecklistXyz->setText(tr("Create decklist (decklist.xyz)"));
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ public:
|
|||
|
||||
QAction *aNewDeck, *aLoadDeck, *aClearRecents, *aSaveDeck, *aSaveDeckAs, *aLoadDeckFromClipboard,
|
||||
*aEditDeckInClipboard, *aEditDeckInClipboardRaw, *aSaveDeckToClipboard, *aSaveDeckToClipboardNoSetInfo,
|
||||
*aSaveDeckToClipboardRaw, *aSaveDeckToClipboardRawNoSetInfo, *aPrintDeck, *aExportDeckDecklist,
|
||||
*aExportDeckDecklistXyz, *aAnalyzeDeckDeckstats, *aAnalyzeDeckTappedout, *aClose;
|
||||
*aSaveDeckToClipboardRaw, *aSaveDeckToClipboardRawNoSetInfo, *aPrintDeck, *aLoadDeckFromWebsite,
|
||||
*aExportDeckDecklist, *aExportDeckDecklistXyz, *aAnalyzeDeckDeckstats, *aAnalyzeDeckTappedout, *aClose;
|
||||
QMenu *loadRecentDeckMenu, *analyzeDeckMenu, *editDeckInClipboardMenu, *saveDeckToClipboardMenu;
|
||||
|
||||
void setSaveStatus(bool newStatus);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
#include "deck_link_to_api_transformer.h"
|
||||
|
||||
#include <QRegularExpression>
|
||||
|
||||
namespace DeckLinkToApiTransformer
|
||||
{
|
||||
|
||||
static const QString TAPPEDOUT_BASE = "https://tappedout.net/mtg-decks/";
|
||||
static const QString TAPPEDOUT_SUFFIX = "/?fmt=txt";
|
||||
|
||||
static const QString ARCHIDEKT_BASE = "https://archidekt.com/api/decks/";
|
||||
static const QString ARCHIDEKT_SUFFIX = "/?format=json";
|
||||
|
||||
static const QString MOXFIELD_BASE = "https://api.moxfield.com/v2/decks/all/";
|
||||
static const QString MOXFIELD_SUFFIX = "/";
|
||||
|
||||
static const QString DECKSTATS_SUFFIX = "?include_comments=1&export_mtgarena=1";
|
||||
|
||||
bool parseDeckUrl(const QString &url, ParsedDeckInfo &outInfo)
|
||||
{
|
||||
static QRegularExpression rxTappedOut("tappedout\\.net/(?:mtg-decks/)?([^/?#]+)");
|
||||
static QRegularExpression rxArchidekt("archidekt\\.com/decks/(\\d+)");
|
||||
static QRegularExpression rxMoxfield("moxfield\\.com/decks/([a-zA-Z0-9_-]+)");
|
||||
static QRegularExpression rxDeckstats("deckstats\\.net/decks/(\\d+/[a-zA-Z0-9_-]+)");
|
||||
|
||||
QRegularExpressionMatch match;
|
||||
|
||||
if ((match = rxTappedOut.match(url)).hasMatch()) {
|
||||
QString slug = match.captured(1);
|
||||
outInfo = ParsedDeckInfo{.baseUrl = TAPPEDOUT_BASE,
|
||||
.deckID = slug,
|
||||
.fullUrl = TAPPEDOUT_BASE + slug + TAPPEDOUT_SUFFIX,
|
||||
.provider = DeckProvider::TappedOut};
|
||||
return true;
|
||||
} else if ((match = rxArchidekt.match(url)).hasMatch()) {
|
||||
QString deckID = match.captured(1);
|
||||
outInfo = ParsedDeckInfo{.baseUrl = ARCHIDEKT_BASE,
|
||||
.deckID = deckID,
|
||||
.fullUrl = ARCHIDEKT_BASE + deckID + ARCHIDEKT_SUFFIX,
|
||||
.provider = DeckProvider::Archidekt};
|
||||
return true;
|
||||
} else if ((match = rxMoxfield.match(url)).hasMatch()) {
|
||||
QString deckID = match.captured(1);
|
||||
outInfo = ParsedDeckInfo{.baseUrl = MOXFIELD_BASE,
|
||||
.deckID = deckID,
|
||||
.fullUrl = MOXFIELD_BASE + deckID + MOXFIELD_SUFFIX,
|
||||
.provider = DeckProvider::Moxfield};
|
||||
return true;
|
||||
} else if ((match = rxDeckstats.match(url)).hasMatch()) {
|
||||
QString deckPath = match.captured(1);
|
||||
outInfo = ParsedDeckInfo{.baseUrl = "https://deckstats.net/decks/",
|
||||
.deckID = deckPath,
|
||||
.fullUrl = "https://deckstats.net/decks/" + deckPath + DECKSTATS_SUFFIX,
|
||||
.provider = DeckProvider::Deckstats};
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace DeckLinkToApiTransformer
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
#ifndef DECK_LINK_TO_API_TRANSFORMER_H
|
||||
#define DECK_LINK_TO_API_TRANSFORMER_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
enum class DeckProvider
|
||||
{
|
||||
TappedOut,
|
||||
Archidekt,
|
||||
Moxfield,
|
||||
Deckstats,
|
||||
Unknown
|
||||
};
|
||||
|
||||
struct ParsedDeckInfo
|
||||
{
|
||||
QString baseUrl;
|
||||
QString deckID;
|
||||
QString fullUrl;
|
||||
DeckProvider provider;
|
||||
};
|
||||
|
||||
namespace DeckLinkToApiTransformer
|
||||
{
|
||||
|
||||
// Returns true if the input URL is recognized and fills outInfo.
|
||||
bool parseDeckUrl(const QString &url, ParsedDeckInfo &outInfo);
|
||||
|
||||
} // namespace DeckLinkToApiTransformer
|
||||
|
||||
#endif // DECK_LINK_TO_API_TRANSFORMER_H
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
#ifndef INTERFACE_JSON_DECK_PARSER_H
|
||||
#define INTERFACE_JSON_DECK_PARSER_H
|
||||
#include "../../../deck/deck_loader.h"
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
|
||||
class IJsonDeckParser
|
||||
{
|
||||
public:
|
||||
virtual ~IJsonDeckParser() = default;
|
||||
|
||||
virtual DeckLoader *parse(const QJsonObject &obj) = 0;
|
||||
};
|
||||
|
||||
class ArchidektJsonParser : public IJsonDeckParser
|
||||
{
|
||||
public:
|
||||
DeckLoader *parse(const QJsonObject &obj) override
|
||||
{
|
||||
DeckLoader *list = new DeckLoader();
|
||||
|
||||
QString deckName = obj.value("name").toString();
|
||||
QString deckDescription = obj.value("description").toString();
|
||||
|
||||
list->setName(deckName);
|
||||
list->setComments(deckDescription);
|
||||
|
||||
QString outputText;
|
||||
QTextStream outStream(&outputText);
|
||||
|
||||
for (auto entry : obj.value("cards").toArray()) {
|
||||
auto quantity = entry.toObject().value("quantity").toInt();
|
||||
|
||||
auto card = entry.toObject().value("card").toObject();
|
||||
auto oracleCard = card.value("oracleCard").toObject();
|
||||
QString cardName = oracleCard.value("name").toString();
|
||||
QString setName = card.value("edition").toObject().value("editioncode").toString().toUpper();
|
||||
QString collectorNumber = card.value("collectorNumber").toString();
|
||||
|
||||
outStream << quantity << ' ' << cardName << " (" << setName << ") " << collectorNumber << '\n';
|
||||
}
|
||||
|
||||
list->loadFromStream_Plain(outStream, false);
|
||||
list->resolveSetNameAndNumberToProviderID();
|
||||
|
||||
return list;
|
||||
}
|
||||
};
|
||||
|
||||
class MoxfieldJsonParser : public IJsonDeckParser
|
||||
{
|
||||
public:
|
||||
DeckLoader *parse(const QJsonObject &obj) override
|
||||
{
|
||||
DeckLoader *list = new DeckLoader();
|
||||
|
||||
QString deckName = obj.value("name").toString();
|
||||
QString deckDescription = obj.value("description").toString();
|
||||
|
||||
list->setName(deckName);
|
||||
list->setComments(deckDescription);
|
||||
|
||||
QString outputText;
|
||||
QTextStream outStream(&outputText);
|
||||
|
||||
for (auto entry : obj.value("mainboard").toObject()) {
|
||||
auto quantity = entry.toObject().value("quantity").toInt();
|
||||
|
||||
auto card = entry.toObject().value("card").toObject();
|
||||
QString cardName = card.value("name").toString();
|
||||
QString setName = card.value("set").toString().toUpper();
|
||||
QString collectorNumber = card.value("cn").toString();
|
||||
|
||||
outStream << quantity << ' ' << cardName << " (" << setName << ") " << collectorNumber << '\n';
|
||||
}
|
||||
|
||||
outStream << '\n';
|
||||
|
||||
for (auto entry : obj.value("sideboard").toObject()) {
|
||||
auto quantity = entry.toObject().value("quantity").toInt();
|
||||
|
||||
auto card = entry.toObject().value("card").toObject();
|
||||
QString cardName = card.value("name").toString();
|
||||
QString setName = card.value("set").toString().toUpper();
|
||||
QString collectorNumber = card.value("cn").toString();
|
||||
|
||||
outStream << quantity << ' ' << cardName << " (" << setName << ") " << collectorNumber << '\n';
|
||||
}
|
||||
|
||||
list->loadFromStream_Plain(outStream, false);
|
||||
list->resolveSetNameAndNumberToProviderID();
|
||||
|
||||
QJsonObject commandersObj = obj.value("commanders").toObject();
|
||||
if (!commandersObj.isEmpty()) {
|
||||
for (auto it = commandersObj.begin(); it != commandersObj.end(); ++it) {
|
||||
QJsonObject cardData = it.value().toObject().value("card").toObject();
|
||||
QString commanderName = cardData.value("name").toString();
|
||||
QString setName = cardData.value("set").toString().toUpper();
|
||||
QString collectorNumber = cardData.value("cn").toString();
|
||||
QString providerId = cardData.value("scryfall_id").toString();
|
||||
|
||||
list->setBannerCard(QPair<QString, QString>(commanderName, providerId));
|
||||
list->addCard(commanderName, DECK_ZONE_MAIN, -1, setName, collectorNumber, providerId);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // INTERFACE_JSON_DECK_PARSER_H
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
#include "../../deck/deck_stats_interface.h"
|
||||
#include "../../dialogs/dlg_load_deck.h"
|
||||
#include "../../dialogs/dlg_load_deck_from_clipboard.h"
|
||||
#include "../../dialogs/dlg_load_deck_from_website.h"
|
||||
#include "../../game/cards/card_database_manager.h"
|
||||
#include "../../game/cards/card_database_model.h"
|
||||
#include "../../server/pending_command.h"
|
||||
|
|
@ -467,6 +468,28 @@ void AbstractTabDeckEditor::actPrintDeck()
|
|||
dlg->exec();
|
||||
}
|
||||
|
||||
void AbstractTabDeckEditor::actLoadDeckFromWebsite()
|
||||
{
|
||||
auto deckOpenLocation = confirmOpen();
|
||||
|
||||
if (deckOpenLocation == CANCELLED) {
|
||||
return;
|
||||
}
|
||||
|
||||
DlgLoadDeckFromWebsite dlg(this);
|
||||
if (!dlg.exec())
|
||||
return;
|
||||
|
||||
if (deckOpenLocation == NEW_TAB) {
|
||||
emit openDeckEditor(dlg.getDeck());
|
||||
} else {
|
||||
setDeck(dlg.getDeck());
|
||||
setModified(true);
|
||||
}
|
||||
|
||||
deckMenu->setSaveStatus(true);
|
||||
}
|
||||
|
||||
void AbstractTabDeckEditor::exportToDecklistWebsite(DeckLoader::DecklistWebsite website)
|
||||
{
|
||||
// check if deck is not null
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ protected slots:
|
|||
void actSaveDeckToClipboardRaw();
|
||||
void actSaveDeckToClipboardRawNoSetInfo();
|
||||
void actPrintDeck();
|
||||
void actLoadDeckFromWebsite();
|
||||
void actExportDeckDecklist();
|
||||
void actExportDeckDecklistXyz();
|
||||
void actAnalyzeDeckDeckstats();
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public:
|
|||
QString getTabText() const override
|
||||
{
|
||||
auto cardName = cardToQuery.isNull() ? QString() : cardToQuery->getName();
|
||||
return tr("EDHREC: ") + cardName;
|
||||
return tr("EDHRec: ") + cardName;
|
||||
}
|
||||
|
||||
CardSizeWidget *getCardSizeSlider()
|
||||
|
|
|
|||
|
|
@ -11,13 +11,10 @@ static constexpr int REFRESH_INTERVAL_MS = 10 * 1000;
|
|||
|
||||
PictureLoaderLocal::PictureLoaderLocal(QObject *parent)
|
||||
: QObject(parent), picsPath(SettingsCache::instance().getPicsPath()),
|
||||
customPicsPath(SettingsCache::instance().getCustomPicsPath()),
|
||||
overrideAllCardArtWithPersonalPreference(SettingsCache::instance().getOverrideAllCardArtWithPersonalPreference())
|
||||
customPicsPath(SettingsCache::instance().getCustomPicsPath())
|
||||
{
|
||||
// Hook up signals to settings
|
||||
connect(&SettingsCache::instance(), &SettingsCache::picsPathChanged, this, &PictureLoaderLocal::picsPathChanged);
|
||||
connect(&SettingsCache::instance(), &SettingsCache::overrideAllCardArtWithPersonalPreferenceChanged, this,
|
||||
&PictureLoaderLocal::setOverrideAllCardArtWithPersonalPreference);
|
||||
|
||||
refreshIndex();
|
||||
|
||||
|
|
@ -59,84 +56,94 @@ QImage PictureLoaderLocal::tryLoad(const CardInfoPtr &toLoad) const
|
|||
{
|
||||
CardSetPtr set = PictureToLoad::extractSetsSorted(toLoad).first();
|
||||
|
||||
QString setName = set ? set->getCorrectedShortName() : QString();
|
||||
PrintingInfo setInstance = CardDatabaseManager::getInstance()->getSetInfoForCard(toLoad);
|
||||
|
||||
QString cardName = toLoad->getName();
|
||||
QString correctedCardName = toLoad->getCorrectedName();
|
||||
|
||||
// FIXME: This is a hack so that to keep old Cockatrice behavior
|
||||
// (ignoring provider ID) when the "override all card art with personal
|
||||
// preference" is set.
|
||||
//
|
||||
// Figure out a proper way to integrate the two systems at some point.
|
||||
//
|
||||
// Note: need to go through a member for
|
||||
// overrideAllCardArtWithPersonalPreference as reading from the
|
||||
// SettingsCache instance from the PictureLoaderWorker thread could
|
||||
// cause race conditions.
|
||||
//
|
||||
// XXX: Reading from the CardDatabaseManager instance from the
|
||||
// PictureLoaderWorker thread might not be safe either
|
||||
bool searchCustomPics =
|
||||
overrideAllCardArtWithPersonalPreference ||
|
||||
CardDatabaseManager::getInstance()->isProviderIdForPreferredPrinting(cardName, toLoad->getPixmapCacheKey());
|
||||
if (searchCustomPics) {
|
||||
qCDebug(PictureLoaderLocalLog).nospace()
|
||||
<< "[card: " << cardName << " set: " << setName << "]: Attempting to load picture from local";
|
||||
return tryLoadCardImageFromDisk(setName, correctedCardName, searchCustomPics);
|
||||
QString setName, collectorNumber, providerId;
|
||||
|
||||
if (setInstance.getSet()) {
|
||||
setName = setInstance.getSet()->getCorrectedShortName();
|
||||
collectorNumber = setInstance.getProperty("num");
|
||||
providerId = setInstance.getProperty("uuid");
|
||||
}
|
||||
|
||||
qCDebug(PictureLoaderLocalLog).nospace()
|
||||
<< "[card: " << cardName << " set: " << setName << "]: Skipping load picture from local";
|
||||
|
||||
return QImage();
|
||||
<< "[card: " << cardName << " set: " << setName << "]: Attempting to load picture from local";
|
||||
return tryLoadCardImageFromDisk(setName, correctedCardName, collectorNumber, providerId);
|
||||
}
|
||||
|
||||
QImage PictureLoaderLocal::tryLoadCardImageFromDisk(const QString &setName,
|
||||
const QString &correctedCardName,
|
||||
const bool searchCustomPics) const
|
||||
const QString &collectorNumber,
|
||||
const QString &providerId) const
|
||||
{
|
||||
QImage image;
|
||||
QImageReader imgReader;
|
||||
imgReader.setDecideFormatFromContent(true);
|
||||
QList<QString> picsPaths = QList<QString>();
|
||||
|
||||
if (searchCustomPics) {
|
||||
picsPaths << customFolderIndex.values(correctedCardName);
|
||||
// Most-to-least specific, these will fall through in order.
|
||||
QStringList nameVariants;
|
||||
|
||||
// cardName_providerId
|
||||
if (!providerId.isEmpty()) {
|
||||
nameVariants << QString("%1-%2").arg(correctedCardName, providerId)
|
||||
<< QString("%1_%2").arg(correctedCardName, providerId);
|
||||
}
|
||||
|
||||
// cardName_setName_collectorNumber & setName-collectorNumber-cardName
|
||||
if (!setName.isEmpty() && !collectorNumber.isEmpty()) {
|
||||
nameVariants << QString("%1_%2_%3").arg(correctedCardName, setName, collectorNumber)
|
||||
<< QString("%1-%2-%3").arg(setName, collectorNumber, correctedCardName);
|
||||
}
|
||||
// cardName_setName
|
||||
if (!setName.isEmpty()) {
|
||||
picsPaths << picsPath + "/" + setName + "/" + correctedCardName
|
||||
// We no longer store downloaded images there, but don't just ignore
|
||||
// stuff that old versions have put there.
|
||||
<< picsPath + "/downloadedPics/" + setName + "/" + correctedCardName;
|
||||
nameVariants << QString("%1_%2").arg(correctedCardName, setName)
|
||||
<< QString("%1-%2").arg(setName, correctedCardName);
|
||||
}
|
||||
|
||||
// Iterates through the list of paths, searching for images with the desired
|
||||
// name with any QImageReader-supported extension
|
||||
for (const auto &_picsPath : picsPaths) {
|
||||
if (!QFileInfo(_picsPath).isFile()) {
|
||||
// cardName
|
||||
nameVariants << correctedCardName;
|
||||
|
||||
for (const QString &nameVariant : nameVariants) {
|
||||
if (nameVariant.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
imgReader.setFileName(_picsPath);
|
||||
if (imgReader.read(&image)) {
|
||||
qCDebug(PictureLoaderLocalLog).nospace()
|
||||
<< "[card: " << correctedCardName << " set: " << setName << "]: Picture found on disk.";
|
||||
return image;
|
||||
QStringList candidatePaths = customFolderIndex.values(nameVariant);
|
||||
|
||||
if (!setName.isEmpty()) {
|
||||
candidatePaths << picsPath + "/" + setName + "/" + nameVariant;
|
||||
candidatePaths << picsPath + "/downloadedPics/" + setName + "/" + nameVariant;
|
||||
}
|
||||
imgReader.setFileName(_picsPath + ".full");
|
||||
if (imgReader.read(&image)) {
|
||||
qCDebug(PictureLoaderLocalLog).nospace()
|
||||
<< "[card: " << correctedCardName << " set: " << setName << "]: Picture.full found on disk.";
|
||||
return image;
|
||||
}
|
||||
imgReader.setFileName(_picsPath + ".xlhq");
|
||||
if (imgReader.read(&image)) {
|
||||
qCDebug(PictureLoaderLocalLog).nospace()
|
||||
<< "[card: " << correctedCardName << " set: " << setName << "]: Picture.xlhq found on disk.";
|
||||
return image;
|
||||
|
||||
for (const QString &path : candidatePaths) {
|
||||
QFileInfo fileInfo(path);
|
||||
QDir dir = fileInfo.dir();
|
||||
QString baseName = fileInfo.fileName();
|
||||
|
||||
if (!dir.exists()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QStringList files = dir.entryList(QDir::Files);
|
||||
for (const QString &file : files) {
|
||||
if (!file.startsWith(baseName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QString fullPath = dir.filePath(file);
|
||||
imgReader.setFileName(fullPath);
|
||||
|
||||
if (imgReader.read(&image)) {
|
||||
qCDebug(PictureLoaderLocalLog).nospace()
|
||||
<< "[card: " << correctedCardName << " set: " << setName << "] Found picture at: " << fullPath;
|
||||
return image;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
qCDebug(PictureLoaderLocalLog).nospace()
|
||||
<< "[card: " << correctedCardName << " set: " << setName << "]: Picture NOT found on disk.";
|
||||
return QImage();
|
||||
|
|
@ -147,8 +154,3 @@ void PictureLoaderLocal::picsPathChanged()
|
|||
picsPath = SettingsCache::instance().getPicsPath();
|
||||
customPicsPath = SettingsCache::instance().getCustomPicsPath();
|
||||
}
|
||||
|
||||
void PictureLoaderLocal::setOverrideAllCardArtWithPersonalPreference(bool _overrideAllCardArtWithPersonalPreference)
|
||||
{
|
||||
overrideAllCardArtWithPersonalPreference = _overrideAllCardArtWithPersonalPreference;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,19 +24,19 @@ public:
|
|||
|
||||
private:
|
||||
QString picsPath, customPicsPath;
|
||||
bool overrideAllCardArtWithPersonalPreference;
|
||||
|
||||
QMultiHash<QString, QString> customFolderIndex; // multimap of cardName to picPaths
|
||||
QTimer *refreshTimer;
|
||||
|
||||
void refreshIndex();
|
||||
|
||||
QImage
|
||||
tryLoadCardImageFromDisk(const QString &setName, const QString &correctedCardName, bool searchCustomPics) const;
|
||||
QImage tryLoadCardImageFromDisk(const QString &setName,
|
||||
const QString &correctedCardName,
|
||||
const QString &collectorNumber,
|
||||
const QString &providerId) const;
|
||||
|
||||
private slots:
|
||||
void picsPathChanged();
|
||||
void setOverrideAllCardArtWithPersonalPreference(bool _overrideAllCardArtWithPersonalPreference);
|
||||
};
|
||||
|
||||
#endif // PICTURE_LOADER_LOCAL_H
|
||||
|
|
|
|||
|
|
@ -28,9 +28,9 @@ PictureToLoad::PictureToLoad(CardInfoPtr _card)
|
|||
QList<CardSetPtr> PictureToLoad::extractSetsSorted(const CardInfoPtr &card)
|
||||
{
|
||||
QList<CardSetPtr> sortedSets;
|
||||
for (const auto &cardInfoPerSetList : card->getSets()) {
|
||||
for (const auto &set : cardInfoPerSetList) {
|
||||
sortedSets << set.getPtr();
|
||||
for (const auto &printings : card->getSets()) {
|
||||
for (const auto &printing : printings) {
|
||||
sortedSets << printing.getSet();
|
||||
}
|
||||
}
|
||||
if (sortedSets.empty()) {
|
||||
|
|
@ -41,11 +41,11 @@ QList<CardSetPtr> PictureToLoad::extractSetsSorted(const CardInfoPtr &card)
|
|||
// If the user hasn't disabled arts other than their personal preference...
|
||||
if (!SettingsCache::instance().getOverrideAllCardArtWithPersonalPreference()) {
|
||||
// If the pixmapCacheKey corresponds to a specific set, we have to try to load it first.
|
||||
for (const auto &cardInfoPerSetList : card->getSets()) {
|
||||
for (const auto &set : cardInfoPerSetList) {
|
||||
if (QLatin1String("card_") + card->getName() + QString("_") + QString(set.getProperty("uuid")) ==
|
||||
for (const auto &printings : card->getSets()) {
|
||||
for (const auto &printing : printings) {
|
||||
if (QLatin1String("card_") + card->getName() + QString("_") + QString(printing.getProperty("uuid")) ==
|
||||
card->getPixmapCacheKey()) {
|
||||
long long setIndex = sortedSets.indexOf(set.getPtr());
|
||||
long long setIndex = sortedSets.indexOf(printing.getSet());
|
||||
CardSetPtr setForCardProviderID = sortedSets.takeAt(setIndex);
|
||||
sortedSets.prepend(setForCardProviderID);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -195,11 +195,11 @@ void DeckEditorDatabaseDisplayWidget::databaseCustomMenu(QPoint point)
|
|||
addToSideboard = menu.addAction(tr("Add to Sideboard"));
|
||||
selectPrinting = menu.addAction(tr("Select Printing"));
|
||||
if (canBeCommander(info)) {
|
||||
edhRecCommander = menu.addAction(tr("Show on EDHREC (Commander)"));
|
||||
edhRecCommander = menu.addAction(tr("Show on EDHRec (Commander)"));
|
||||
connect(edhRecCommander, &QAction::triggered, this,
|
||||
[this, info] { deckEditor->getTabSupervisor()->addEdhrecTab(info, true); });
|
||||
}
|
||||
edhRecCard = menu.addAction(tr("Show on EDHREC (Card)"));
|
||||
edhRecCard = menu.addAction(tr("Show on EDHRec (Card)"));
|
||||
|
||||
connect(addToDeck, &QAction::triggered, this, &DeckEditorDatabaseDisplayWidget::actAddCardToMainDeck);
|
||||
connect(addToSideboard, &QAction::triggered, this, &DeckEditorDatabaseDisplayWidget::actAddCardToSideboard);
|
||||
|
|
|
|||
|
|
@ -476,9 +476,9 @@ bool DeckEditorDeckDockWidget::swapCard(const QModelIndex ¤tIndex)
|
|||
const QString otherZoneName = zoneName == DECK_ZONE_MAIN ? DECK_ZONE_SIDE : DECK_ZONE_MAIN;
|
||||
|
||||
// Third argument (true) says create the card no matter what, even if not in DB
|
||||
QModelIndex newCardIndex = deckModel->addCard(
|
||||
cardName, CardDatabaseManager::getInstance()->getSpecificSetForCard(cardName, cardProviderID), otherZoneName,
|
||||
true);
|
||||
QModelIndex newCardIndex =
|
||||
deckModel->addCard(cardName, CardDatabaseManager::getInstance()->getSpecificPrinting(cardName, cardProviderID),
|
||||
otherZoneName, true);
|
||||
recursiveExpand(newCardIndex);
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
* @param deckView Pointer to the QTreeView for the deck display.
|
||||
* @param cardSizeSlider Pointer to the QSlider used for dynamic font resizing.
|
||||
* @param rootCard The root card for the widget.
|
||||
* @param setInfoForCard The set information for the card.
|
||||
* @param printingInfo The printing information for the card.
|
||||
*/
|
||||
AllZonesCardAmountWidget::AllZonesCardAmountWidget(QWidget *parent,
|
||||
AbstractTabDeckEditor *deckEditor,
|
||||
|
|
@ -24,9 +24,9 @@ AllZonesCardAmountWidget::AllZonesCardAmountWidget(QWidget *parent,
|
|||
QTreeView *deckView,
|
||||
QSlider *cardSizeSlider,
|
||||
CardInfoPtr rootCard,
|
||||
CardInfoPerSet setInfoForCard)
|
||||
PrintingInfo printingInfo)
|
||||
: QWidget(parent), deckEditor(deckEditor), deckModel(deckModel), deckView(deckView), cardSizeSlider(cardSizeSlider),
|
||||
rootCard(rootCard), setInfoForCard(setInfoForCard)
|
||||
rootCard(rootCard), printingInfo(printingInfo)
|
||||
{
|
||||
layout = new QVBoxLayout(this);
|
||||
layout->setAlignment(Qt::AlignHCenter);
|
||||
|
|
@ -36,10 +36,10 @@ AllZonesCardAmountWidget::AllZonesCardAmountWidget(QWidget *parent,
|
|||
|
||||
zoneLabelMainboard = new ShadowBackgroundLabel(this, tr("Mainboard"));
|
||||
buttonBoxMainboard = new CardAmountWidget(this, deckEditor, deckModel, deckView, cardSizeSlider, rootCard,
|
||||
setInfoForCard, DECK_ZONE_MAIN);
|
||||
printingInfo, DECK_ZONE_MAIN);
|
||||
zoneLabelSideboard = new ShadowBackgroundLabel(this, tr("Sideboard"));
|
||||
buttonBoxSideboard = new CardAmountWidget(this, deckEditor, deckModel, deckView, cardSizeSlider, rootCard,
|
||||
setInfoForCard, DECK_ZONE_SIDE);
|
||||
printingInfo, DECK_ZONE_SIDE);
|
||||
|
||||
layout->addWidget(zoneLabelMainboard, 0, Qt::AlignHCenter | Qt::AlignBottom);
|
||||
layout->addWidget(buttonBoxMainboard, 0, Qt::AlignHCenter | Qt::AlignTop);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public:
|
|||
QTreeView *deckView,
|
||||
QSlider *cardSizeSlider,
|
||||
CardInfoPtr rootCard,
|
||||
CardInfoPerSet setInfoForCard);
|
||||
PrintingInfo printingInfo);
|
||||
int getMainboardAmount();
|
||||
int getSideboardAmount();
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
|
|
@ -36,7 +36,7 @@ private:
|
|||
QTreeView *deckView;
|
||||
QSlider *cardSizeSlider;
|
||||
CardInfoPtr rootCard;
|
||||
CardInfoPerSet setInfoForCard;
|
||||
PrintingInfo printingInfo;
|
||||
QLabel *zoneLabelMainboard;
|
||||
CardAmountWidget *buttonBoxMainboard;
|
||||
QLabel *zoneLabelSideboard;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
* @param deckView Pointer to the QTreeView displaying the deck.
|
||||
* @param cardSizeSlider Pointer to the QSlider for adjusting font size.
|
||||
* @param rootCard The root card to manage within the widget.
|
||||
* @param setInfoForCard Card set information for the root card.
|
||||
* @param printingInfo Printing info for the root card.
|
||||
* @param zoneName The zone name (e.g., DECK_ZONE_MAIN or DECK_ZONE_SIDE).
|
||||
*/
|
||||
CardAmountWidget::CardAmountWidget(QWidget *parent,
|
||||
|
|
@ -21,10 +21,10 @@ CardAmountWidget::CardAmountWidget(QWidget *parent,
|
|||
QTreeView *deckView,
|
||||
QSlider *cardSizeSlider,
|
||||
CardInfoPtr &rootCard,
|
||||
CardInfoPerSet &setInfoForCard,
|
||||
PrintingInfo &printingInfo,
|
||||
const QString &zoneName)
|
||||
: QWidget(parent), deckEditor(deckEditor), deckModel(deckModel), deckView(deckView), cardSizeSlider(cardSizeSlider),
|
||||
rootCard(rootCard), setInfoForCard(setInfoForCard), zoneName(zoneName), hovered(false)
|
||||
rootCard(rootCard), printingInfo(printingInfo), zoneName(zoneName), hovered(false)
|
||||
{
|
||||
layout = new QHBoxLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
|
|
@ -142,18 +142,18 @@ void CardAmountWidget::updateCardCount()
|
|||
*/
|
||||
void CardAmountWidget::addPrinting(const QString &zone)
|
||||
{
|
||||
auto newCardIndex = deckModel->addCard(rootCard->getName(), setInfoForCard, zone);
|
||||
auto newCardIndex = deckModel->addCard(rootCard->getName(), printingInfo, zone);
|
||||
recursiveExpand(newCardIndex);
|
||||
QModelIndex find_card = deckModel->findCard(rootCard->getName(), zone);
|
||||
if (find_card.isValid() && find_card != newCardIndex) {
|
||||
auto amount = deckModel->data(find_card, Qt::DisplayRole);
|
||||
for (int i = 0; i < amount.toInt() - 1; i++) {
|
||||
deckModel->addCard(rootCard->getName(), setInfoForCard, zone);
|
||||
deckModel->addCard(rootCard->getName(), printingInfo, zone);
|
||||
}
|
||||
deckModel->removeRow(find_card.row(), find_card.parent());
|
||||
}
|
||||
newCardIndex = deckModel->findCard(rootCard->getName(), zone, setInfoForCard.getProperty("uuid"),
|
||||
setInfoForCard.getProperty("num"));
|
||||
newCardIndex = deckModel->findCard(rootCard->getName(), zone, printingInfo.getProperty("uuid"),
|
||||
printingInfo.getProperty("num"));
|
||||
deckView->setCurrentIndex(newCardIndex);
|
||||
deckView->setFocus(Qt::FocusReason::MouseFocusReason);
|
||||
deckEditor->setModified(true);
|
||||
|
|
@ -235,8 +235,8 @@ void CardAmountWidget::offsetCountAtIndex(const QModelIndex &idx, int offset)
|
|||
*/
|
||||
void CardAmountWidget::decrementCardHelper(const QString &zone)
|
||||
{
|
||||
QModelIndex idx = deckModel->findCard(rootCard->getName(), zone, setInfoForCard.getProperty("uuid"),
|
||||
setInfoForCard.getProperty("num"));
|
||||
QModelIndex idx = deckModel->findCard(rootCard->getName(), zone, printingInfo.getProperty("uuid"),
|
||||
printingInfo.getProperty("num"));
|
||||
offsetCountAtIndex(idx, -1);
|
||||
deckEditor->setModified(true);
|
||||
}
|
||||
|
|
@ -249,7 +249,7 @@ void CardAmountWidget::decrementCardHelper(const QString &zone)
|
|||
*/
|
||||
int CardAmountWidget::countCardsInZone(const QString &deckZone)
|
||||
{
|
||||
if (setInfoForCard.getProperty("uuid").isEmpty()) {
|
||||
if (printingInfo.getProperty("uuid").isEmpty()) {
|
||||
return 0; // Cards without uuids/providerIds CANNOT match another card, they are undefined for us.
|
||||
}
|
||||
|
||||
|
|
@ -286,7 +286,7 @@ int CardAmountWidget::countCardsInZone(const QString &deckZone)
|
|||
}
|
||||
|
||||
for (int k = 0; k < currentCard->getNumber(); ++k) {
|
||||
if (currentCard->getCardProviderId() == setInfoForCard.getProperty("uuid")) {
|
||||
if (currentCard->getCardProviderId() == printingInfo.getProperty("uuid")) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public:
|
|||
QTreeView *deckView,
|
||||
QSlider *cardSizeSlider,
|
||||
CardInfoPtr &rootCard,
|
||||
CardInfoPerSet &setInfoForCard,
|
||||
PrintingInfo &printingInfo,
|
||||
const QString &zoneName);
|
||||
int countCardsInZone(const QString &deckZone);
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ private:
|
|||
QTreeView *deckView;
|
||||
QSlider *cardSizeSlider;
|
||||
CardInfoPtr rootCard;
|
||||
CardInfoPerSet setInfoForCard;
|
||||
PrintingInfo printingInfo;
|
||||
QString zoneName;
|
||||
QHBoxLayout *layout;
|
||||
DynamicFontSizePushButton *incrementButton;
|
||||
|
|
|
|||
|
|
@ -33,24 +33,6 @@ PrintingSelector::PrintingSelector(QWidget *parent, AbstractTabDeckEditor *_deck
|
|||
layout = new QVBoxLayout(this);
|
||||
setLayout(layout);
|
||||
|
||||
if (PictureLoader::hasCustomArt()) {
|
||||
QFrame *warningFrame = new QFrame(this);
|
||||
warningFrame->setFrameShape(QFrame::StyledPanel);
|
||||
|
||||
warningLabel = new QLabel(this);
|
||||
warningLabel->setTextFormat(Qt::RichText);
|
||||
warningLabel->setWordWrap(true);
|
||||
|
||||
auto *warningLayout = new QVBoxLayout(warningFrame);
|
||||
warningFrame->setLayout(warningLayout);
|
||||
|
||||
warningLayout->addWidget(warningLabel);
|
||||
|
||||
layout->addWidget(warningFrame);
|
||||
} else {
|
||||
warningLabel = nullptr;
|
||||
}
|
||||
|
||||
widgetLoadingBufferTimer = new QTimer(this);
|
||||
|
||||
flowWidget = new FlowWidget(this, Qt::Horizontal, Qt::ScrollBarAlwaysOff, Qt::ScrollBarAsNeeded);
|
||||
|
|
@ -107,12 +89,6 @@ PrintingSelector::PrintingSelector(QWidget *parent, AbstractTabDeckEditor *_deck
|
|||
void PrintingSelector::retranslateUi()
|
||||
{
|
||||
navigationCheckBox->setText(tr("Display Navigation Buttons"));
|
||||
|
||||
if (warningLabel) {
|
||||
warningLabel->setText(
|
||||
tr("<b>Warning:</b> You appear to be using custom card art, which has known bugs when also "
|
||||
"using the printing selector in this version of Cockatrice."));
|
||||
}
|
||||
}
|
||||
|
||||
void PrintingSelector::printingsInDeckChanged()
|
||||
|
|
@ -224,27 +200,27 @@ void PrintingSelector::getAllSetsForCurrentCard()
|
|||
return;
|
||||
}
|
||||
|
||||
CardInfoPerSetMap cardInfoPerSets = selectedCard->getSets();
|
||||
const QList<CardInfoPerSet> sortedSets = sortToolBar->sortSets(cardInfoPerSets);
|
||||
const QList<CardInfoPerSet> filteredSets =
|
||||
sortToolBar->filterSets(sortedSets, searchBar->getSearchText().trimmed().toLower());
|
||||
QList<CardInfoPerSet> setsToUse;
|
||||
SetToPrintingsMap setMap = selectedCard->getSets();
|
||||
const QList<PrintingInfo> sortedPrintings = sortToolBar->sortSets(setMap);
|
||||
const QList<PrintingInfo> filteredPrintings =
|
||||
sortToolBar->filterSets(sortedPrintings, searchBar->getSearchText().trimmed().toLower());
|
||||
QList<PrintingInfo> printingsToUse;
|
||||
|
||||
if (SettingsCache::instance().getBumpSetsWithCardsInDeckToTop()) {
|
||||
setsToUse = sortToolBar->prependPrintingsInDeck(filteredSets, selectedCard, deckModel);
|
||||
printingsToUse = sortToolBar->prependPrintingsInDeck(filteredPrintings, selectedCard, deckModel);
|
||||
} else {
|
||||
setsToUse = filteredSets;
|
||||
printingsToUse = filteredPrintings;
|
||||
}
|
||||
setsToUse = sortToolBar->prependPinnedPrintings(setsToUse, selectedCard->getName());
|
||||
printingsToUse = sortToolBar->prependPinnedPrintings(printingsToUse, selectedCard->getName());
|
||||
|
||||
// Defer widget creation
|
||||
currentIndex = 0;
|
||||
|
||||
connect(widgetLoadingBufferTimer, &QTimer::timeout, this, [=, this]() mutable {
|
||||
for (int i = 0; i < BATCH_SIZE && currentIndex < setsToUse.size(); ++i, ++currentIndex) {
|
||||
for (int i = 0; i < BATCH_SIZE && currentIndex < printingsToUse.size(); ++i, ++currentIndex) {
|
||||
auto *cardDisplayWidget = new PrintingSelectorCardDisplayWidget(this, deckEditor, deckModel, deckView,
|
||||
cardSizeWidget->getSlider(), selectedCard,
|
||||
setsToUse[currentIndex], currentZone);
|
||||
printingsToUse[currentIndex], currentZone);
|
||||
flowWidget->addWidget(cardDisplayWidget);
|
||||
cardDisplayWidget->clampSetNameToPicture();
|
||||
connect(cardDisplayWidget, &PrintingSelectorCardDisplayWidget::cardPreferenceChanged, this,
|
||||
|
|
@ -252,7 +228,7 @@ void PrintingSelector::getAllSetsForCurrentCard()
|
|||
}
|
||||
|
||||
// Stop timer when done
|
||||
if (currentIndex >= setsToUse.size()) {
|
||||
if (currentIndex >= printingsToUse.size()) {
|
||||
widgetLoadingBufferTimer->stop();
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ private:
|
|||
QWidget *sortAndOptionsContainer;
|
||||
QHBoxLayout *sortAndOptionsLayout;
|
||||
QCheckBox *navigationCheckBox;
|
||||
QLabel *warningLabel;
|
||||
PrintingSelectorCardSortingWidget *sortToolBar;
|
||||
PrintingSelectorCardSearchWidget *searchBar;
|
||||
FlowWidget *flowWidget;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
* @param _deckView The QTreeView instance displaying the deck.
|
||||
* @param _cardSizeSlider The slider controlling the size of the displayed card.
|
||||
* @param _rootCard The root card object, representing the card to be displayed.
|
||||
* @param _setInfoForCard The set-specific information for the card being displayed.
|
||||
* @param _printingInfo The printing info for the card being displayed.
|
||||
* @param _currentZone The current zone in which the card is located.
|
||||
*/
|
||||
PrintingSelectorCardDisplayWidget::PrintingSelectorCardDisplayWidget(QWidget *parent,
|
||||
|
|
@ -33,10 +33,10 @@ PrintingSelectorCardDisplayWidget::PrintingSelectorCardDisplayWidget(QWidget *pa
|
|||
QTreeView *_deckView,
|
||||
QSlider *_cardSizeSlider,
|
||||
CardInfoPtr _rootCard,
|
||||
const CardInfoPerSet &_setInfoForCard,
|
||||
const PrintingInfo &_printingInfo,
|
||||
QString &_currentZone)
|
||||
: QWidget(parent), deckEditor(_deckEditor), deckModel(_deckModel), deckView(_deckView),
|
||||
cardSizeSlider(_cardSizeSlider), rootCard(std::move(_rootCard)), setInfoForCard(_setInfoForCard),
|
||||
cardSizeSlider(_cardSizeSlider), rootCard(std::move(_rootCard)), printingInfo(_printingInfo),
|
||||
currentZone(_currentZone)
|
||||
{
|
||||
layout = new QVBoxLayout(this);
|
||||
|
|
@ -45,15 +45,15 @@ PrintingSelectorCardDisplayWidget::PrintingSelectorCardDisplayWidget(QWidget *pa
|
|||
|
||||
// Create the overlay widget for the card display
|
||||
overlayWidget = new PrintingSelectorCardOverlayWidget(this, deckEditor, deckModel, deckView, cardSizeSlider,
|
||||
rootCard, setInfoForCard);
|
||||
rootCard, _printingInfo);
|
||||
connect(overlayWidget, &PrintingSelectorCardOverlayWidget::cardPreferenceChanged, this,
|
||||
[this]() { emit cardPreferenceChanged(); });
|
||||
|
||||
// Create the widget to display the set name and collector's number
|
||||
const QString combinedSetName =
|
||||
QString(setInfoForCard.getPtr()->getLongName() + " (" + setInfoForCard.getPtr()->getShortName() + ")");
|
||||
QString(_printingInfo.getSet()->getLongName() + " (" + _printingInfo.getSet()->getShortName() + ")");
|
||||
setNameAndCollectorsNumberDisplayWidget = new SetNameAndCollectorsNumberDisplayWidget(
|
||||
this, combinedSetName, setInfoForCard.getProperty("num"), cardSizeSlider);
|
||||
this, combinedSetName, _printingInfo.getProperty("num"), cardSizeSlider);
|
||||
|
||||
// Add the widgets to the layout
|
||||
layout->addWidget(overlayWidget, 0, Qt::AlignHCenter);
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public:
|
|||
QTreeView *_deckView,
|
||||
QSlider *_cardSizeSlider,
|
||||
CardInfoPtr _rootCard,
|
||||
const CardInfoPerSet &_setInfoForCard,
|
||||
const PrintingInfo &_printingInfo,
|
||||
QString &_currentZone);
|
||||
|
||||
public slots:
|
||||
|
|
@ -39,7 +39,7 @@ private:
|
|||
QSlider *cardSizeSlider;
|
||||
CardInfoPtr rootCard;
|
||||
CardInfoPtr setCard;
|
||||
CardInfoPerSet setInfoForCard;
|
||||
PrintingInfo printingInfo;
|
||||
QString currentZone;
|
||||
PrintingSelectorCardOverlayWidget *overlayWidget;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
* @param _deckView The QTreeView instance displaying the deck.
|
||||
* @param _cardSizeSlider The slider controlling the size of the card.
|
||||
* @param _rootCard The root card object that contains information about the card.
|
||||
* @param _setInfoForCard The set-specific information for the card being displayed.
|
||||
* @param _printingInfo The printing-specific information for the card being displayed.
|
||||
*/
|
||||
PrintingSelectorCardOverlayWidget::PrintingSelectorCardOverlayWidget(QWidget *parent,
|
||||
AbstractTabDeckEditor *_deckEditor,
|
||||
|
|
@ -30,9 +30,9 @@ PrintingSelectorCardOverlayWidget::PrintingSelectorCardOverlayWidget(QWidget *pa
|
|||
QTreeView *_deckView,
|
||||
QSlider *_cardSizeSlider,
|
||||
CardInfoPtr _rootCard,
|
||||
const CardInfoPerSet &_setInfoForCard)
|
||||
const PrintingInfo &_printingInfo)
|
||||
: QWidget(parent), deckEditor(_deckEditor), deckModel(_deckModel), deckView(_deckView),
|
||||
cardSizeSlider(_cardSizeSlider), rootCard(std::move(_rootCard)), setInfoForCard(_setInfoForCard)
|
||||
cardSizeSlider(_cardSizeSlider), rootCard(std::move(_rootCard)), printingInfo(_printingInfo)
|
||||
{
|
||||
// Set up the main layout
|
||||
auto *mainLayout = new QVBoxLayout(this);
|
||||
|
|
@ -45,13 +45,13 @@ PrintingSelectorCardOverlayWidget::PrintingSelectorCardOverlayWidget(QWidget *pa
|
|||
cardInfoPicture->setMinimumSize(0, 0);
|
||||
cardInfoPicture->setScaleFactor(cardSizeSlider->value());
|
||||
setCard = CardDatabaseManager::getInstance()->getCardByNameAndProviderId(rootCard->getName(),
|
||||
setInfoForCard.getProperty("uuid"));
|
||||
_printingInfo.getProperty("uuid"));
|
||||
cardInfoPicture->setCard(setCard);
|
||||
mainLayout->addWidget(cardInfoPicture);
|
||||
|
||||
// Add AllZonesCardAmountWidget
|
||||
allZonesCardAmountWidget =
|
||||
new AllZonesCardAmountWidget(this, deckEditor, deckModel, deckView, cardSizeSlider, setCard, setInfoForCard);
|
||||
new AllZonesCardAmountWidget(this, deckEditor, deckModel, deckView, cardSizeSlider, setCard, _printingInfo);
|
||||
|
||||
allZonesCardAmountWidget->raise(); // Ensure it's on top of the picture
|
||||
// Set initial visibility based on amounts
|
||||
|
|
@ -172,7 +172,7 @@ void PrintingSelectorCardOverlayWidget::customMenu(QPoint point)
|
|||
|
||||
const auto &preferredProviderId =
|
||||
SettingsCache::instance().cardOverrides().getCardPreferenceOverride(rootCard->getName());
|
||||
const auto &cardProviderId = setInfoForCard.getProperty("uuid");
|
||||
const auto &cardProviderId = printingInfo.getProperty("uuid");
|
||||
|
||||
if (preferredProviderId.isEmpty() || preferredProviderId != cardProviderId) {
|
||||
auto *pinAction = preferenceMenu->addAction(tr("Pin Printing"));
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public:
|
|||
QTreeView *_deckView,
|
||||
QSlider *_cardSizeSlider,
|
||||
CardInfoPtr _rootCard,
|
||||
const CardInfoPerSet &_setInfoForCard);
|
||||
const PrintingInfo &_printingInfo);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
|
|
@ -45,7 +45,7 @@ private:
|
|||
QSlider *cardSizeSlider;
|
||||
CardInfoPtr rootCard;
|
||||
CardInfoPtr setCard;
|
||||
CardInfoPerSet setInfoForCard;
|
||||
PrintingInfo printingInfo;
|
||||
};
|
||||
|
||||
#endif // PRINTING_SELECTOR_CARD_OVERLAY_WIDGET_H
|
||||
|
|
|
|||
|
|
@ -73,16 +73,16 @@ void PrintingSelectorCardSortingWidget::updateSortSetting()
|
|||
* - Contained in Deck
|
||||
* - Potential Cards in Deck
|
||||
*
|
||||
* @param cardInfoPerSets The list of card sets to be sorted.
|
||||
* @return A sorted list of card sets.
|
||||
* @param setMap The list of card sets to be sorted.
|
||||
* @return A sorted list of printings.
|
||||
*/
|
||||
QList<CardInfoPerSet> PrintingSelectorCardSortingWidget::sortSets(const CardInfoPerSetMap &cardInfoPerSets)
|
||||
QList<PrintingInfo> PrintingSelectorCardSortingWidget::sortSets(const SetToPrintingsMap &setMap)
|
||||
{
|
||||
QList<CardSetPtr> sortedSets;
|
||||
|
||||
for (const auto &cardInfoPerSetList : cardInfoPerSets) {
|
||||
for (const auto &set : cardInfoPerSetList) {
|
||||
sortedSets << set.getPtr();
|
||||
for (const auto &printingInfos : setMap) {
|
||||
for (const auto &set : printingInfos) {
|
||||
sortedSets << set.getSet();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -98,14 +98,14 @@ QList<CardInfoPerSet> PrintingSelectorCardSortingWidget::sortSets(const CardInfo
|
|||
std::sort(sortedSets.begin(), sortedSets.end(), SetReleaseDateComparator());
|
||||
}
|
||||
|
||||
QList<CardInfoPerSet> sortedCardInfoPerSets;
|
||||
// Reconstruct sorted list of CardInfoPerSet
|
||||
QList<PrintingInfo> sortedPrintings;
|
||||
// Reconstruct sorted list of PrintingInfo
|
||||
for (const auto &set : sortedSets) {
|
||||
for (auto it = cardInfoPerSets.begin(); it != cardInfoPerSets.end(); ++it) {
|
||||
for (const auto &cardInfoPerSet : it.value()) {
|
||||
if (cardInfoPerSet.getPtr() == set) {
|
||||
if (!sortedCardInfoPerSets.contains(cardInfoPerSet)) {
|
||||
sortedCardInfoPerSets << cardInfoPerSet;
|
||||
for (auto it = setMap.begin(); it != setMap.end(); ++it) {
|
||||
for (const auto &printingInfo : it.value()) {
|
||||
if (printingInfo.getSet() == set) {
|
||||
if (!sortedPrintings.contains(printingInfo)) {
|
||||
sortedPrintings << printingInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -113,10 +113,10 @@ QList<CardInfoPerSet> PrintingSelectorCardSortingWidget::sortSets(const CardInfo
|
|||
}
|
||||
|
||||
if (descendingSort) {
|
||||
std::reverse(sortedCardInfoPerSets.begin(), sortedCardInfoPerSets.end());
|
||||
std::reverse(sortedPrintings.begin(), sortedPrintings.end());
|
||||
}
|
||||
|
||||
return sortedCardInfoPerSets;
|
||||
return sortedPrintings;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -126,81 +126,81 @@ QList<CardInfoPerSet> PrintingSelectorCardSortingWidget::sortSets(const CardInfo
|
|||
* text. If the search text matches either the long or short name of a card set, that set is included in the filtered
|
||||
* list.
|
||||
*
|
||||
* @param sets The list of card sets to be filtered.
|
||||
* @param printings The list of printings to be filtered.
|
||||
* @param searchText The search text used to filter the card sets.
|
||||
* @return A filtered list of card sets.
|
||||
*/
|
||||
QList<CardInfoPerSet> PrintingSelectorCardSortingWidget::filterSets(const QList<CardInfoPerSet> &sets,
|
||||
const QString &searchText)
|
||||
QList<PrintingInfo> PrintingSelectorCardSortingWidget::filterSets(const QList<PrintingInfo> &printings,
|
||||
const QString &searchText)
|
||||
{
|
||||
if (searchText.isEmpty()) {
|
||||
return sets;
|
||||
return printings;
|
||||
}
|
||||
|
||||
QList<CardInfoPerSet> filteredSets;
|
||||
QList<PrintingInfo> filteredPrintings;
|
||||
|
||||
for (const auto &set : sets) {
|
||||
const QString longName = set.getPtr()->getLongName().toLower();
|
||||
const QString shortName = set.getPtr()->getShortName().toLower();
|
||||
for (const auto &printing : printings) {
|
||||
const QString longName = printing.getSet()->getLongName().toLower();
|
||||
const QString shortName = printing.getSet()->getShortName().toLower();
|
||||
|
||||
if (longName.contains(searchText) || shortName.contains(searchText)) {
|
||||
filteredSets << set;
|
||||
filteredPrintings << printing;
|
||||
}
|
||||
}
|
||||
|
||||
return filteredSets;
|
||||
return filteredPrintings;
|
||||
}
|
||||
|
||||
QList<CardInfoPerSet> PrintingSelectorCardSortingWidget::prependPinnedPrintings(const QList<CardInfoPerSet> &sets,
|
||||
const QString &cardName)
|
||||
QList<PrintingInfo> PrintingSelectorCardSortingWidget::prependPinnedPrintings(const QList<PrintingInfo> &printings,
|
||||
const QString &cardName)
|
||||
{
|
||||
auto setsToUse = sets;
|
||||
auto printingsToUse = printings;
|
||||
const auto &cardProviderId = SettingsCache::instance().cardOverrides().getCardPreferenceOverride(cardName);
|
||||
if (!cardProviderId.isEmpty()) {
|
||||
for (int i = 0; i < setsToUse.size(); ++i) {
|
||||
const auto &card = setsToUse[i];
|
||||
for (int i = 0; i < printingsToUse.size(); ++i) {
|
||||
const auto &card = printingsToUse[i];
|
||||
if (card.getProperty("uuid") == cardProviderId) {
|
||||
setsToUse.move(i, 0);
|
||||
printingsToUse.move(i, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return setsToUse;
|
||||
return printingsToUse;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Prepend card printings that are contained in the deck to the list of card sets.
|
||||
* @brief Prepend card printings that are contained in the deck to the list of printings.
|
||||
*
|
||||
* This function adjusts the list of card sets by moving the printings that are already contained in the deck to the
|
||||
* This function adjusts the list of printings by moving the printings that are already contained in the deck to the
|
||||
* beginning of the list, sorted by the count of cards in the deck.
|
||||
*
|
||||
* @param sets The original list of card sets.
|
||||
* @param printings The original list of printings.
|
||||
* @param selectedCard The currently selected card.
|
||||
* @param deckModel The model representing the deck.
|
||||
* @return A list of card sets with the printings contained in the deck prepended.
|
||||
* @return A list of printings with the printings contained in the deck prepended.
|
||||
*/
|
||||
QList<CardInfoPerSet> PrintingSelectorCardSortingWidget::prependPrintingsInDeck(const QList<CardInfoPerSet> &sets,
|
||||
const CardInfoPtr &selectedCard,
|
||||
DeckListModel *deckModel)
|
||||
QList<PrintingInfo> PrintingSelectorCardSortingWidget::prependPrintingsInDeck(const QList<PrintingInfo> &printings,
|
||||
const CardInfoPtr &selectedCard,
|
||||
DeckListModel *deckModel)
|
||||
{
|
||||
if (!selectedCard) {
|
||||
return {};
|
||||
}
|
||||
|
||||
CardInfoPerSetMap cardInfoPerSets = selectedCard->getSets();
|
||||
QList<QPair<CardInfoPerSet, int>> countList;
|
||||
SetToPrintingsMap setMap = selectedCard->getSets();
|
||||
QList<QPair<PrintingInfo, int>> countList;
|
||||
|
||||
// Collect sets with their counts
|
||||
for (const auto &cardInfoPerSetList : cardInfoPerSets) {
|
||||
for (const auto &cardInfoPerSet : cardInfoPerSetList) {
|
||||
for (const auto &printingList : setMap) {
|
||||
for (const auto &printing : printingList) {
|
||||
QModelIndex find_card =
|
||||
deckModel->findCard(selectedCard->getName(), DECK_ZONE_MAIN, cardInfoPerSet.getProperty("uuid"));
|
||||
deckModel->findCard(selectedCard->getName(), DECK_ZONE_MAIN, printing.getProperty("uuid"));
|
||||
if (find_card.isValid()) {
|
||||
int count =
|
||||
deckModel->data(find_card, Qt::DisplayRole).toInt(); // Ensure the count is treated as an integer
|
||||
if (count > 0) {
|
||||
countList.append(qMakePair(cardInfoPerSet, count));
|
||||
countList.append(qMakePair(printing, count));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -209,16 +209,16 @@ QList<CardInfoPerSet> PrintingSelectorCardSortingWidget::prependPrintingsInDeck(
|
|||
|
||||
// Sort sets by count in descending numerical order
|
||||
std::sort(countList.begin(), countList.end(),
|
||||
[](const QPair<CardInfoPerSet, int> &a, const QPair<CardInfoPerSet, int> &b) {
|
||||
[](const QPair<PrintingInfo, int> &a, const QPair<PrintingInfo, int> &b) {
|
||||
return a.second > b.second; // Ensure numerical comparison
|
||||
});
|
||||
|
||||
// Create a copy of the original list to modify
|
||||
QList<CardInfoPerSet> result = sets;
|
||||
QList<PrintingInfo> result = printings;
|
||||
|
||||
// Prepend sorted sets and remove them from the original list
|
||||
for (const auto &pair : countList) {
|
||||
auto it = std::find_if(result.begin(), result.end(), [&pair](const CardInfoPerSet &item) {
|
||||
auto it = std::find_if(result.begin(), result.end(), [&pair](const PrintingInfo &item) {
|
||||
return item.getProperty("uuid") == pair.first.getProperty("uuid");
|
||||
});
|
||||
if (it != result.end()) {
|
||||
|
|
|
|||
|
|
@ -12,12 +12,12 @@ class PrintingSelectorCardSortingWidget : public QWidget
|
|||
Q_OBJECT
|
||||
public:
|
||||
explicit PrintingSelectorCardSortingWidget(PrintingSelector *parent);
|
||||
QList<CardInfoPerSet> sortSets(const CardInfoPerSetMap &cardInfoPerSets);
|
||||
QList<CardInfoPerSet> filterSets(const QList<CardInfoPerSet> &sets, const QString &searchText);
|
||||
QList<CardInfoPerSet> prependPinnedPrintings(const QList<CardInfoPerSet> &sets, const QString &cardName);
|
||||
QList<CardInfoPerSet> prependPrintingsInDeck(const QList<CardInfoPerSet> &sets,
|
||||
const CardInfoPtr &selectedCard,
|
||||
DeckListModel *deckModel);
|
||||
QList<PrintingInfo> sortSets(const SetToPrintingsMap &setMap);
|
||||
QList<PrintingInfo> filterSets(const QList<PrintingInfo> &printings, const QString &searchText);
|
||||
QList<PrintingInfo> prependPinnedPrintings(const QList<PrintingInfo> &printings, const QString &cardName);
|
||||
QList<PrintingInfo> prependPrintingsInDeck(const QList<PrintingInfo> &printings,
|
||||
const CardInfoPtr &selectedCard,
|
||||
DeckListModel *deckModel);
|
||||
|
||||
public slots:
|
||||
void updateSortOrder();
|
||||
|
|
|
|||
|
|
@ -230,11 +230,11 @@ void VisualDatabaseDisplayWidget::populateCards()
|
|||
|
||||
if (CardInfoPtr info = CardDatabaseManager::getInstance()->getCard(name.toString())) {
|
||||
if (setFilter) {
|
||||
CardInfoPerSetMap setMap = info->getSets();
|
||||
SetToPrintingsMap setMap = info->getSets();
|
||||
if (setMap.contains(setFilter->term())) {
|
||||
for (CardInfoPerSet cardSetInstance : setMap[setFilter->term()]) {
|
||||
for (PrintingInfo printing : setMap[setFilter->term()]) {
|
||||
addCard(CardDatabaseManager::getInstance()->getCardByNameAndProviderId(
|
||||
name.toString(), cardSetInstance.getProperty("uuid")));
|
||||
name.toString(), printing.getProperty("uuid")));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -296,11 +296,11 @@ void VisualDatabaseDisplayWidget::loadNextPage()
|
|||
QVariant name = databaseDisplayModel->data(index, Qt::DisplayRole);
|
||||
if (CardInfoPtr info = CardDatabaseManager::getInstance()->getCard(name.toString())) {
|
||||
if (setFilter) {
|
||||
CardInfoPerSetMap setMap = info->getSets();
|
||||
SetToPrintingsMap setMap = info->getSets();
|
||||
if (setMap.contains(setFilter->term())) {
|
||||
for (CardInfoPerSet cardSetInstance : setMap[setFilter->term()]) {
|
||||
for (PrintingInfo printing : setMap[setFilter->term()]) {
|
||||
addCard(CardDatabaseManager::getInstance()->getCardByNameAndProviderId(
|
||||
name.toString(), cardSetInstance.getProperty("uuid")));
|
||||
name.toString(), printing.getProperty("uuid")));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -367,17 +367,16 @@ QModelIndex DeckListModel::findCard(const QString &cardName,
|
|||
|
||||
QModelIndex DeckListModel::addPreferredPrintingCard(const QString &cardName, const QString &zoneName, bool abAddAnyway)
|
||||
{
|
||||
return addCard(cardName, CardDatabaseManager::getInstance()->getPreferredSetForCard(cardName), zoneName,
|
||||
abAddAnyway);
|
||||
return addCard(cardName, CardDatabaseManager::getInstance()->getPreferredPrinting(cardName), zoneName, abAddAnyway);
|
||||
}
|
||||
|
||||
QModelIndex DeckListModel::addCard(const QString &cardName,
|
||||
const CardInfoPerSet &cardInfoSet,
|
||||
const PrintingInfo &printingInfo,
|
||||
const QString &zoneName,
|
||||
bool abAddAnyway)
|
||||
{
|
||||
CardInfoPtr cardInfo =
|
||||
CardDatabaseManager::getInstance()->getCardByNameAndProviderId(cardName, cardInfoSet.getProperty("uuid"));
|
||||
CardDatabaseManager::getInstance()->getCardByNameAndProviderId(cardName, printingInfo.getProperty("uuid"));
|
||||
|
||||
if (cardInfo == nullptr) {
|
||||
if (abAddAnyway) {
|
||||
|
|
@ -398,15 +397,15 @@ QModelIndex DeckListModel::addCard(const QString &cardName,
|
|||
|
||||
const QModelIndex parentIndex = nodeToIndex(groupNode);
|
||||
auto *cardNode = dynamic_cast<DecklistModelCardNode *>(groupNode->findCardChildByNameProviderIdAndNumber(
|
||||
cardName, cardInfoSet.getProperty("uuid"), cardInfoSet.getProperty("num")));
|
||||
const auto cardSetName = cardInfoSet.getPtr().isNull() ? "" : cardInfoSet.getPtr()->getCorrectedShortName();
|
||||
cardName, printingInfo.getProperty("uuid"), printingInfo.getProperty("num")));
|
||||
const auto cardSetName = printingInfo.getSet().isNull() ? "" : printingInfo.getSet()->getCorrectedShortName();
|
||||
|
||||
if (!cardNode) {
|
||||
// Determine the correct index
|
||||
int insertRow = findSortedInsertRow(groupNode, cardInfo);
|
||||
|
||||
auto *decklistCard = deckList->addCard(cardInfo->getName(), zoneName, insertRow, cardSetName,
|
||||
cardInfoSet.getProperty("num"), cardInfoSet.getProperty("uuid"));
|
||||
printingInfo.getProperty("num"), printingInfo.getProperty("uuid"));
|
||||
|
||||
beginInsertRows(parentIndex, insertRow, insertRow);
|
||||
cardNode = new DecklistModelCardNode(decklistCard, groupNode, insertRow);
|
||||
|
|
@ -414,8 +413,8 @@ QModelIndex DeckListModel::addCard(const QString &cardName,
|
|||
} else {
|
||||
cardNode->setNumber(cardNode->getNumber() + 1);
|
||||
cardNode->setCardSetShortName(cardSetName);
|
||||
cardNode->setCardCollectorNumber(cardInfoSet.getProperty("num"));
|
||||
cardNode->setCardProviderId(cardInfoSet.getProperty("uuid"));
|
||||
cardNode->setCardCollectorNumber(printingInfo.getProperty("num"));
|
||||
cardNode->setCardProviderId(printingInfo.getProperty("uuid"));
|
||||
deckList->refreshDeckHash();
|
||||
}
|
||||
sort(lastKnownColumn, lastKnownOrder);
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ public:
|
|||
const QString &cardNumber = "") const;
|
||||
QModelIndex addPreferredPrintingCard(const QString &cardName, const QString &zoneName, bool abAddAnyway);
|
||||
QModelIndex addCard(const ::QString &cardName,
|
||||
const CardInfoPerSet &cardInfoSet,
|
||||
const PrintingInfo &printingInfo,
|
||||
const QString &zoneName,
|
||||
bool abAddAnyway = false);
|
||||
int findSortedInsertRow(InnerDecklistNode *parent, CardInfoPtr cardInfo) const;
|
||||
|
|
|
|||
|
|
@ -324,12 +324,10 @@ struct SetProviderIdToPreferred
|
|||
void operator()(const InnerDecklistNode *node, DecklistCardNode *card) const
|
||||
{
|
||||
Q_UNUSED(node);
|
||||
CardInfoPerSet preferredSet = CardDatabaseManager::getInstance()->getSpecificSetForCard(
|
||||
card->getName(),
|
||||
CardDatabaseManager::getInstance()->getPreferredPrintingProviderIdForCard(card->getName()));
|
||||
QString providerId = preferredSet.getProperty("uuid");
|
||||
QString setShortName = preferredSet.getPtr()->getShortName();
|
||||
QString collectorNumber = preferredSet.getProperty("num");
|
||||
PrintingInfo preferredPrinting = CardDatabaseManager::getInstance()->getPreferredPrinting(card->getName());
|
||||
QString providerId = preferredPrinting.getProperty("uuid");
|
||||
QString setShortName = preferredPrinting.getSet()->getShortName();
|
||||
QString collectorNumber = preferredPrinting.getProperty("num");
|
||||
|
||||
card->setCardProviderId(providerId);
|
||||
card->setCardCollectorNumber(collectorNumber);
|
||||
|
|
@ -360,7 +358,7 @@ void DeckLoader::resolveSetNameAndNumberToProviderID()
|
|||
// Retrieve the providerId based on setName and collectorNumber
|
||||
QString providerId =
|
||||
CardDatabaseManager::getInstance()
|
||||
->getSpecificSetForCard(card->getName(), card->getCardSetShortName(), card->getCardCollectorNumber())
|
||||
->getSpecificPrinting(card->getName(), card->getCardSetShortName(), card->getCardCollectorNumber())
|
||||
.getProperty("uuid");
|
||||
|
||||
// Set the providerId on the card
|
||||
|
|
|
|||
|
|
@ -162,8 +162,8 @@ void DlgEditTokens::actAddToken()
|
|||
}
|
||||
|
||||
QString setName = CardSet::TOKENS_SETNAME;
|
||||
CardInfoPerSetMap sets;
|
||||
sets[setName].append(CardInfoPerSet(databaseModel->getDatabase()->getSet(setName)));
|
||||
SetToPrintingsMap sets;
|
||||
sets[setName].append(PrintingInfo(databaseModel->getDatabase()->getSet(setName)));
|
||||
CardInfoPtr card = CardInfo::newInstance(name, "", true, QVariantHash(), QList<CardRelation *>(),
|
||||
QList<CardRelation *>(), sets, false, false, -1, false);
|
||||
card->setCardType("Token");
|
||||
|
|
|
|||
145
cockatrice/src/dialogs/dlg_load_deck_from_website.cpp
Normal file
145
cockatrice/src/dialogs/dlg_load_deck_from_website.cpp
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
#include "dlg_load_deck_from_website.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QEventLoop>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QMessageBox>
|
||||
#include <QNetworkReply>
|
||||
|
||||
DlgLoadDeckFromWebsite::DlgLoadDeckFromWebsite(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
nam = new QNetworkAccessManager(this);
|
||||
|
||||
layout = new QVBoxLayout(this);
|
||||
setLayout(layout);
|
||||
|
||||
instructionLabel = new QLabel(this);
|
||||
layout->addWidget(instructionLabel);
|
||||
|
||||
urlEdit = new QLineEdit(this);
|
||||
urlEdit->setText(QApplication::clipboard()->text());
|
||||
|
||||
layout->addWidget(urlEdit);
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
|
||||
layout->addWidget(buttonBox);
|
||||
|
||||
if (testValidUrl()) {
|
||||
QMetaObject::invokeMethod(this, "accept", Qt::QueuedConnection);
|
||||
hide();
|
||||
}
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void DlgLoadDeckFromWebsite::retranslateUi()
|
||||
{
|
||||
instructionLabel->setText(tr("Paste a link to a decklist site here to import it.\n(Archidekt, Deckstats, Moxfield, "
|
||||
"and TappedOut are supported.)"));
|
||||
}
|
||||
|
||||
bool DlgLoadDeckFromWebsite::testValidUrl()
|
||||
{
|
||||
ParsedDeckInfo info;
|
||||
return DeckLinkToApiTransformer::parseDeckUrl(urlEdit->text(), info);
|
||||
}
|
||||
|
||||
void DlgLoadDeckFromWebsite::accept()
|
||||
{
|
||||
ParsedDeckInfo info;
|
||||
if (DeckLinkToApiTransformer::parseDeckUrl(urlEdit->text(), info)) {
|
||||
qCInfo(DlgLoadDeckFromWebsiteLog) << info.baseUrl << info.deckID << info.fullUrl;
|
||||
|
||||
auto jsonParser = createParserForProvider(info.provider);
|
||||
if (!jsonParser && info.provider != DeckProvider::Deckstats && info.provider != DeckProvider::TappedOut) {
|
||||
qCWarning(DlgLoadDeckFromWebsiteLog) << "No parser found for provider";
|
||||
QMessageBox::warning(this, tr("Load Deck from Website"),
|
||||
tr("No parser available for this deck provider.\n (Archidekt, Deckstats, Moxfield, "
|
||||
"and TappedOut are supported.)"));
|
||||
QDialog::reject();
|
||||
return;
|
||||
}
|
||||
|
||||
QNetworkRequest request(QUrl(info.fullUrl));
|
||||
QNetworkReply *reply = nam->get(request);
|
||||
|
||||
QEventLoop loop;
|
||||
connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
||||
loop.exec();
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(DlgLoadDeckFromWebsiteLog) << "Network error:" << reply->errorString();
|
||||
QMessageBox::warning(this, tr("Load Deck from Website"), tr("Network error: %1").arg(reply->errorString()));
|
||||
reply->deleteLater();
|
||||
QDialog::reject();
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray responseData = reply->readAll();
|
||||
reply->deleteLater();
|
||||
|
||||
// Special handling for Deckstats and TappedOut .txt
|
||||
if (info.provider == DeckProvider::Deckstats || info.provider == DeckProvider::TappedOut) {
|
||||
QString deckText = QString::fromUtf8(responseData);
|
||||
if (deckText.isEmpty()) {
|
||||
qCWarning(DlgLoadDeckFromWebsiteLog) << "Response is empty";
|
||||
QMessageBox::warning(this, tr("Load Deck from Website"), tr("Received empty deck data."));
|
||||
QDialog::reject();
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse the plain text deck here
|
||||
DeckLoader *loader = new DeckLoader();
|
||||
QTextStream stream(&deckText);
|
||||
loader->loadFromStream_Plain(stream, false);
|
||||
loader->resolveSetNameAndNumberToProviderID();
|
||||
deck = loader;
|
||||
|
||||
QDialog::accept();
|
||||
return;
|
||||
}
|
||||
|
||||
// Normal JSON parsing for other providers
|
||||
QJsonParseError parseError;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(responseData, &parseError);
|
||||
if (parseError.error != QJsonParseError::NoError) {
|
||||
qCWarning(DlgLoadDeckFromWebsiteLog) << "JSON parse error:" << parseError.errorString();
|
||||
QMessageBox::warning(this, tr("Load Deck from Website"),
|
||||
tr("Failed to parse deck data: %1").arg(parseError.errorString()));
|
||||
QDialog::reject();
|
||||
return;
|
||||
}
|
||||
|
||||
deck = jsonParser->parse(doc.object());
|
||||
QDialog::accept();
|
||||
|
||||
} else {
|
||||
qCInfo(DlgLoadDeckFromWebsiteLog) << "URL not recognized";
|
||||
QMessageBox::warning(this, tr("Load Deck from Website"),
|
||||
tr("The provided URL is not recognized as a valid deck URL.\n"
|
||||
"Valid deck URLs look like this:\n\n"
|
||||
"https://archidekt.com/decks/9999999\n"
|
||||
"https://deckstats.net/decks/99999/9999999-your-deck-name/en\n"
|
||||
"https://moxfield.com/decks/XYZxx-XYZ99Yyy-xyzXzzz\n"
|
||||
"https://tappedout.net/mtg-decks/your-deck-name/"));
|
||||
QDialog::reject();
|
||||
}
|
||||
}
|
||||
|
||||
QSharedPointer<IJsonDeckParser> DlgLoadDeckFromWebsite::createParserForProvider(DeckProvider provider)
|
||||
{
|
||||
switch (provider) {
|
||||
case DeckProvider::Archidekt:
|
||||
return QSharedPointer<IJsonDeckParser>(new ArchidektJsonParser());
|
||||
case DeckProvider::Moxfield:
|
||||
return QSharedPointer<IJsonDeckParser>(new MoxfieldJsonParser());
|
||||
default:
|
||||
return QSharedPointer<IJsonDeckParser>(nullptr);
|
||||
}
|
||||
}
|
||||
40
cockatrice/src/dialogs/dlg_load_deck_from_website.h
Normal file
40
cockatrice/src/dialogs/dlg_load_deck_from_website.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#ifndef DLG_LOAD_DECK_FROM_WEBSITE_H
|
||||
#define DLG_LOAD_DECK_FROM_WEBSITE_H
|
||||
|
||||
#include "../client/network/parsers/deck_link_to_api_transformer.h"
|
||||
#include "../client/network/parsers/interface_json_deck_parser.h"
|
||||
|
||||
#include <QDialog>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
inline Q_LOGGING_CATEGORY(DlgLoadDeckFromWebsiteLog, "dlg_load_deck_from_website");
|
||||
|
||||
class DlgLoadDeckFromWebsite : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DlgLoadDeckFromWebsite(QWidget *parent);
|
||||
void retranslateUi();
|
||||
bool testValidUrl();
|
||||
DeckLoader *deck;
|
||||
|
||||
DeckLoader *getDeck()
|
||||
{
|
||||
return deck;
|
||||
}
|
||||
|
||||
private:
|
||||
QNetworkAccessManager *nam;
|
||||
QVBoxLayout *layout;
|
||||
QLabel *instructionLabel;
|
||||
QLineEdit *urlEdit;
|
||||
|
||||
public slots:
|
||||
void accept() override;
|
||||
QSharedPointer<IJsonDeckParser> createParserForProvider(DeckProvider provider);
|
||||
};
|
||||
|
||||
#endif // DLG_LOAD_DECK_FROM_WEBSITE_H
|
||||
|
|
@ -152,7 +152,7 @@ void DlgSelectSetForCards::actOK()
|
|||
continue;
|
||||
}
|
||||
model->removeRow(find_card.row(), find_card.parent());
|
||||
model->addCard(card, CardDatabaseManager::getInstance()->getSpecificSetForCard(card, modifiedSet, ""),
|
||||
model->addCard(card, CardDatabaseManager::getInstance()->getSpecificPrinting(card, modifiedSet, ""),
|
||||
DECK_ZONE_MAIN);
|
||||
}
|
||||
}
|
||||
|
|
@ -226,8 +226,8 @@ QMap<QString, int> DlgSelectSetForCards::getSetsForCards()
|
|||
if (!infoPtr)
|
||||
continue;
|
||||
|
||||
CardInfoPerSetMap infoPerSetMap = infoPtr->getSets();
|
||||
for (auto it = infoPerSetMap.begin(); it != infoPerSetMap.end(); ++it) {
|
||||
SetToPrintingsMap setMap = infoPtr->getSets();
|
||||
for (auto it = setMap.begin(); it != setMap.end(); ++it) {
|
||||
setCounts[it.key()]++;
|
||||
}
|
||||
}
|
||||
|
|
@ -297,7 +297,7 @@ void DlgSelectSetForCards::updateCardLists()
|
|||
} else {
|
||||
CardInfoPtr infoPtr = CardDatabaseManager::getInstance()->getCardByNameAndProviderId(
|
||||
currentCard->getName(), CardDatabaseManager::getInstance()
|
||||
->getSpecificSetForCard(currentCard->getName(), foundSetName, "")
|
||||
->getSpecificPrinting(currentCard->getName(), foundSetName, "")
|
||||
.getProperty("uuid"));
|
||||
CardInfoPictureWidget *picture_widget = new CardInfoPictureWidget(modifiedCardsFlowWidget);
|
||||
picture_widget->setCard(infoPtr);
|
||||
|
|
@ -380,8 +380,8 @@ QMap<QString, QStringList> DlgSelectSetForCards::getCardsForSets()
|
|||
if (!infoPtr)
|
||||
continue;
|
||||
|
||||
CardInfoPerSetMap infoPerSetMap = infoPtr->getSets();
|
||||
for (auto it = infoPerSetMap.begin(); it != infoPerSetMap.end(); ++it) {
|
||||
SetToPrintingsMap setMap = infoPtr->getSets();
|
||||
for (auto it = setMap.begin(); it != setMap.end(); ++it) {
|
||||
setCards[it.key()].append(currentCard->getName());
|
||||
}
|
||||
}
|
||||
|
|
@ -628,7 +628,7 @@ void SetEntryWidget::updateCardDisplayWidgets()
|
|||
CardInfoPictureWidget *picture_widget = new CardInfoPictureWidget(cardListContainer);
|
||||
picture_widget->setCard(CardDatabaseManager::getInstance()->getCardByNameAndProviderId(
|
||||
cardName,
|
||||
CardDatabaseManager::getInstance()->getSpecificSetForCard(cardName, setName, nullptr).getProperty("uuid")));
|
||||
CardDatabaseManager::getInstance()->getSpecificPrinting(cardName, setName, nullptr).getProperty("uuid")));
|
||||
cardListContainer->addWidget(picture_widget);
|
||||
}
|
||||
|
||||
|
|
@ -636,7 +636,7 @@ void SetEntryWidget::updateCardDisplayWidgets()
|
|||
CardInfoPictureWidget *picture_widget = new CardInfoPictureWidget(alreadySelectedCardListContainer);
|
||||
picture_widget->setCard(CardDatabaseManager::getInstance()->getCardByNameAndProviderId(
|
||||
cardName,
|
||||
CardDatabaseManager::getInstance()->getSpecificSetForCard(cardName, setName, nullptr).getProperty("uuid")));
|
||||
CardDatabaseManager::getInstance()->getSpecificPrinting(cardName, setName, nullptr).getProperty("uuid")));
|
||||
alreadySelectedCardListContainer->addWidget(picture_widget);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ void AbstractCardItem::refreshCardInfo()
|
|||
QVariantHash properties = QVariantHash();
|
||||
|
||||
info = CardInfo::newInstance(name, "", true, QVariantHash(), QList<CardRelation *>(), QList<CardRelation *>(),
|
||||
CardInfoPerSetMap(), false, false, -1, false);
|
||||
SetToPrintingsMap(), false, false, -1, false);
|
||||
}
|
||||
if (info.data()) {
|
||||
connect(info.data(), &CardInfo::pixmapUpdated, this, &AbstractCardItem::pixmapUpdated);
|
||||
|
|
|
|||
|
|
@ -44,11 +44,9 @@ void CardDatabase::clear()
|
|||
{
|
||||
clearDatabaseMutex->lock();
|
||||
|
||||
QHashIterator<QString, CardInfoPtr> i(cards);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
if (i.value()) {
|
||||
removeCard(i.value());
|
||||
for (const auto &card : cards.values()) {
|
||||
if (card) {
|
||||
removeCard(card);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -73,9 +71,9 @@ void CardDatabase::addCard(CardInfoPtr card)
|
|||
// if card already exists just add the new set property
|
||||
if (cards.contains(card->getName())) {
|
||||
CardInfoPtr sameCard = cards[card->getName()];
|
||||
for (const auto &cardInfoPerSetList : card->getSets()) {
|
||||
for (const CardInfoPerSet &set : cardInfoPerSetList) {
|
||||
sameCard->addToSet(set.getPtr(), set);
|
||||
for (const auto &printings : card->getSets()) {
|
||||
for (const PrintingInfo &printing : printings) {
|
||||
sameCard->addToSet(printing.getSet(), printing);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
|
@ -113,14 +111,14 @@ void CardDatabase::removeCard(CardInfoPtr card)
|
|||
|
||||
CardInfoPtr CardDatabase::getCard(const QString &cardName) const
|
||||
{
|
||||
return getCardFromMap(cards, cardName);
|
||||
return cards.value(cardName);
|
||||
}
|
||||
|
||||
QList<CardInfoPtr> CardDatabase::getCards(const QStringList &cardNames) const
|
||||
{
|
||||
QList<CardInfoPtr> cardInfos;
|
||||
for (const QString &cardName : cardNames) {
|
||||
CardInfoPtr ptr = getCardFromMap(cards, cardName);
|
||||
CardInfoPtr ptr = cards.value(cardName);
|
||||
if (ptr)
|
||||
cardInfos.append(ptr);
|
||||
}
|
||||
|
|
@ -147,12 +145,12 @@ CardInfoPtr CardDatabase::getCardByNameAndProviderId(const QString &cardName, co
|
|||
return info;
|
||||
}
|
||||
|
||||
for (const auto &cardInfoPerSetList : info->getSets()) {
|
||||
for (const auto &set : cardInfoPerSetList) {
|
||||
if (set.getProperty("uuid") == providerId) {
|
||||
for (const auto &printings : info->getSets()) {
|
||||
for (const auto &printing : printings) {
|
||||
if (printing.getProperty("uuid") == providerId) {
|
||||
CardInfoPtr cardFromSpecificSet = info->clone();
|
||||
cardFromSpecificSet->setPixmapCacheKey(QLatin1String("card_") + QString(info->getName()) +
|
||||
QString("_") + QString(set.getProperty("uuid")));
|
||||
QString("_") + QString(printing.getProperty("uuid")));
|
||||
return cardFromSpecificSet;
|
||||
}
|
||||
}
|
||||
|
|
@ -162,7 +160,7 @@ CardInfoPtr CardDatabase::getCardByNameAndProviderId(const QString &cardName, co
|
|||
|
||||
CardInfoPtr CardDatabase::getCardBySimpleName(const QString &cardName) const
|
||||
{
|
||||
return getCardFromMap(simpleNameCards, CardInfo::simplifyName(cardName));
|
||||
return simpleNameCards.value(CardInfo::simplifyName(cardName));
|
||||
}
|
||||
|
||||
CardInfoPtr CardDatabase::guessCard(const QString &cardName, const QString &providerId) const
|
||||
|
|
@ -198,22 +196,12 @@ void CardDatabase::addSet(CardSetPtr set)
|
|||
SetList CardDatabase::getSetList() const
|
||||
{
|
||||
SetList result;
|
||||
QHashIterator<QString, CardSetPtr> i(sets);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
result << i.value();
|
||||
for (auto set : sets.values()) {
|
||||
result << set;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
CardInfoPtr CardDatabase::getCardFromMap(const CardNameMap &cardMap, const QString &cardName) const
|
||||
{
|
||||
if (cardMap.contains(cardName))
|
||||
return cardMap.value(cardName);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
LoadStatus CardDatabase::loadFromFile(const QString &fileName)
|
||||
{
|
||||
QFile file(fileName);
|
||||
|
|
@ -309,53 +297,58 @@ void CardDatabase::refreshPreferredPrintings()
|
|||
}
|
||||
}
|
||||
|
||||
CardInfoPerSet CardDatabase::getPreferredSetForCard(const QString &cardName) const
|
||||
PrintingInfo CardDatabase::getPreferredPrinting(const QString &cardName) const
|
||||
{
|
||||
CardInfoPtr cardInfo = getCard(cardName);
|
||||
return getPreferredPrinting(cardInfo);
|
||||
}
|
||||
|
||||
PrintingInfo CardDatabase::getPreferredPrinting(const CardInfoPtr &cardInfo) const
|
||||
{
|
||||
if (!cardInfo) {
|
||||
return CardInfoPerSet(nullptr);
|
||||
return PrintingInfo(nullptr);
|
||||
}
|
||||
|
||||
CardInfoPerSetMap setMap = cardInfo->getSets();
|
||||
SetToPrintingsMap setMap = cardInfo->getSets();
|
||||
if (setMap.empty()) {
|
||||
return CardInfoPerSet(nullptr);
|
||||
return PrintingInfo(nullptr);
|
||||
}
|
||||
|
||||
CardSetPtr preferredSet = nullptr;
|
||||
CardInfoPerSet preferredCard;
|
||||
PrintingInfo preferredPrinting;
|
||||
SetPriorityComparator comparator;
|
||||
|
||||
for (const auto &cardInfoPerSetList : setMap) {
|
||||
for (auto &cardInfoForSet : cardInfoPerSetList) {
|
||||
CardSetPtr currentSet = cardInfoForSet.getPtr();
|
||||
for (const auto &printings : setMap) {
|
||||
for (auto &printing : printings) {
|
||||
CardSetPtr currentSet = printing.getSet();
|
||||
if (!preferredSet || comparator(currentSet, preferredSet)) {
|
||||
preferredSet = currentSet;
|
||||
preferredCard = cardInfoForSet;
|
||||
preferredPrinting = printing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (preferredSet) {
|
||||
return preferredCard;
|
||||
return preferredPrinting;
|
||||
}
|
||||
|
||||
return CardInfoPerSet(nullptr);
|
||||
return PrintingInfo(nullptr);
|
||||
}
|
||||
|
||||
CardInfoPerSet CardDatabase::getSpecificSetForCard(const QString &cardName, const QString &providerId) const
|
||||
PrintingInfo CardDatabase::getSpecificPrinting(const QString &cardName, const QString &providerId) const
|
||||
{
|
||||
CardInfoPtr cardInfo = getCard(cardName);
|
||||
if (!cardInfo) {
|
||||
return CardInfoPerSet(nullptr);
|
||||
return PrintingInfo(nullptr);
|
||||
}
|
||||
|
||||
CardInfoPerSetMap setMap = cardInfo->getSets();
|
||||
SetToPrintingsMap setMap = cardInfo->getSets();
|
||||
if (setMap.empty()) {
|
||||
return CardInfoPerSet(nullptr);
|
||||
return PrintingInfo(nullptr);
|
||||
}
|
||||
|
||||
for (const auto &cardInfoPerSetList : setMap) {
|
||||
for (auto &cardInfoForSet : cardInfoPerSetList) {
|
||||
for (const auto &printings : setMap) {
|
||||
for (auto &cardInfoForSet : printings) {
|
||||
if (cardInfoForSet.getProperty("uuid") == providerId) {
|
||||
return cardInfoForSet;
|
||||
}
|
||||
|
|
@ -363,56 +356,57 @@ CardInfoPerSet CardDatabase::getSpecificSetForCard(const QString &cardName, cons
|
|||
}
|
||||
|
||||
if (providerId.isNull()) {
|
||||
return getPreferredSetForCard(cardName);
|
||||
return getPreferredPrinting(cardName);
|
||||
}
|
||||
|
||||
return CardInfoPerSet(nullptr);
|
||||
return PrintingInfo(nullptr);
|
||||
}
|
||||
|
||||
CardInfoPerSet CardDatabase::getSpecificSetForCard(const QString &cardName,
|
||||
const QString &setShortName,
|
||||
const QString &collectorNumber) const
|
||||
PrintingInfo CardDatabase::getSpecificPrinting(const QString &cardName,
|
||||
const QString &setShortName,
|
||||
const QString &collectorNumber) const
|
||||
{
|
||||
CardInfoPtr cardInfo = getCard(cardName);
|
||||
if (!cardInfo) {
|
||||
return CardInfoPerSet(nullptr);
|
||||
return PrintingInfo(nullptr);
|
||||
}
|
||||
|
||||
CardInfoPerSetMap setMap = cardInfo->getSets();
|
||||
SetToPrintingsMap setMap = cardInfo->getSets();
|
||||
if (setMap.empty()) {
|
||||
return CardInfoPerSet(nullptr);
|
||||
return PrintingInfo(nullptr);
|
||||
}
|
||||
|
||||
for (const auto &cardInfoPerSetList : setMap) {
|
||||
for (auto &cardInfoForSet : cardInfoPerSetList) {
|
||||
for (const auto &printings : setMap) {
|
||||
for (auto &cardInfoForSet : printings) {
|
||||
if (collectorNumber != nullptr) {
|
||||
if (cardInfoForSet.getPtr()->getShortName() == setShortName &&
|
||||
if (cardInfoForSet.getSet()->getShortName() == setShortName &&
|
||||
cardInfoForSet.getProperty("num") == collectorNumber) {
|
||||
return cardInfoForSet;
|
||||
}
|
||||
} else {
|
||||
if (cardInfoForSet.getPtr()->getShortName() == setShortName) {
|
||||
if (cardInfoForSet.getSet()->getShortName() == setShortName) {
|
||||
return cardInfoForSet;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return CardInfoPerSet(nullptr);
|
||||
return PrintingInfo(nullptr);
|
||||
}
|
||||
|
||||
QString CardDatabase::getPreferredPrintingProviderIdForCard(const QString &cardName)
|
||||
{
|
||||
CardInfoPerSet preferredSetCardInfo = getPreferredSetForCard(cardName);
|
||||
QString preferredPrintingProviderId = preferredSetCardInfo.getProperty(QString("uuid"));
|
||||
if (preferredPrintingProviderId.isEmpty()) {
|
||||
CardInfoPtr defaultCardInfo = getCard(cardName);
|
||||
if (defaultCardInfo.isNull()) {
|
||||
return cardName;
|
||||
}
|
||||
return defaultCardInfo->getName();
|
||||
PrintingInfo preferredPrinting = getPreferredPrinting(cardName);
|
||||
QString uuid = preferredPrinting.getProperty("uuid");
|
||||
if (!uuid.isEmpty()) {
|
||||
return uuid;
|
||||
}
|
||||
return preferredPrintingProviderId;
|
||||
|
||||
CardInfoPtr defaultCardInfo = getCard(cardName);
|
||||
if (defaultCardInfo.isNull()) {
|
||||
return cardName;
|
||||
}
|
||||
return defaultCardInfo->getName();
|
||||
}
|
||||
|
||||
bool CardDatabase::isProviderIdForPreferredPrinting(const QString &cardName, const QString &providerId)
|
||||
|
|
@ -424,15 +418,15 @@ bool CardDatabase::isProviderIdForPreferredPrinting(const QString &cardName, con
|
|||
return providerId == getPreferredPrintingProviderIdForCard(cardName);
|
||||
}
|
||||
|
||||
CardInfoPerSet CardDatabase::getSetInfoForCard(const CardInfoPtr &_card)
|
||||
PrintingInfo CardDatabase::getSetInfoForCard(const CardInfoPtr &_card)
|
||||
{
|
||||
const CardInfoPerSetMap &setMap = _card->getSets();
|
||||
const SetToPrintingsMap &setMap = _card->getSets();
|
||||
if (setMap.empty()) {
|
||||
return CardInfoPerSet(nullptr);
|
||||
return PrintingInfo(nullptr);
|
||||
}
|
||||
|
||||
for (const auto &cardInfoPerSetList : setMap) {
|
||||
for (const auto &cardInfoForSet : cardInfoPerSetList) {
|
||||
for (const auto &printings : setMap) {
|
||||
for (const auto &cardInfoForSet : printings) {
|
||||
if (QLatin1String("card_") + _card->getName() + QString("_") + cardInfoForSet.getProperty("uuid") ==
|
||||
_card->getPixmapCacheKey()) {
|
||||
return cardInfoForSet;
|
||||
|
|
@ -440,7 +434,7 @@ CardInfoPerSet CardDatabase::getSetInfoForCard(const CardInfoPtr &_card)
|
|||
}
|
||||
}
|
||||
|
||||
return CardInfoPerSet(nullptr);
|
||||
return PrintingInfo(nullptr);
|
||||
}
|
||||
|
||||
void CardDatabase::refreshCachedReverseRelatedCards()
|
||||
|
|
@ -470,9 +464,8 @@ void CardDatabase::refreshCachedReverseRelatedCards()
|
|||
QStringList CardDatabase::getAllMainCardTypes() const
|
||||
{
|
||||
QSet<QString> types;
|
||||
QHashIterator<QString, CardInfoPtr> cardIterator(cards);
|
||||
while (cardIterator.hasNext()) {
|
||||
types.insert(cardIterator.next().value()->getMainCardType());
|
||||
for (const auto &card : cards.values()) {
|
||||
types.insert(card->getMainCardType());
|
||||
}
|
||||
return types.values();
|
||||
}
|
||||
|
|
@ -480,10 +473,9 @@ QStringList CardDatabase::getAllMainCardTypes() const
|
|||
QMap<QString, int> CardDatabase::getAllMainCardTypesWithCount() const
|
||||
{
|
||||
QMap<QString, int> typeCounts;
|
||||
QHashIterator<QString, CardInfoPtr> cardIterator(cards);
|
||||
|
||||
while (cardIterator.hasNext()) {
|
||||
QString type = cardIterator.next().value()->getMainCardType();
|
||||
for (const auto &card : cards.values()) {
|
||||
QString type = card->getMainCardType();
|
||||
typeCounts[type]++;
|
||||
}
|
||||
|
||||
|
|
@ -493,10 +485,9 @@ QMap<QString, int> CardDatabase::getAllMainCardTypesWithCount() const
|
|||
QMap<QString, int> CardDatabase::getAllSubCardTypesWithCount() const
|
||||
{
|
||||
QMap<QString, int> typeCounts;
|
||||
QHashIterator<QString, CardInfoPtr> cardIterator(cards);
|
||||
|
||||
while (cardIterator.hasNext()) {
|
||||
QString type = cardIterator.next().value()->getCardType();
|
||||
for (const auto &card : cards.values()) {
|
||||
QString type = card->getCardType();
|
||||
|
||||
QStringList parts = type.split(" — ");
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ protected:
|
|||
QVector<ICardDatabaseParser *> availableParsers;
|
||||
|
||||
private:
|
||||
CardInfoPtr getCardFromMap(const CardNameMap &cardMap, const QString &cardName) const;
|
||||
void checkUnknownSets();
|
||||
void refreshCachedReverseRelatedCards();
|
||||
|
||||
|
|
@ -65,15 +64,20 @@ public:
|
|||
~CardDatabase() override;
|
||||
void clear();
|
||||
void removeCard(CardInfoPtr card);
|
||||
|
||||
[[nodiscard]] CardInfoPtr getCard(const QString &cardName) const;
|
||||
[[nodiscard]] QList<CardInfoPtr> getCards(const QStringList &cardNames) const;
|
||||
QList<CardInfoPtr> getCardsByNameAndProviderId(const QMap<QString, QString> &cardNames) const;
|
||||
[[nodiscard]] CardInfoPtr getCardByNameAndProviderId(const QString &cardName, const QString &providerId) const;
|
||||
[[nodiscard]] CardInfoPerSet getPreferredSetForCard(const QString &cardName) const;
|
||||
[[nodiscard]] CardInfoPerSet getSpecificSetForCard(const QString &cardName, const QString &providerId) const;
|
||||
CardInfoPerSet
|
||||
getSpecificSetForCard(const QString &cardName, const QString &setShortName, const QString &collectorNumber) const;
|
||||
|
||||
[[nodiscard]] PrintingInfo getPreferredPrinting(const QString &cardName) const;
|
||||
[[nodiscard]] PrintingInfo getPreferredPrinting(const CardInfoPtr &cardInfo) const;
|
||||
[[nodiscard]] PrintingInfo getSpecificPrinting(const QString &cardName, const QString &providerId) const;
|
||||
PrintingInfo
|
||||
getSpecificPrinting(const QString &cardName, const QString &setShortName, const QString &collectorNumber) const;
|
||||
QString getPreferredPrintingProviderIdForCard(const QString &cardName);
|
||||
bool isProviderIdForPreferredPrinting(const QString &cardName, const QString &providerId);
|
||||
|
||||
[[nodiscard]] CardInfoPtr guessCard(const QString &cardName, const QString &providerId = QString()) const;
|
||||
|
||||
/*
|
||||
|
|
@ -83,8 +87,7 @@ public:
|
|||
[[nodiscard]] CardInfoPtr getCardBySimpleName(const QString &cardName) const;
|
||||
|
||||
CardSetPtr getSet(const QString &setName);
|
||||
bool isProviderIdForPreferredPrinting(const QString &cardName, const QString &providerId);
|
||||
static CardInfoPerSet getSetInfoForCard(const CardInfoPtr &_card);
|
||||
static PrintingInfo getSetInfoForCard(const CardInfoPtr &_card);
|
||||
const CardNameMap &getCardList() const
|
||||
{
|
||||
return cards;
|
||||
|
|
|
|||
|
|
@ -98,9 +98,9 @@ bool CardDatabaseModel::checkCardHasAtLeastOneEnabledSet(CardInfoPtr card)
|
|||
if (!showOnlyCardsFromEnabledSets)
|
||||
return true;
|
||||
|
||||
for (const auto &cardInfoPerSetList : card->getSets()) {
|
||||
for (const auto &set : cardInfoPerSetList) {
|
||||
if (set.getPtr()->getEnabled())
|
||||
for (const auto &printings : card->getSets()) {
|
||||
for (const auto &printing : printings) {
|
||||
if (printing.getSet()->getEnabled())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ void CockatriceXml3Parser::loadCardsFromXml(QXmlStreamReader &xml)
|
|||
QVariantHash properties = QVariantHash();
|
||||
QString colors = QString("");
|
||||
QList<CardRelation *> relatedCards, reverseRelatedCards;
|
||||
auto _sets = CardInfoPerSetMap();
|
||||
auto _sets = SetToPrintingsMap();
|
||||
int tableRow = 0;
|
||||
bool cipt = false;
|
||||
bool landscapeOrientation = false;
|
||||
|
|
@ -209,7 +209,7 @@ void CockatriceXml3Parser::loadCardsFromXml(QXmlStreamReader &xml)
|
|||
// NOTE: attributes must be read before readElementText()
|
||||
QXmlStreamAttributes attrs = xml.attributes();
|
||||
QString setName = xml.readElementText(QXmlStreamReader::IncludeChildElements);
|
||||
CardInfoPerSet setInfo(internalAddSet(setName));
|
||||
PrintingInfo setInfo(internalAddSet(setName));
|
||||
if (attrs.hasAttribute("muId")) {
|
||||
setInfo.setProperty("muid", attrs.value("muId").toString());
|
||||
}
|
||||
|
|
@ -343,9 +343,9 @@ static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfoPtr &in
|
|||
}
|
||||
|
||||
// sets
|
||||
const CardInfoPerSetMap sets = info->getSets();
|
||||
for (const auto &cardInfoPerSetList : sets) {
|
||||
for (const CardInfoPerSet &set : cardInfoPerSetList) {
|
||||
const SetToPrintingsMap setMap = info->getSets();
|
||||
for (const auto &printings : setMap) {
|
||||
for (const PrintingInfo &set : printings) {
|
||||
xml.writeStartElement("set");
|
||||
xml.writeAttribute("rarity", set.getProperty("rarity"));
|
||||
xml.writeAttribute("muId", set.getProperty("muid"));
|
||||
|
|
@ -361,7 +361,7 @@ static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfoPtr &in
|
|||
xml.writeAttribute("picURL", tmpString);
|
||||
}
|
||||
|
||||
xml.writeCharacters(set.getPtr()->getShortName());
|
||||
xml.writeCharacters(set.getSet()->getShortName());
|
||||
xml.writeEndElement();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ void CockatriceXml4Parser::loadCardsFromXml(QXmlStreamReader &xml)
|
|||
QString text = QString("");
|
||||
QVariantHash properties = QVariantHash();
|
||||
QList<CardRelation *> relatedCards, reverseRelatedCards;
|
||||
auto _sets = CardInfoPerSetMap();
|
||||
auto _sets = SetToPrintingsMap();
|
||||
int tableRow = 0;
|
||||
bool cipt = false;
|
||||
bool landscapeOrientation = false;
|
||||
|
|
@ -184,12 +184,12 @@ void CockatriceXml4Parser::loadCardsFromXml(QXmlStreamReader &xml)
|
|||
QString setName = xml.readElementText(QXmlStreamReader::IncludeChildElements);
|
||||
auto set = internalAddSet(setName);
|
||||
if (set->getEnabled()) {
|
||||
CardInfoPerSet setInfo(set);
|
||||
PrintingInfo printingInfo(set);
|
||||
for (QXmlStreamAttribute attr : attrs) {
|
||||
QString attrName = attr.name().toString();
|
||||
if (attrName == "picURL")
|
||||
attrName = "picurl";
|
||||
setInfo.setProperty(attrName, attr.value().toString());
|
||||
printingInfo.setProperty(attrName, attr.value().toString());
|
||||
}
|
||||
|
||||
// This is very much a hack and not the right place to
|
||||
|
|
@ -199,8 +199,8 @@ void CockatriceXml4Parser::loadCardsFromXml(QXmlStreamReader &xml)
|
|||
// However, this is also true of the `set->getEnabled()`
|
||||
// check above (which is currently bugged as well), so
|
||||
// we'll fix both at the same time.
|
||||
if (includeRebalancedCards || setInfo.getProperty("isRebalanced") != "true") {
|
||||
_sets[setName].append(setInfo);
|
||||
if (includeRebalancedCards || printingInfo.getProperty("isRebalanced") != "true") {
|
||||
_sets[setName].append(printingInfo);
|
||||
}
|
||||
}
|
||||
// related cards
|
||||
|
|
@ -309,14 +309,14 @@ static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfoPtr &in
|
|||
xml.writeEndElement();
|
||||
|
||||
// sets
|
||||
for (const auto &cardInfoPerSetList : info->getSets()) {
|
||||
for (const CardInfoPerSet &set : cardInfoPerSetList) {
|
||||
for (const auto &printings : info->getSets()) {
|
||||
for (const PrintingInfo &set : printings) {
|
||||
xml.writeStartElement("set");
|
||||
for (const QString &propName : set.getProperties()) {
|
||||
xml.writeAttribute(propName, set.getProperty(propName));
|
||||
}
|
||||
|
||||
xml.writeCharacters(set.getPtr()->getShortName());
|
||||
xml.writeCharacters(set.getSet()->getShortName());
|
||||
xml.writeEndElement();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -215,7 +215,7 @@ void SetList::defaultSort()
|
|||
});
|
||||
}
|
||||
|
||||
CardInfoPerSet::CardInfoPerSet(const CardSetPtr &_set) : set(_set)
|
||||
PrintingInfo::PrintingInfo(const CardSetPtr &_set) : set(_set)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -225,13 +225,13 @@ CardInfo::CardInfo(const QString &_name,
|
|||
QVariantHash _properties,
|
||||
const QList<CardRelation *> &_relatedCards,
|
||||
const QList<CardRelation *> &_reverseRelatedCards,
|
||||
CardInfoPerSetMap _sets,
|
||||
SetToPrintingsMap _sets,
|
||||
bool _cipt,
|
||||
bool _landscapeOrientation,
|
||||
int _tableRow,
|
||||
bool _upsideDownArt)
|
||||
: name(_name), text(_text), isToken(_isToken), properties(std::move(_properties)), relatedCards(_relatedCards),
|
||||
reverseRelatedCards(_reverseRelatedCards), sets(std::move(_sets)), cipt(_cipt),
|
||||
reverseRelatedCards(_reverseRelatedCards), setsToPrintings(std::move(_sets)), cipt(_cipt),
|
||||
landscapeOrientation(_landscapeOrientation), tableRow(_tableRow), upsideDownArt(_upsideDownArt)
|
||||
{
|
||||
pixmapCacheKey = QLatin1String("card_") + name;
|
||||
|
|
@ -248,7 +248,7 @@ CardInfo::~CardInfo()
|
|||
CardInfoPtr CardInfo::newInstance(const QString &_name)
|
||||
{
|
||||
return newInstance(_name, QString(), false, QVariantHash(), QList<CardRelation *>(), QList<CardRelation *>(),
|
||||
CardInfoPerSetMap(), false, false, 0, false);
|
||||
SetToPrintingsMap(), false, false, 0, false);
|
||||
}
|
||||
|
||||
CardInfoPtr CardInfo::newInstance(const QString &_name,
|
||||
|
|
@ -257,7 +257,7 @@ CardInfoPtr CardInfo::newInstance(const QString &_name,
|
|||
QVariantHash _properties,
|
||||
const QList<CardRelation *> &_relatedCards,
|
||||
const QList<CardRelation *> &_reverseRelatedCards,
|
||||
CardInfoPerSetMap _sets,
|
||||
SetToPrintingsMap _sets,
|
||||
bool _cipt,
|
||||
bool _landscapeOrientation,
|
||||
int _tableRow,
|
||||
|
|
@ -267,9 +267,9 @@ CardInfoPtr CardInfo::newInstance(const QString &_name,
|
|||
_sets, _cipt, _landscapeOrientation, _tableRow, _upsideDownArt));
|
||||
ptr->setSmartPointer(ptr);
|
||||
|
||||
for (const auto &cardInfoPerSetList : _sets) {
|
||||
for (const CardInfoPerSet &set : cardInfoPerSetList) {
|
||||
set.getPtr()->append(ptr);
|
||||
for (const auto &printings : _sets) {
|
||||
for (const PrintingInfo &printing : printings) {
|
||||
printing.getSet()->append(ptr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -289,13 +289,13 @@ QString CardInfo::getCorrectedName() const
|
|||
return result.remove(rmrx).replace(spacerx, space);
|
||||
}
|
||||
|
||||
void CardInfo::addToSet(const CardSetPtr &_set, const CardInfoPerSet _info)
|
||||
void CardInfo::addToSet(const CardSetPtr &_set, const PrintingInfo _info)
|
||||
{
|
||||
if (!_set->contains(smartThis)) {
|
||||
_set->append(smartThis);
|
||||
}
|
||||
if (!sets[_set->getShortName()].contains(_info)) {
|
||||
sets[_set->getShortName()].append(_info);
|
||||
if (!setsToPrintings[_set->getShortName()].contains(_info)) {
|
||||
setsToPrintings[_set->getShortName()].append(_info);
|
||||
}
|
||||
|
||||
refreshCachedSetNames();
|
||||
|
|
@ -316,10 +316,10 @@ void CardInfo::refreshCachedSetNames()
|
|||
{
|
||||
QStringList setList;
|
||||
// update the cached list of set names
|
||||
for (const auto &cardInfoPerSetList : sets) {
|
||||
for (const auto &set : cardInfoPerSetList) {
|
||||
if (set.getPtr()->getEnabled()) {
|
||||
setList << set.getPtr()->getShortName();
|
||||
for (const auto &printings : setsToPrintings) {
|
||||
for (const auto &printing : printings) {
|
||||
if (printing.getSet()->getEnabled()) {
|
||||
setList << printing.getSet()->getShortName();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,15 +15,14 @@
|
|||
inline Q_LOGGING_CATEGORY(CardInfoLog, "card_info");
|
||||
|
||||
class CardInfo;
|
||||
class CardInfoPerSet;
|
||||
class PrintingInfo;
|
||||
class CardSet;
|
||||
class CardRelation;
|
||||
class ICardDatabaseParser;
|
||||
|
||||
typedef QMap<QString, QString> QStringMap;
|
||||
typedef QSharedPointer<CardInfo> CardInfoPtr;
|
||||
typedef QSharedPointer<CardSet> CardSetPtr;
|
||||
typedef QMap<QString, QList<CardInfoPerSet>> CardInfoPerSetMap;
|
||||
typedef QMap<QString, QList<PrintingInfo>> SetToPrintingsMap;
|
||||
|
||||
typedef QHash<QString, CardInfoPtr> CardNameMap;
|
||||
typedef QHash<QString, CardSetPtr> SetNameMap;
|
||||
|
|
@ -143,32 +142,35 @@ public:
|
|||
void defaultSort();
|
||||
};
|
||||
|
||||
class CardInfoPerSet
|
||||
/**
|
||||
* Info relating to a specific printing for a card.
|
||||
*/
|
||||
class PrintingInfo
|
||||
{
|
||||
public:
|
||||
explicit CardInfoPerSet(const CardSetPtr &_set = QSharedPointer<CardSet>(nullptr));
|
||||
~CardInfoPerSet() = default;
|
||||
explicit PrintingInfo(const CardSetPtr &_set = QSharedPointer<CardSet>(nullptr));
|
||||
~PrintingInfo() = default;
|
||||
|
||||
bool operator==(const CardInfoPerSet &other) const
|
||||
bool operator==(const PrintingInfo &other) const
|
||||
{
|
||||
return this->set == other.set && this->properties == other.properties;
|
||||
}
|
||||
|
||||
private:
|
||||
CardSetPtr set;
|
||||
// per-set card properties;
|
||||
// per-printing card properties;
|
||||
QVariantHash properties;
|
||||
|
||||
public:
|
||||
const CardSetPtr getPtr() const
|
||||
CardSetPtr getSet() const
|
||||
{
|
||||
return set;
|
||||
}
|
||||
const QStringList getProperties() const
|
||||
QStringList getProperties() const
|
||||
{
|
||||
return properties.keys();
|
||||
}
|
||||
const QString getProperty(const QString &propertyName) const
|
||||
QString getProperty(const QString &propertyName) const
|
||||
{
|
||||
return properties.value(propertyName).toString();
|
||||
}
|
||||
|
|
@ -202,7 +204,7 @@ private:
|
|||
// the cards thare are reverse-related to me
|
||||
QList<CardRelation *> reverseRelatedCardsToMe;
|
||||
// card sets
|
||||
CardInfoPerSetMap sets;
|
||||
SetToPrintingsMap setsToPrintings;
|
||||
// cached set names
|
||||
QString setsNames;
|
||||
// positioning properties; used by UI
|
||||
|
|
@ -218,7 +220,7 @@ public:
|
|||
QVariantHash _properties,
|
||||
const QList<CardRelation *> &_relatedCards,
|
||||
const QList<CardRelation *> &_reverseRelatedCards,
|
||||
CardInfoPerSetMap _sets,
|
||||
SetToPrintingsMap _sets,
|
||||
bool _cipt,
|
||||
bool _landscapeOrientation,
|
||||
int _tableRow,
|
||||
|
|
@ -227,7 +229,7 @@ public:
|
|||
: QObject(other.parent()), name(other.name), simpleName(other.simpleName), pixmapCacheKey(other.pixmapCacheKey),
|
||||
text(other.text), isToken(other.isToken), properties(other.properties), relatedCards(other.relatedCards),
|
||||
reverseRelatedCards(other.reverseRelatedCards), reverseRelatedCardsToMe(other.reverseRelatedCardsToMe),
|
||||
sets(other.sets), setsNames(other.setsNames), cipt(other.cipt),
|
||||
setsToPrintings(other.setsToPrintings), setsNames(other.setsNames), cipt(other.cipt),
|
||||
landscapeOrientation(other.landscapeOrientation), tableRow(other.tableRow), upsideDownArt(other.upsideDownArt)
|
||||
{
|
||||
}
|
||||
|
|
@ -241,7 +243,7 @@ public:
|
|||
QVariantHash _properties,
|
||||
const QList<CardRelation *> &_relatedCards,
|
||||
const QList<CardRelation *> &_reverseRelatedCards,
|
||||
CardInfoPerSetMap _sets,
|
||||
SetToPrintingsMap _sets,
|
||||
bool _cipt,
|
||||
bool _landscapeOrientation,
|
||||
int _tableRow,
|
||||
|
|
@ -292,11 +294,11 @@ public:
|
|||
{
|
||||
return isToken;
|
||||
}
|
||||
const QStringList getProperties() const
|
||||
QStringList getProperties() const
|
||||
{
|
||||
return properties.keys();
|
||||
}
|
||||
const QString getProperty(const QString &propertyName) const
|
||||
QString getProperty(const QString &propertyName) const
|
||||
{
|
||||
return properties.value(propertyName).toString();
|
||||
}
|
||||
|
|
@ -309,27 +311,27 @@ public:
|
|||
{
|
||||
return properties.contains(propertyName);
|
||||
}
|
||||
const CardInfoPerSetMap &getSets() const
|
||||
const SetToPrintingsMap &getSets() const
|
||||
{
|
||||
return sets;
|
||||
return setsToPrintings;
|
||||
}
|
||||
const QString &getSetsNames() const
|
||||
{
|
||||
return setsNames;
|
||||
}
|
||||
const QString getSetProperty(const QString &setName, const QString &propertyName) const
|
||||
QString getSetProperty(const QString &setName, const QString &propertyName) const
|
||||
{
|
||||
if (!sets.contains(setName))
|
||||
if (!setsToPrintings.contains(setName))
|
||||
return "";
|
||||
|
||||
for (const auto &set : sets[setName]) {
|
||||
for (const auto &set : setsToPrintings[setName]) {
|
||||
if (QLatin1String("card_") + this->getName() + QString("_") + QString(set.getProperty("uuid")) ==
|
||||
this->getPixmapCacheKey()) {
|
||||
return set.getProperty(propertyName);
|
||||
}
|
||||
}
|
||||
|
||||
return sets[setName][0].getProperty(propertyName);
|
||||
return setsToPrintings[setName][0].getProperty(propertyName);
|
||||
}
|
||||
|
||||
// related cards
|
||||
|
|
@ -345,7 +347,7 @@ public:
|
|||
{
|
||||
return reverseRelatedCardsToMe;
|
||||
}
|
||||
const QList<CardRelation *> getAllRelatedCards() const
|
||||
QList<CardRelation *> getAllRelatedCards() const
|
||||
{
|
||||
QList<CardRelation *> result;
|
||||
result.append(getRelatedCards());
|
||||
|
|
@ -399,7 +401,7 @@ public:
|
|||
return getSetProperty(set, "picurl");
|
||||
}
|
||||
QString getCorrectedName() const;
|
||||
void addToSet(const CardSetPtr &_set, CardInfoPerSet _info = CardInfoPerSet());
|
||||
void addToSet(const CardSetPtr &_set, PrintingInfo _info = PrintingInfo());
|
||||
void combineLegalities(const QVariantHash &props);
|
||||
void emitPixmapUpdated()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "../../deck/deck_loader.h"
|
||||
#include "../../dialogs/dlg_load_deck.h"
|
||||
#include "../../dialogs/dlg_load_deck_from_clipboard.h"
|
||||
#include "../../dialogs/dlg_load_deck_from_website.h"
|
||||
#include "../../dialogs/dlg_load_remote_deck.h"
|
||||
#include "../../server/pending_command.h"
|
||||
#include "../../settings/cache_settings.h"
|
||||
|
|
@ -54,6 +55,7 @@ DeckViewContainer::DeckViewContainer(int _playerId, TabGame *parent)
|
|||
loadLocalButton = new QPushButton;
|
||||
loadRemoteButton = new QPushButton;
|
||||
loadFromClipboardButton = new QPushButton;
|
||||
loadFromWebsiteButton = new QPushButton;
|
||||
unloadDeckButton = new QPushButton;
|
||||
readyStartButton = new ToggleButton;
|
||||
forceStartGameButton = new QPushButton;
|
||||
|
|
@ -62,6 +64,7 @@ DeckViewContainer::DeckViewContainer(int _playerId, TabGame *parent)
|
|||
connect(loadLocalButton, &QPushButton::clicked, this, &DeckViewContainer::loadLocalDeck);
|
||||
connect(loadRemoteButton, &QPushButton::clicked, this, &DeckViewContainer::loadRemoteDeck);
|
||||
connect(loadFromClipboardButton, &QPushButton::clicked, this, &DeckViewContainer::loadFromClipboard);
|
||||
connect(loadFromWebsiteButton, &QPushButton::clicked, this, &DeckViewContainer::loadFromWebsite);
|
||||
connect(readyStartButton, &QPushButton::clicked, this, &DeckViewContainer::readyStart);
|
||||
connect(unloadDeckButton, &QPushButton::clicked, this, &DeckViewContainer::unloadDeck);
|
||||
connect(forceStartGameButton, &QPushButton::clicked, this, &DeckViewContainer::forceStart);
|
||||
|
|
@ -72,6 +75,7 @@ DeckViewContainer::DeckViewContainer(int _playerId, TabGame *parent)
|
|||
buttonHBox->addWidget(loadLocalButton);
|
||||
buttonHBox->addWidget(loadRemoteButton);
|
||||
buttonHBox->addWidget(loadFromClipboardButton);
|
||||
buttonHBox->addWidget(loadFromWebsiteButton);
|
||||
buttonHBox->addWidget(unloadDeckButton);
|
||||
buttonHBox->addWidget(readyStartButton);
|
||||
buttonHBox->addWidget(sideboardLockButton);
|
||||
|
|
@ -123,6 +127,7 @@ void DeckViewContainer::retranslateUi()
|
|||
loadLocalButton->setText(tr("Load deck..."));
|
||||
loadRemoteButton->setText(tr("Load remote deck..."));
|
||||
loadFromClipboardButton->setText(tr("Load from clipboard..."));
|
||||
loadFromWebsiteButton->setText(tr("Load from website..."));
|
||||
unloadDeckButton->setText(tr("Unload deck"));
|
||||
readyStartButton->setText(tr("Ready to start"));
|
||||
forceStartGameButton->setText(tr("Force start"));
|
||||
|
|
@ -154,6 +159,7 @@ void DeckViewContainer::switchToDeckSelectView()
|
|||
setVisibility(loadLocalButton, true);
|
||||
setVisibility(loadRemoteButton, !parentGame->getIsLocalGame());
|
||||
setVisibility(loadFromClipboardButton, true);
|
||||
setVisibility(loadFromWebsiteButton, true);
|
||||
setVisibility(unloadDeckButton, false);
|
||||
setVisibility(readyStartButton, false);
|
||||
setVisibility(sideboardLockButton, false);
|
||||
|
|
@ -179,6 +185,7 @@ void DeckViewContainer::switchToDeckLoadedView()
|
|||
setVisibility(loadLocalButton, false);
|
||||
setVisibility(loadRemoteButton, false);
|
||||
setVisibility(loadFromClipboardButton, false);
|
||||
setVisibility(loadFromWebsiteButton, false);
|
||||
setVisibility(unloadDeckButton, true);
|
||||
setVisibility(readyStartButton, true);
|
||||
setVisibility(sideboardLockButton, true);
|
||||
|
|
@ -309,6 +316,18 @@ void DeckViewContainer::loadFromClipboard()
|
|||
loadDeckFromDeckLoader(deck);
|
||||
}
|
||||
|
||||
void DeckViewContainer::loadFromWebsite()
|
||||
{
|
||||
auto dlg = DlgLoadDeckFromWebsite(this);
|
||||
|
||||
if (!dlg.exec()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DeckLoader *deck = dlg.getDeck();
|
||||
loadDeckFromDeckLoader(deck);
|
||||
}
|
||||
|
||||
void DeckViewContainer::deckSelectFinished(const Response &r)
|
||||
{
|
||||
const Response_DeckDownload &resp = r.GetExtension(Response_DeckDownload::ext);
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class DeckViewContainer : public QWidget
|
|||
Q_OBJECT
|
||||
private:
|
||||
QVBoxLayout *deckViewLayout;
|
||||
QPushButton *loadLocalButton, *loadRemoteButton, *loadFromClipboardButton;
|
||||
QPushButton *loadLocalButton, *loadRemoteButton, *loadFromClipboardButton, *loadFromWebsiteButton;
|
||||
QPushButton *unloadDeckButton, *forceStartGameButton;
|
||||
ToggleButton *readyStartButton, *sideboardLockButton;
|
||||
DeckView *deckView;
|
||||
|
|
@ -60,6 +60,7 @@ private slots:
|
|||
void loadLocalDeck();
|
||||
void loadRemoteDeck();
|
||||
void loadFromClipboard();
|
||||
void loadFromWebsite();
|
||||
void unloadDeck();
|
||||
void readyStart();
|
||||
void forceStart();
|
||||
|
|
|
|||
|
|
@ -129,14 +129,14 @@ static void setupParserRules()
|
|||
search["RarityQuery"] = [](const peg::SemanticValues &sv) -> Filter {
|
||||
const auto rarity = std::any_cast<QString>(sv[0]);
|
||||
return [=](const CardData &x) -> bool {
|
||||
QList<CardInfoPerSet> infos;
|
||||
for (const auto &setsValue : x->getSets().values()) {
|
||||
for (const auto &cardInfoPerSet : setsValue) {
|
||||
infos.append(cardInfoPerSet);
|
||||
QList<PrintingInfo> infos;
|
||||
for (const auto &printings : x->getSets()) {
|
||||
for (const auto &printing : printings) {
|
||||
infos.append(printing);
|
||||
}
|
||||
}
|
||||
|
||||
auto matchesRarity = [&rarity](const CardInfoPerSet &info) { return rarity == info.getProperty("rarity"); };
|
||||
auto matchesRarity = [&rarity](const PrintingInfo &info) { return rarity == info.getProperty("rarity"); };
|
||||
return std::any_of(infos.begin(), infos.end(), matchesRarity);
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -215,10 +215,10 @@ bool FilterItem::acceptText(const CardInfoPtr info) const
|
|||
bool FilterItem::acceptSet(const CardInfoPtr info) const
|
||||
{
|
||||
bool status = false;
|
||||
for (const auto &cardInfoPerSetList : info->getSets()) {
|
||||
for (const auto &set : cardInfoPerSetList) {
|
||||
if (set.getPtr()->getShortName().compare(term, Qt::CaseInsensitive) == 0 ||
|
||||
set.getPtr()->getLongName().compare(term, Qt::CaseInsensitive) == 0) {
|
||||
for (const auto &printings : info->getSets()) {
|
||||
for (const auto &set : printings) {
|
||||
if (set.getSet()->getShortName().compare(term, Qt::CaseInsensitive) == 0 ||
|
||||
set.getSet()->getLongName().compare(term, Qt::CaseInsensitive) == 0) {
|
||||
status = true;
|
||||
break;
|
||||
}
|
||||
|
|
@ -350,9 +350,9 @@ bool FilterItem::acceptRarity(const CardInfoPtr info) const
|
|||
}
|
||||
}
|
||||
|
||||
for (const auto &cardInfoPerSetList : info->getSets()) {
|
||||
for (const auto &set : cardInfoPerSetList) {
|
||||
if (set.getProperty("rarity").compare(converted_term, Qt::CaseInsensitive) == 0) {
|
||||
for (const auto &printings : info->getSets()) {
|
||||
for (const auto &printing : printings) {
|
||||
if (printing.getProperty("rarity").compare(converted_term, Qt::CaseInsensitive) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,12 +47,12 @@ public:
|
|||
* Enabled sets have priority over disabled sets
|
||||
* Both groups follow the user-defined order
|
||||
*/
|
||||
inline bool operator()(const CardInfoPerSet &a, const CardInfoPerSet &b) const
|
||||
inline bool operator()(const PrintingInfo &a, const PrintingInfo &b) const
|
||||
{
|
||||
if (a.getPtr()->getEnabled()) {
|
||||
return !b.getPtr()->getEnabled() || a.getPtr()->getSortKey() < b.getPtr()->getSortKey();
|
||||
if (a.getSet()->getEnabled()) {
|
||||
return !b.getSet()->getEnabled() || a.getSet()->getSortKey() < b.getSet()->getSortKey();
|
||||
} else {
|
||||
return !b.getPtr()->getEnabled() && a.getPtr()->getSortKey() < b.getPtr()->getSortKey();
|
||||
return !b.getSet()->getEnabled() && a.getSet()->getSortKey() < b.getSet()->getSortKey();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue