Rework of the card database, xml format and oracle parser (#3511)

* CardDB: merge all card properties in a new structure

* Pre Json parser changes

 * Cockatrice: use qt's builtin json support
 * Move qt-json src dir from cockatrice to oracle
 * Add dummy cockatricexml4 parser (yet to be implemented)

* Implement a new parser and xml format

 * cockatricexml4: new xml parser following the "generic properties hash" pattern;
 * oracleimporter: refactor the parsing code to better adapt to cockatricexml4; rewrote split cards parsing
 * carddb: change "colors" from a stringlist to a string
 * carddb: move the getMainCardType() method to the cockatricexml3 parser
 *

* CardInfo: show all properties (stil missing: nice name + translation)

* Rework the "add related card" feature so that it doesn't change the card name in the carddb

Also, fix token count display

* Picture loader: Added support for transform cards

* Fix side information for flip cards

Mtgjson uses side a/b for flip cards, while scryfall doesn't

* Pictureloader: dynamic tag resolution from card properties

Examples old => new
* !cardid! => !set:muid!
* !uuid!   => !set:uuid!
* !collectornumber! => !set:num!
New examples:
 * !prop:type!
 * !prop:manacost!

* Start moving mtg-related property names to a specific file

* Clangify

* Fix tests

* Make gcc an happy puppy

* Revert "Make gcc an happy puppy"

This reverts commit 446ec5f27516c4d3b32dbfc79557f4827c5c5bdf.

* Some gcc fixes

* Share set list between different db parsers, so they won't overwrite one each other

* All glory to the hypnoclangifier!

* Fix test compilation

* Cleanup edited files in the prior PR. (#3519)

* Cleanup edited files in the prior PR.

Signed-off-by: Zach Halpern <ZaHalpern+github@gmail.com>

* Fix includes

Signed-off-by: Zach Halpern <ZaHalpern+github@gmail.com>

* Update carddatabase.h
This commit is contained in:
ctrlaltca 2019-01-24 00:17:10 +01:00 committed by Zach H
parent 19180243aa
commit ed70099e36
44 changed files with 1814 additions and 1360 deletions

View file

@ -3,14 +3,14 @@
#include <QMap>
#include <QVariant>
#include <carddatabase.h>
#include <utility>
class SetToDownload
{
private:
QString shortName, longName;
QVariant cards;
QList<QVariant> cards;
QDate releaseDate;
QString setType;
@ -23,7 +23,7 @@ public:
{
return longName;
}
const QVariant &getCards() const
const QList<QVariant> &getCards() const
{
return cards;
}
@ -35,12 +35,13 @@ public:
{
return releaseDate;
}
SetToDownload(const QString &_shortName,
const QString &_longName,
const QVariant &_cards,
const QString &_setType = QString(),
SetToDownload(QString _shortName,
QString _longName,
QList<QVariant> _cards,
QString _setType = QString(),
const QDate &_releaseDate = QDate())
: shortName(_shortName), longName(_longName), cards(_cards), releaseDate(_releaseDate), setType(_setType)
: shortName(std::move(_shortName)), longName(std::move(_longName)), cards(std::move(_cards)),
releaseDate(_releaseDate), setType(std::move(_setType))
{
}
bool operator<(const SetToDownload &set) const
@ -49,6 +50,34 @@ public:
}
};
class SplitCardPart
{
public:
SplitCardPart(int _index, const QString &_text, const QVariantHash &_properties, CardInfoPerSet setInfo);
inline const int &getIndex() const
{
return index;
}
inline const QString &getText() const
{
return text;
}
inline const QVariantHash &getProperties() const
{
return properties;
}
inline const CardInfoPerSet &getSetInfo() const
{
return setInfo;
}
private:
int index;
QString text;
QVariantHash properties;
CardInfoPerSet setInfo;
};
class OracleImporter : public CardDatabase
{
Q_OBJECT
@ -57,33 +86,22 @@ private:
QVariantMap setsMap;
QString dataDir;
CardInfoPtr addCard(const QString &setName,
QString cardName,
CardInfoPtr addCard(QString name,
QString text,
bool isToken,
int cardId,
QString &cardUuId,
QString &setNumber,
QString &cardCost,
QString &cmc,
const QString &cardType,
const QString &cardPT,
const QString &cardLoyalty,
const QString &cardText,
const QStringList &colors,
const QList<CardRelation *> &relatedCards,
const QList<CardRelation *> &reverseRelatedCards,
bool upsideDown,
QString &rarity);
QVariantHash properties,
QList<CardRelation *> &relatedCards,
CardInfoPerSet setInfo);
signals:
void setIndexChanged(int cardsImported, int setIndex, const QString &setName);
void dataReadProgress(int bytesRead, int totalBytes);
public:
OracleImporter(const QString &_dataDir, QObject *parent = 0);
explicit OracleImporter(const QString &_dataDir, QObject *parent = nullptr);
bool readSetsFromByteArray(const QByteArray &data);
int startImport();
bool saveToFile(const QString &fileName);
int importTextSpoiler(CardSetPtr set, const QVariant &data);
int importCardsFromSet(CardSetPtr currentSet, const QList<QVariant> &cards);
QList<SetToDownload> &getSets()
{
return allSets;
@ -94,7 +112,8 @@ public:
}
protected:
void sortColors(QStringList &colors);
inline QString getStringPropertyFromMap(QVariantMap card, QString propertyName);
void sortAndReduceColors(QString &colors);
};
#endif