mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 08:34:52 -07:00
[TabArchidekt] Place sideboard categories into the sideboard.
Took 35 minutes Took 3 seconds
This commit is contained in:
parent
58a8c7d3df
commit
2bcebd83ca
3 changed files with 89 additions and 11 deletions
|
|
@ -4,10 +4,29 @@ void ArchidektApiResponseCardEntry::fromJson(const QJsonObject &json)
|
||||||
{
|
{
|
||||||
id = json.value("id").toInt();
|
id = json.value("id").toInt();
|
||||||
|
|
||||||
|
categories.clear();
|
||||||
|
|
||||||
auto categoriesJson = json.value("categories").toArray();
|
auto categoriesJson = json.value("categories").toArray();
|
||||||
|
|
||||||
for (auto category : categoriesJson) {
|
for (const auto &categoryValue : categoriesJson) {
|
||||||
categories.append(category.toString());
|
Category cat;
|
||||||
|
|
||||||
|
if (categoryValue.isObject()) {
|
||||||
|
QJsonObject obj = categoryValue.toObject();
|
||||||
|
|
||||||
|
cat.id = obj.value("id").toInt();
|
||||||
|
cat.name = obj.value("name").toString();
|
||||||
|
cat.isPremier = obj.value("isPremier").toBool();
|
||||||
|
cat.includedInDeck = obj.value("includedInDeck").toBool();
|
||||||
|
cat.includedInPrice = obj.value("includedInPrice").toBool();
|
||||||
|
} else if (categoryValue.isString()) {
|
||||||
|
cat.name = categoryValue.toString();
|
||||||
|
|
||||||
|
// assume mainboard unless known otherwise
|
||||||
|
cat.includedInDeck = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
categories.append(cat);
|
||||||
}
|
}
|
||||||
|
|
||||||
companion = json.value("companion").toBool();
|
companion = json.value("companion").toBool();
|
||||||
|
|
@ -27,7 +46,13 @@ void ArchidektApiResponseCardEntry::fromJson(const QJsonObject &json)
|
||||||
void ArchidektApiResponseCardEntry::debugPrint() const
|
void ArchidektApiResponseCardEntry::debugPrint() const
|
||||||
{
|
{
|
||||||
qDebug() << "Id:" << id;
|
qDebug() << "Id:" << id;
|
||||||
qDebug() << "Categories:" << categories;
|
for (auto category : categories) {
|
||||||
|
qDebug() << "Category ID:" << category.id;
|
||||||
|
qDebug() << "Category Name:" << category.name;
|
||||||
|
qDebug() << "Category Premier:" << category.isPremier;
|
||||||
|
qDebug() << "Category Included in Deck:" << category.includedInDeck;
|
||||||
|
qDebug() << "Category Included in Price:" << category.includedInPrice;
|
||||||
|
}
|
||||||
qDebug() << "Companion:" << companion;
|
qDebug() << "Companion:" << companion;
|
||||||
qDebug() << "FlippedDefault:" << flippedDefault;
|
qDebug() << "FlippedDefault:" << flippedDefault;
|
||||||
qDebug() << "Label:" << label;
|
qDebug() << "Label:" << label;
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,15 @@
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
|
struct Category
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
QString name;
|
||||||
|
bool isPremier;
|
||||||
|
bool includedInDeck;
|
||||||
|
bool includedInPrice;
|
||||||
|
};
|
||||||
|
|
||||||
class ArchidektApiResponseCardEntry
|
class ArchidektApiResponseCardEntry
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -26,7 +35,7 @@ public:
|
||||||
return card;
|
return card;
|
||||||
};
|
};
|
||||||
|
|
||||||
QStringList getCategories() const
|
QList<Category> getCategories() const
|
||||||
{
|
{
|
||||||
return categories;
|
return categories;
|
||||||
}
|
}
|
||||||
|
|
@ -38,7 +47,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int id;
|
int id;
|
||||||
QStringList categories;
|
QList<Category> categories;
|
||||||
bool companion;
|
bool companion;
|
||||||
bool flippedDefault;
|
bool flippedDefault;
|
||||||
QString label;
|
QString label;
|
||||||
|
|
|
||||||
|
|
@ -63,16 +63,60 @@ ArchidektApiResponseDeckDisplayWidget::ArchidektApiResponseDeckDisplayWidget(QWi
|
||||||
QString tempDeck;
|
QString tempDeck;
|
||||||
QTextStream deckStream(&tempDeck);
|
QTextStream deckStream(&tempDeck);
|
||||||
|
|
||||||
for (auto card : response.getCards()) {
|
QString mainboardText;
|
||||||
|
QString sideboardText;
|
||||||
|
|
||||||
|
QTextStream mainStream(&mainboardText);
|
||||||
|
QTextStream sideStream(&sideboardText);
|
||||||
|
|
||||||
|
for (const auto &card : response.getCards()) {
|
||||||
QString fullName = card.getCard().getOracleCard().value("name").toString();
|
QString fullName = card.getCard().getOracleCard().value("name").toString();
|
||||||
// We don't really care about the second card, the card database already has it as a relation
|
// We don't really care about the second card, the card database already has it as a relation
|
||||||
QString cleanName = fullName.split("//").first().trimmed();
|
QString cleanName = fullName.split("//").first().trimmed();
|
||||||
|
|
||||||
tempDeck += QString("%1 %2 (%3) %4\n")
|
QString line = QString("%1 %2 (%3) %4\n")
|
||||||
.arg(card.getQuantity())
|
.arg(card.getQuantity())
|
||||||
.arg(cleanName)
|
.arg(cleanName)
|
||||||
.arg(card.getCard().getEdition().getEditionCode().toUpper())
|
.arg(card.getCard().getEdition().getEditionCode().toUpper())
|
||||||
.arg(card.getCard().getCollectorNumber());
|
.arg(card.getCard().getCollectorNumber());
|
||||||
|
|
||||||
|
bool isCommander = false;
|
||||||
|
bool isSideboardCategory = false;
|
||||||
|
bool includedInDeck = false;
|
||||||
|
|
||||||
|
for (const auto &cat : card.getCategories()) {
|
||||||
|
|
||||||
|
if (cat.name.compare("Commander", Qt::CaseInsensitive) == 0) {
|
||||||
|
isCommander = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cat.name.compare("Sideboard", Qt::CaseInsensitive) == 0 ||
|
||||||
|
cat.name.compare("Maybeboard", Qt::CaseInsensitive) == 0) {
|
||||||
|
isSideboardCategory = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cat.includedInDeck) {
|
||||||
|
includedInDeck = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString target;
|
||||||
|
|
||||||
|
if (isCommander || isSideboardCategory) {
|
||||||
|
sideStream << line;
|
||||||
|
} else if (includedInDeck) {
|
||||||
|
mainStream << line;
|
||||||
|
} else {
|
||||||
|
sideStream << line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Combine with blank line separator
|
||||||
|
tempDeck = mainboardText;
|
||||||
|
|
||||||
|
if (!sideboardText.isEmpty()) {
|
||||||
|
tempDeck += "\n";
|
||||||
|
tempDeck += sideboardText;
|
||||||
}
|
}
|
||||||
|
|
||||||
model = new DeckListModel(this);
|
model = new DeckListModel(this);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue