mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-15 19:47:46 -07:00
Split pictuloader out of carddatabase
This commit is contained in:
parent
aebc18fc3f
commit
4d7795ca3a
19 changed files with 648 additions and 686 deletions
|
|
@ -8,17 +8,9 @@
|
|||
#include <QDataStream>
|
||||
#include <QList>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QNetworkRequest>
|
||||
#include <QThread>
|
||||
#include <QMutex>
|
||||
#include <QWaitCondition>
|
||||
#include <QPixmapCache>
|
||||
|
||||
class CardDatabase;
|
||||
class CardInfo;
|
||||
class QNetworkAccessManager;
|
||||
class QNetworkReply;
|
||||
class QNetworkRequest;
|
||||
|
||||
typedef QMap<QString, QString> QStringMap;
|
||||
|
||||
|
|
@ -55,9 +47,7 @@ public:
|
|||
class SetList : public QList<CardSet *> {
|
||||
private:
|
||||
class KeyCompareFunctor;
|
||||
class EnabledAndKeyCompareFunctor;
|
||||
public:
|
||||
void sortByEnabledAndKey();
|
||||
void sortByKey();
|
||||
void guessSortKeys();
|
||||
void enableAllUnknown();
|
||||
|
|
@ -67,53 +57,6 @@ public:
|
|||
int getUnknownSetsNum();
|
||||
};
|
||||
|
||||
class PictureToLoad {
|
||||
private:
|
||||
CardInfo *card;
|
||||
SetList sortedSets;
|
||||
int setIndex;
|
||||
bool hq;
|
||||
public:
|
||||
PictureToLoad(CardInfo *_card = 0, bool _hq = true);
|
||||
CardInfo *getCard() const { return card; }
|
||||
CardSet *getCurrentSet() const;
|
||||
QString getSetName() const;
|
||||
bool nextSet();
|
||||
bool getHq() const { return hq; }
|
||||
void setHq(bool _hq) { hq = _hq; }
|
||||
};
|
||||
|
||||
class PictureLoader : public QObject {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QString _picsPath;
|
||||
QList<PictureToLoad> loadQueue;
|
||||
QMutex mutex;
|
||||
QNetworkAccessManager *networkManager;
|
||||
QList<PictureToLoad> cardsToDownload;
|
||||
PictureToLoad cardBeingLoaded;
|
||||
PictureToLoad cardBeingDownloaded;
|
||||
bool picDownload, picDownloadHq, downloadRunning, loadQueueRunning;
|
||||
void startNextPicDownload();
|
||||
QString getPicUrl();
|
||||
static QStringList md5Blacklist;
|
||||
public:
|
||||
PictureLoader(const QString &__picsPath, bool _picDownload, bool _picDownloadHq, QObject *parent = 0);
|
||||
~PictureLoader();
|
||||
void setPicsPath(const QString &path);
|
||||
void setPicDownload(bool _picDownload);
|
||||
void setPicDownloadHq(bool _picDownloadHq);
|
||||
void loadImage(CardInfo *card);
|
||||
private slots:
|
||||
void picDownloadFinished(QNetworkReply *reply);
|
||||
void picDownloadFailed();
|
||||
public slots:
|
||||
void processLoadQueue();
|
||||
signals:
|
||||
void startLoadQueue();
|
||||
void imageLoaded(CardInfo *card, const QImage &image);
|
||||
};
|
||||
|
||||
class CardInfo : public QObject {
|
||||
Q_OBJECT
|
||||
private:
|
||||
|
|
@ -138,7 +81,7 @@ private:
|
|||
QStringList relatedCards;
|
||||
bool upsideDownArt;
|
||||
int loyalty;
|
||||
QStringMap customPicURLs, customPicURLsHq;
|
||||
QStringMap customPicURLs;
|
||||
MuidMap muIds;
|
||||
bool cipt;
|
||||
int tableRow;
|
||||
|
|
@ -160,7 +103,6 @@ public:
|
|||
int _tableRow = 0,
|
||||
const SetList &_sets = SetList(),
|
||||
const QStringMap &_customPicURLs = QStringMap(),
|
||||
const QStringMap &_customPicURLsHq = QStringMap(),
|
||||
MuidMap muids = MuidMap()
|
||||
);
|
||||
~CardInfo();
|
||||
|
|
@ -173,6 +115,7 @@ public:
|
|||
const QString &getCardType() const { return cardtype; }
|
||||
const QString &getPowTough() const { return powtough; }
|
||||
const QString &getText() const { return text; }
|
||||
const QString &getPixmapCacheKey() const { return pixmapCacheKey; }
|
||||
const int &getLoyalty() const { return loyalty; }
|
||||
bool getCipt() const { return cipt; }
|
||||
void setManaCost(const QString &_manaCost) { manacost = _manaCost; emit cardInfoChanged(this); }
|
||||
|
|
@ -185,7 +128,6 @@ public:
|
|||
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); }
|
||||
QString getMainCardType() const;
|
||||
QString getCorrectedName() const;
|
||||
|
|
@ -193,22 +135,15 @@ public:
|
|||
void setTableRow(int _tableRow) { tableRow = _tableRow; }
|
||||
void setLoyalty(int _loyalty) { loyalty = _loyalty; emit cardInfoChanged(this); }
|
||||
void setCustomPicURL(const QString &_set, const QString &_customPicURL) { customPicURLs.insert(_set, _customPicURL); }
|
||||
void setCustomPicURLHq(const QString &_set, const QString &_customPicURL) { customPicURLsHq.insert(_set, _customPicURL); }
|
||||
void setMuId(const QString &_set, const int &_muId) { muIds.insert(_set, _muId); }
|
||||
void addToSet(CardSet *set);
|
||||
void loadPixmap(QPixmap &pixmap);
|
||||
void getPixmap(QSize size, QPixmap &pixmap);
|
||||
void clearPixmapCache();
|
||||
void clearPixmapCacheMiss();
|
||||
void imageLoaded(const QImage &image);
|
||||
void emitPixmapUpdated() { emit pixmapUpdated(); }
|
||||
|
||||
/**
|
||||
* Simplify a name to have no punctuation and lowercase all letters, for
|
||||
* less strict name-matching.
|
||||
*/
|
||||
static QString simplifyName(const QString &name);
|
||||
public slots:
|
||||
void updatePixmapCache();
|
||||
signals:
|
||||
void pixmapUpdated();
|
||||
void cardInfoChanged(CardInfo *card);
|
||||
|
|
@ -237,10 +172,11 @@ protected:
|
|||
*/
|
||||
SetNameMap sets;
|
||||
|
||||
/*
|
||||
* A dummy card returned by getCard() ad a fallback
|
||||
*/
|
||||
CardInfo *noCard;
|
||||
|
||||
QThread *pictureLoaderThread;
|
||||
PictureLoader *pictureLoader;
|
||||
LoadStatus loadStatus;
|
||||
bool detectedFirstRun;
|
||||
private:
|
||||
|
|
@ -258,13 +194,17 @@ public:
|
|||
void clear();
|
||||
void addCard(CardInfo *card);
|
||||
void removeCard(CardInfo *card);
|
||||
CardInfo *getCard(const QString &cardName = QString(), bool createIfNotFound = true);
|
||||
/*
|
||||
* Get card object by name. Ensured to return a valid CardInfo * object; check noCard
|
||||
*/
|
||||
CardInfo *getCard(const QString &cardName = QString(), bool createIfNotFound = false);
|
||||
QList <CardInfo *> getCards(const QStringList &cardNames);
|
||||
|
||||
/*
|
||||
* Get a card by its simple name. The name will be simplified in this
|
||||
* function, so you don't need to simplify it beforehand.
|
||||
*/
|
||||
CardInfo *getCardBySimpleName(const QString &cardName = QString(), bool createIfNotFound = true);
|
||||
CardInfo *getCardBySimpleName(const QString &cardName = QString(), bool createIfNotFound = false);
|
||||
|
||||
CardSet *getSet(const QString &setName);
|
||||
QList<CardInfo *> getCardList() const { return cards.values(); }
|
||||
|
|
@ -275,20 +215,12 @@ public:
|
|||
QStringList getAllMainCardTypes() const;
|
||||
LoadStatus getLoadStatus() const { return loadStatus; }
|
||||
bool getLoadSuccess() const { return loadStatus == Ok; }
|
||||
void cacheCardPixmaps(const QStringList &cardNames);
|
||||
void loadImage(CardInfo *card);
|
||||
bool hasDetectedFirstRun();
|
||||
public slots:
|
||||
void clearPixmapCache();
|
||||
LoadStatus loadCardDatabase(const QString &path, bool tokens = false);
|
||||
void loadCustomCardDatabases(const QString &path);
|
||||
void emitCardListChanged();
|
||||
private slots:
|
||||
void imageLoaded(CardInfo *card, QImage image);
|
||||
void picDownloadChanged();
|
||||
void picDownloadHqChanged();
|
||||
void picsPathChanged();
|
||||
|
||||
void loadCardDatabase();
|
||||
void loadTokenDatabase();
|
||||
signals:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue