mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-14 14:32:15 -07:00
Dependency inject the card preference provider to satisfy dbconverter mocks.
Took 36 minutes
This commit is contained in:
parent
6939b6d623
commit
fc6ac89098
14 changed files with 62 additions and 10 deletions
|
|
@ -15,7 +15,7 @@
|
|||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
CardDatabase::CardDatabase(QObject *parent) : QObject(parent), loadStatus(NotLoaded)
|
||||
CardDatabase::CardDatabase(QObject *parent, std::shared_ptr<ICardPreferenceProvider> prefs) : QObject(parent), loadStatus(NotLoaded)
|
||||
{
|
||||
qRegisterMetaType<CardInfoPtr>("CardInfoPtr");
|
||||
qRegisterMetaType<CardInfoPtr>("CardSetPtr");
|
||||
|
|
@ -28,7 +28,7 @@ CardDatabase::CardDatabase(QObject *parent) : QObject(parent), loadStatus(NotLoa
|
|||
connect(loader, &CardDatabaseLoader::newSetsFound, this, &CardDatabase::cardDatabaseNewSetsFound);
|
||||
connect(loader, &CardDatabaseLoader::allNewSetsEnabled, this, &CardDatabase::cardDatabaseAllNewSetsEnabled);
|
||||
|
||||
querier = new CardDatabaseQuerier(this, this);
|
||||
querier = new CardDatabaseQuerier(this, this, prefs);
|
||||
}
|
||||
|
||||
CardDatabase::~CardDatabase()
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "../common/card_ref.h"
|
||||
#include "card_database_loader.h"
|
||||
#include "card_database_querier.h"
|
||||
#include "interface/noop_card_preference_provider.h"
|
||||
|
||||
#include <QBasicMutex>
|
||||
#include <QDate>
|
||||
|
|
@ -51,7 +52,7 @@ private:
|
|||
*removeCardMutex = new QBasicMutex();
|
||||
|
||||
public:
|
||||
explicit CardDatabase(QObject *parent = nullptr);
|
||||
explicit CardDatabase(QObject *parent = nullptr, std::shared_ptr<ICardPreferenceProvider> prefs = nullptr);
|
||||
~CardDatabase() override;
|
||||
|
||||
void removeCard(CardInfoPtr card);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
CardDatabase *CardDatabaseManager::getInstance()
|
||||
{
|
||||
static CardDatabase instance; // Created only once, on first access
|
||||
static CardDatabase instance(nullptr, std::make_shared<SettingsCardPreferenceProvider>()); // Created only once, on first access
|
||||
return &instance;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,11 @@
|
|||
#include "../settings/cache_settings.h"
|
||||
#include "../utility/card_set_comparator.h"
|
||||
#include "card_database.h"
|
||||
#include "interface/settings_card_preference_provider.h"
|
||||
|
||||
#include <qrandom.h>
|
||||
|
||||
CardDatabaseQuerier::CardDatabaseQuerier(QObject *_parent, const CardDatabase *_db) : QObject(_parent), db(_db)
|
||||
CardDatabaseQuerier::CardDatabaseQuerier(QObject *_parent, const CardDatabase *_db, std::shared_ptr<ICardPreferenceProvider> prefs) : QObject(_parent), db(_db), prefs(std::move(prefs))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -246,8 +247,7 @@ PrintingInfo CardDatabaseQuerier::getPreferredPrinting(const CardInfoPtr &cardIn
|
|||
return PrintingInfo(nullptr);
|
||||
}
|
||||
|
||||
const auto &pinnedPrintingProviderId =
|
||||
SettingsCache::instance().cardOverrides().getCardPreferenceOverride(cardInfo->getName());
|
||||
const auto &pinnedPrintingProviderId = prefs->getCardPreferenceOverride(cardInfo->getName());
|
||||
|
||||
if (!pinnedPrintingProviderId.isEmpty()) {
|
||||
return getSpecificPrinting({cardInfo->getName(), pinnedPrintingProviderId});
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "../card/exact_card.h"
|
||||
#include "../common/card_ref.h"
|
||||
#include "interface/interface_card_preference_provider.h"
|
||||
#include "interface/settings_card_preference_provider.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
|
|
@ -12,7 +14,7 @@ class CardDatabaseQuerier : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CardDatabaseQuerier(QObject *parent, const CardDatabase *db);
|
||||
explicit CardDatabaseQuerier(QObject *parent, const CardDatabase *db, std::shared_ptr<ICardPreferenceProvider> prefs);
|
||||
|
||||
[[nodiscard]] CardInfoPtr getCardInfo(const QString &cardName) const;
|
||||
[[nodiscard]] QList<CardInfoPtr> getCardInfos(const QStringList &cardNames) const;
|
||||
|
|
@ -49,6 +51,8 @@ public:
|
|||
private:
|
||||
const CardDatabase *db;
|
||||
|
||||
std::shared_ptr<ICardPreferenceProvider> prefs;
|
||||
|
||||
CardInfoPtr lookupCardByName(const QString &name) const;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
#include "../../utility/interface_card_preference_provider.h"
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef COCKATRICE_INTERFACE_CARD_PREFERENCE_PROVIDER_H
|
||||
#define COCKATRICE_INTERFACE_CARD_PREFERENCE_PROVIDER_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
class ICardPreferenceProvider {
|
||||
public:
|
||||
virtual ~ICardPreferenceProvider() = default;
|
||||
virtual QString getCardPreferenceOverride(const QString &cardName) const = 0;
|
||||
};
|
||||
|
||||
#endif //COCKATRICE_INTERFACE_CARD_PREFERENCE_PROVIDER_H
|
||||
|
|
@ -0,0 +1 @@
|
|||
#include "noop_card_preference_provider.h"
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef COCKATRICE_NOOP_CARD_PREFERENCE_PROVIDER_H
|
||||
#define COCKATRICE_NOOP_CARD_PREFERENCE_PROVIDER_H
|
||||
#include "interface_card_preference_provider.h"
|
||||
|
||||
class NoopCardPreferenceProvider : public ICardPreferenceProvider {
|
||||
public:
|
||||
QString getCardPreferenceOverride(const QString &) const override {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
#endif //COCKATRICE_NOOP_CARD_PREFERENCE_PROVIDER_H
|
||||
|
|
@ -0,0 +1 @@
|
|||
#include "../../utility/settings_card_preference_provider.h"
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef COCKATRICE_SETTINGS_CARD_PREFERENCE_PROVIDER_H
|
||||
#define COCKATRICE_SETTINGS_CARD_PREFERENCE_PROVIDER_H
|
||||
#include "interface_card_preference_provider.h"
|
||||
#include "../../settings/cache_settings.h"
|
||||
|
||||
class SettingsCardPreferenceProvider : public ICardPreferenceProvider {
|
||||
public:
|
||||
QString getCardPreferenceOverride(const QString &cardName) const override {
|
||||
return SettingsCache::instance().cardOverrides().getCardPreferenceOverride(cardName);
|
||||
}
|
||||
};
|
||||
|
||||
#endif //COCKATRICE_SETTINGS_CARD_PREFERENCE_PROVIDER_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue