1 #ifndef ORACLEIMPORTER_H 2 #define ORACLEIMPORTER_H 3 4 #include <QMap> 5 #include <QVariant> 6 #include <carddatabase.h> 7 #include <utility> 8 9 // many users prefer not to see these sets with non english arts 10 // as a solution we remove the date property on these sets 11 // that way they will be sorted last by default 12 // this will cause their art to not get priority over english cards 13 // users will still be able to find these sets and prioritize them manually 14 const QStringList nonEnglishSets = {"4BB", "FBB", "PS11", "PSAL", "REN", "RIN"}; 15 16 class SetToDownload 17 { 18 private: 19 QString shortName, longName; 20 QList<QVariant> cards; 21 QDate releaseDate; 22 QString setType; 23 24 public: getShortName()25 const QString &getShortName() const 26 { 27 return shortName; 28 } getLongName()29 const QString &getLongName() const 30 { 31 return longName; 32 } getCards()33 const QList<QVariant> &getCards() const 34 { 35 return cards; 36 } getSetType()37 const QString &getSetType() const 38 { 39 return setType; 40 } getReleaseDate()41 const QDate &getReleaseDate() const 42 { 43 return releaseDate; 44 } 45 SetToDownload(QString _shortName, 46 QString _longName, 47 QList<QVariant> _cards, 48 QString _setType = QString(), 49 const QDate &_releaseDate = QDate()) shortName(std::move (_shortName))50 : shortName(std::move(_shortName)), longName(std::move(_longName)), cards(std::move(_cards)), 51 releaseDate(_releaseDate), setType(std::move(_setType)) 52 { 53 } 54 bool operator<(const SetToDownload &set) const 55 { 56 return longName.compare(set.longName, Qt::CaseInsensitive) < 0; 57 } 58 }; 59 60 class SplitCardPart 61 { 62 public: 63 SplitCardPart(const QString &_name, const QString &_text, const QVariantHash &_properties, CardInfoPerSet setInfo); getName()64 inline const QString &getName() const 65 { 66 return name; 67 } getText()68 inline const QString &getText() const 69 { 70 return text; 71 } getProperties()72 inline const QVariantHash &getProperties() const 73 { 74 return properties; 75 } getSetInfo()76 inline const CardInfoPerSet &getSetInfo() const 77 { 78 return setInfo; 79 } 80 81 private: 82 QString name; 83 QString text; 84 QVariantHash properties; 85 CardInfoPerSet setInfo; 86 }; 87 88 class OracleImporter : public CardDatabase 89 { 90 Q_OBJECT 91 private: 92 const QStringList mainCardTypes = {"Planeswalker", "Creature", "Land", "Sorcery", 93 "Instant", "Artifact", "Enchantment"}; 94 QList<SetToDownload> allSets; 95 QVariantMap setsMap; 96 QString dataDir; 97 98 QString getMainCardType(const QStringList &typeList); 99 CardInfoPtr addCard(QString name, 100 QString text, 101 bool isToken, 102 QVariantHash properties, 103 QList<CardRelation *> &relatedCards, 104 CardInfoPerSet setInfo); 105 signals: 106 void setIndexChanged(int cardsImported, int setIndex, const QString &setName); 107 void dataReadProgress(int bytesRead, int totalBytes); 108 109 public: 110 explicit OracleImporter(const QString &_dataDir, QObject *parent = nullptr); 111 bool readSetsFromByteArray(const QByteArray &data); 112 int startImport(); 113 bool saveToFile(const QString &fileName, const QString &sourceUrl, const QString &sourceVersion); 114 int importCardsFromSet(const CardSetPtr ¤tSet, const QList<QVariant> &cards, bool skipSpecialNums = true); getSets()115 QList<SetToDownload> &getSets() 116 { 117 return allSets; 118 } getDataDir()119 const QString &getDataDir() const 120 { 121 return dataDir; 122 } 123 void clear(); 124 125 protected: 126 inline QString getStringPropertyFromMap(const QVariantMap &card, const QString &propertyName); 127 void sortAndReduceColors(QString &colors); 128 }; 129 130 #endif 131