servatrice/oracle/src/oracleimporter.h
ctrlaltca ed70099e36 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
2019-01-23 18:17:10 -05:00

119 lines
2.9 KiB
C++

#ifndef ORACLEIMPORTER_H
#define ORACLEIMPORTER_H
#include <QMap>
#include <QVariant>
#include <carddatabase.h>
#include <utility>
class SetToDownload
{
private:
QString shortName, longName;
QList<QVariant> cards;
QDate releaseDate;
QString setType;
public:
const QString &getShortName() const
{
return shortName;
}
const QString &getLongName() const
{
return longName;
}
const QList<QVariant> &getCards() const
{
return cards;
}
const QString &getSetType() const
{
return setType;
}
const QDate &getReleaseDate() const
{
return releaseDate;
}
SetToDownload(QString _shortName,
QString _longName,
QList<QVariant> _cards,
QString _setType = QString(),
const QDate &_releaseDate = QDate())
: shortName(std::move(_shortName)), longName(std::move(_longName)), cards(std::move(_cards)),
releaseDate(_releaseDate), setType(std::move(_setType))
{
}
bool operator<(const SetToDownload &set) const
{
return longName.compare(set.longName, Qt::CaseInsensitive) < 0;
}
};
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
private:
QList<SetToDownload> allSets;
QVariantMap setsMap;
QString dataDir;
CardInfoPtr addCard(QString name,
QString text,
bool isToken,
QVariantHash properties,
QList<CardRelation *> &relatedCards,
CardInfoPerSet setInfo);
signals:
void setIndexChanged(int cardsImported, int setIndex, const QString &setName);
void dataReadProgress(int bytesRead, int totalBytes);
public:
explicit OracleImporter(const QString &_dataDir, QObject *parent = nullptr);
bool readSetsFromByteArray(const QByteArray &data);
int startImport();
bool saveToFile(const QString &fileName);
int importCardsFromSet(CardSetPtr currentSet, const QList<QVariant> &cards);
QList<SetToDownload> &getSets()
{
return allSets;
}
const QString &getDataDir() const
{
return dataDir;
}
protected:
inline QString getStringPropertyFromMap(QVariantMap card, QString propertyName);
void sortAndReduceColors(QString &colors);
};
#endif