From 518bda8c0915d39183ad0a458fb8a1b807d3fd47 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Sat, 13 Jun 2015 16:10:06 +0200 Subject: [PATCH] Rotate 180 degrees the art of flipped cards --- cockatrice/src/carddatabase.cpp | 17 +++++++++++++++-- cockatrice/src/carddatabase.h | 3 +++ oracle/src/oracleimporter.cpp | 19 +++++++++++++++---- oracle/src/oracleimporter.h | 2 +- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/cockatrice/src/carddatabase.cpp b/cockatrice/src/carddatabase.cpp index 072d397c..8f31be7c 100644 --- a/cockatrice/src/carddatabase.cpp +++ b/cockatrice/src/carddatabase.cpp @@ -483,6 +483,7 @@ CardInfo::CardInfo(CardDatabase *_db, const QString &_text, const QStringList &_colors, const QStringList &_relatedCards, + bool _upsideDownArt, int _loyalty, bool _cipt, int _tableRow, @@ -502,6 +503,7 @@ CardInfo::CardInfo(CardDatabase *_db, text(_text), colors(_colors), relatedCards(_relatedCards), + upsideDownArt(_upsideDownArt), loyalty(_loyalty), customPicURLs(_customPicURLs), customPicURLsHq(_customPicURLsHq), @@ -583,7 +585,13 @@ void CardInfo::loadPixmap(QPixmap &pixmap) void CardInfo::imageLoaded(const QImage &image) { if (!image.isNull()) { - QPixmapCache::insert(pixmapCacheKey, QPixmap::fromImage(image)); + if(upsideDownArt) + { + QImage mirrorImage = image.mirrored(true, true); + QPixmapCache::insert(pixmapCacheKey, QPixmap::fromImage(mirrorImage)); + } else { + QPixmapCache::insert(pixmapCacheKey, QPixmap::fromImage(image)); + } emit pixmapUpdated(); } } @@ -705,6 +713,8 @@ static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfo *info) xml.writeTextElement("cipt", "1"); if (info->getIsToken()) xml.writeTextElement("token", "1"); + if (info->getUpsideDownArt()) + xml.writeTextElement("upsidedown", "1"); xml.writeEndElement(); // card return xml; @@ -867,6 +877,7 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml, bool tokens) int loyalty = 0; bool cipt = false; bool isToken = false; + bool upsideDown = false; while (!xml.atEnd()) { if (xml.readNext() == QXmlStreamReader::EndElement) break; @@ -903,6 +914,8 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml, bool tokens) tableRow = xml.readElementText().toInt(); else if (xml.name() == "cipt") cipt = (xml.readElementText() == "1"); + else if (xml.name() == "upsidedown") + upsideDown = (xml.readElementText() == "1"); else if (xml.name() == "loyalty") loyalty = xml.readElementText().toInt(); else if (xml.name() == "token") @@ -910,7 +923,7 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml, bool tokens) } if (isToken == tokens) { - addCard(new CardInfo(this, name, isToken, manacost, cmc, type, pt, text, colors, relatedCards, loyalty, cipt, tableRow, sets, customPicURLs, customPicURLsHq, muids)); + addCard(new CardInfo(this, name, isToken, manacost, cmc, type, pt, text, colors, relatedCards, upsideDown, loyalty, cipt, tableRow, sets, customPicURLs, customPicURLsHq, muids)); } } } diff --git a/cockatrice/src/carddatabase.h b/cockatrice/src/carddatabase.h index 67a08def..af817778 100644 --- a/cockatrice/src/carddatabase.h +++ b/cockatrice/src/carddatabase.h @@ -133,6 +133,7 @@ private: QString text; QStringList colors; QStringList relatedCards; + bool upsideDownArt; int loyalty; QStringMap customPicURLs, customPicURLsHq; MuidMap muIds; @@ -150,6 +151,7 @@ public: const QString &_text = QString(), const QStringList &_colors = QStringList(), const QStringList &_relatedCards = QStringList(), + bool _upsideDownArt = false, int _loyalty = 0, bool _cipt = false, int _tableRow = 0, @@ -178,6 +180,7 @@ public: void setColors(const QStringList &_colors) { colors = _colors; emit cardInfoChanged(this); } const QStringList &getColors() const { return colors; } const QStringList &getRelatedCards() const { return relatedCards; } + bool getUpsideDownArt() const { return upsideDownArt; } QString getCustomPicURL(const QString &set) const { return customPicURLs.value(set); } QString getCustomPicURLHq(const QString &set) const { return customPicURLsHq.value(set); } int getMuId(const QString &set) const { return muIds.value(set); } diff --git a/oracle/src/oracleimporter.cpp b/oracle/src/oracleimporter.cpp index 78b5f16a..3a5d2f4e 100644 --- a/oracle/src/oracleimporter.cpp +++ b/oracle/src/oracleimporter.cpp @@ -66,7 +66,8 @@ CardInfo *OracleImporter::addCard(const QString &setName, int cardLoyalty, const QString &cardText, const QStringList & colors, - const QStringList & relatedCards + const QStringList & relatedCards, + bool upsideDown ) { QStringList cardTextRows = cardText.split("\n"); @@ -99,7 +100,7 @@ CardInfo *OracleImporter::addCard(const QString &setName, bool cipt = cardText.contains("Hideaway") || (cardText.contains(cardName + " enters the battlefield tapped") && !cardText.contains(cardName + " enters the battlefield tapped unless")); - card = new CardInfo(this, cardName, isToken, cardCost, cmc, cardType, cardPT, cardText, colors, relatedCards, cardLoyalty, cipt); + card = new CardInfo(this, cardName, isToken, cardCost, cmc, cardType, cardPT, cardText, colors, relatedCards, upsideDown, cardLoyalty, cipt); int tableRow = 1; QString mainCardType = card->getMainCardType(); if ((mainCardType == "Land") || mArtifact) @@ -153,6 +154,7 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QVariant &data) int cardId; int cardLoyalty; bool cardIsToken = false; + bool upsideDown = false; QMap splitCards; while (it.hasNext()) { @@ -208,6 +210,7 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QVariant &data) colors.removeDuplicates(); relatedCards = QStringList(); + upsideDown = false; } else { // first card of a pair; enqueue for later merging // Conditional on cardId because promo prints have no muid - see #640 @@ -227,7 +230,15 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QVariant &data) cardLoyalty = map.contains("loyalty") ? map.value("loyalty").toInt() : 0; cardIsToken = map.value("layout") == "token"; relatedCards = map.contains("names") ? map.value("names").toStringList() : QStringList(); - relatedCards.removeAll(cardName); + relatedCards.removeAll(cardName); + + if(0 == QString::compare(map.value("layout").toString(), QString("flip"), Qt::CaseInsensitive)) + { + QStringList cardNames = map.contains("names") ? map.value("names").toStringList() : QStringList(); + upsideDown = (cardNames.indexOf(cardName) > 0); + } else { + upsideDown = false; + } colors.clear(); extractColors(map.value("colors").toStringList(), colors); @@ -239,7 +250,7 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QVariant &data) } if (!cardIsToken) { - CardInfo *card = addCard(set->getShortName(), cardName, cardIsToken, cardId, cardCost, cmc, cardType, cardPT, cardLoyalty, cardText, colors, relatedCards); + CardInfo *card = addCard(set->getShortName(), cardName, cardIsToken, cardId, cardCost, cmc, cardType, cardPT, cardLoyalty, cardText, colors, relatedCards, upsideDown); if (!set->contains(card)) { card->addToSet(set); diff --git a/oracle/src/oracleimporter.h b/oracle/src/oracleimporter.h index 294d4c28..888eabaf 100644 --- a/oracle/src/oracleimporter.h +++ b/oracle/src/oracleimporter.h @@ -29,7 +29,7 @@ private: QVariantMap setsMap; QString dataDir; - CardInfo *addCard(const QString &setName, QString cardName, bool isToken, int cardId, QString &cardCost, QString &cmc, const QString &cardType, const QString &cardPT, int cardLoyalty, const QString &cardText, const QStringList & colors, const QStringList & relatedCards); + CardInfo *addCard(const QString &setName, QString cardName, bool isToken, int cardId, QString &cardCost, QString &cmc, const QString &cardType, const QString &cardPT, int cardLoyalty, const QString &cardText, const QStringList & colors, const QStringList & relatedCards, bool upsideDown); signals: void setIndexChanged(int cardsImported, int setIndex, const QString &setName); void dataReadProgress(int bytesRead, int totalBytes);