mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-15 19:47:46 -07:00
Multiple Printings per Deck (#5171)
* Refactor CardInfo Widgets to reside in their appropriate folder and to have a clearer naming structure. * Added Zach's work on storing printing information in the DeckList (#1) * Change CardInfo's PixmapCacheKey to be the UUID of the preferred set after database loading has finished. Otherwise, and if no UUID of a preferred set is available, default to the card name. * Refactor CardDatabase *db global variable to singleton CardDatabaseManager. This commit refactors the global variable CardDatabase *db into a singleton encapsulated by the DatabaseManager class, accessible via DatabaseManager::getInstance(). This change centralizes access to the database instance, improving code modularity and encapsulation, resolving dependencies on main.h for code that requires access to the database instance. - Added DatabaseManager class with getInstance() method returning a pointer to the singleton CardDatabase. - Removed global db variable and updated references across the codebase. - Thread-safe static initialization for the singleton. Impact: This refactor should have no functional impact on the application, as it maintains the same interface for accessing the CardDatabase instance. However, the codebase now benefits from improved encapsulation, lifetime management, and thread-safety. * fixed db issue an renamed sets to set in picture loader * canibalized zach work and added it to the decklist builder --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de> * Reintroduce some changes lost in the merge. * Introduce UUID attribute to abstract_card_item, card_item, deck_view_card, server_card and serverinfo_card. * Have various game events respect the new UUID attribute on instantiation. * Correct some calls to default to preferred printing. * DeckList now tries to assign reasonable defaults for UUID and collectorNumber if none are found in loaded DeckLists. Rename overloaded DeckListModel findChild() function to findCardChildByNameAndUUID() for clarity. * canibalized zach work and added it to the decklist builder * Change getPreferredPrintingForCard to getPreferredSetForCard to reflect refactor. * Properly update and set the DeckEditor's CardFrame to fetch by name and UUID if a card was selected from the decklist. * Mainboard/Sideboard swaps should respect the UUID from the old zone instead of just blindly adding preferredPrinting. * If the card info is null, there's no point in trying to look for the sets. * Don't define methods twice. * Convenience method to fetch a specific CardInfoPerSet instance for a cardName and a UUID. * Check if the uuid starts with card_ when comparing. * Address pull request comments (nullptr checks and additional comments, mostly.) * Reformat code so the linter will stop yelling at me. * DeckList no longer pre-populates uuids. * Update Event_MoveCard to include the card UUID. * Update Player::MoveCard to include the card UUID. * Set the uuid when we set the cardName, in terms of hidden zones. * [TEST/RevertMe] Set the uuid everywhere to test. * Don't inline setUUID and mimic setName for AbstractCardItem. * Revert blindly setting uuid for testing. * Address PR comments (AbstractCardItem). * Combine if-statement. * Re-order uuid to visually align with its field number. * Remove unnecessary new uuid field from event_move_card. * Remove unused imports. * Include cardName in the PixmapCacheKey in order to not break double-faced cards. * Refactor setCode to cardUUID and introduce new cardSetShortName field. * Override * Refactor UUID to be providerId and change QString comparisons with empty string to isEmpty(). * Update translations. * Change parent to be the first argument. * Pull Parent argument up for CardItem. * Pull Parent argument up for CardItem. * Linter. --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de> Co-authored-by: LunaticCat <39006478+LunyaticCat@users.noreply.github.com> Co-authored-by: luna <yannbrun1507@outlook.fr> Co-authored-by: ZeldaZach <zahalpern+github@gmail.com>
This commit is contained in:
parent
86a4b130ff
commit
f73196841a
26 changed files with 397 additions and 491 deletions
|
|
@ -1,7 +1,6 @@
|
|||
#include "abstract_card_item.h"
|
||||
|
||||
#include "../../client/ui/picture_loader.h"
|
||||
#include "../../main.h"
|
||||
#include "../../settings/cache_settings.h"
|
||||
#include "../game_scene.h"
|
||||
#include "card_database.h"
|
||||
|
|
@ -13,9 +12,13 @@
|
|||
#include <QPainter>
|
||||
#include <algorithm>
|
||||
|
||||
AbstractCardItem::AbstractCardItem(const QString &_name, Player *_owner, int _id, QGraphicsItem *parent)
|
||||
: ArrowTarget(_owner, parent), id(_id), name(_name), tapped(false), facedown(false), tapAngle(0),
|
||||
bgColor(Qt::transparent), isHovered(false), realZValue(0)
|
||||
AbstractCardItem::AbstractCardItem(QGraphicsItem *parent,
|
||||
const QString &_name,
|
||||
const QString &_providerId,
|
||||
Player *_owner,
|
||||
int _id)
|
||||
: ArrowTarget(_owner, parent), id(_id), name(_name), providerId(_providerId), tapped(false), facedown(false),
|
||||
tapAngle(0), bgColor(Qt::transparent), isHovered(false), realZValue(0)
|
||||
{
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
setFlag(ItemIsSelectable);
|
||||
|
|
@ -50,7 +53,7 @@ void AbstractCardItem::pixmapUpdated()
|
|||
|
||||
void AbstractCardItem::cardInfoUpdated()
|
||||
{
|
||||
info = CardDatabaseManager::getInstance()->getCard(name);
|
||||
info = CardDatabaseManager::getInstance()->getCardByNameAndProviderId(name, providerId);
|
||||
|
||||
if (!info && !name.isEmpty()) {
|
||||
QVariantHash properties = QVariantHash();
|
||||
|
|
@ -185,6 +188,21 @@ void AbstractCardItem::setName(const QString &_name)
|
|||
cardInfoUpdated();
|
||||
}
|
||||
|
||||
void AbstractCardItem::setProviderId(const QString &_providerId)
|
||||
{
|
||||
if (providerId == _providerId) {
|
||||
return;
|
||||
}
|
||||
|
||||
emit deleteCardInfoPopup(name);
|
||||
if (info) {
|
||||
disconnect(info.data(), nullptr, this, nullptr);
|
||||
}
|
||||
providerId = _providerId;
|
||||
|
||||
cardInfoUpdated();
|
||||
}
|
||||
|
||||
void AbstractCardItem::setHovered(bool _hovered)
|
||||
{
|
||||
if (isHovered == _hovered)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ protected:
|
|||
CardInfoPtr info;
|
||||
int id;
|
||||
QString name;
|
||||
QString providerId;
|
||||
bool tapped;
|
||||
bool facedown;
|
||||
int tapAngle;
|
||||
|
|
@ -48,10 +49,11 @@ public:
|
|||
{
|
||||
return Type;
|
||||
}
|
||||
AbstractCardItem(const QString &_name = QString(),
|
||||
AbstractCardItem(QGraphicsItem *parent = nullptr,
|
||||
const QString &_name = QString(),
|
||||
const QString &_providerId = QString(),
|
||||
Player *_owner = nullptr,
|
||||
int _id = -1,
|
||||
QGraphicsItem *parent = nullptr);
|
||||
int _id = -1);
|
||||
~AbstractCardItem();
|
||||
QRectF boundingRect() const override;
|
||||
QPainterPath shape() const override;
|
||||
|
|
@ -75,6 +77,11 @@ public:
|
|||
return name;
|
||||
}
|
||||
void setName(const QString &_name = QString());
|
||||
QString getProviderId() const
|
||||
{
|
||||
return providerId;
|
||||
}
|
||||
void setProviderId(const QString &_providerId = QString());
|
||||
qreal getRealZValue() const
|
||||
{
|
||||
return realZValue;
|
||||
|
|
|
|||
|
|
@ -441,13 +441,18 @@ QList<CardInfoPtr> CardDatabase::getCards(const QStringList &cardNames) const
|
|||
return cardInfos;
|
||||
}
|
||||
|
||||
CardInfoPtr CardDatabase::getCardByNameAndUUID(const QString &cardName, const QString &uuid) const
|
||||
CardInfoPtr CardDatabase::getCardByNameAndProviderId(const QString &cardName, const QString &providerId) const
|
||||
{
|
||||
auto info = getCard(cardName);
|
||||
if (providerId.isNull() || providerId.isEmpty() || info.isNull()) {
|
||||
return info;
|
||||
}
|
||||
|
||||
for (const auto &set : info->getSets()) {
|
||||
if (set.getProperty("uuid") == uuid) {
|
||||
if (set.getProperty("uuid") == providerId) {
|
||||
CardInfoPtr cardFromSpecificSet = info->clone();
|
||||
cardFromSpecificSet->setPixmapCacheKey(QLatin1String("card_") + QString(set.getProperty("uuid")));
|
||||
cardFromSpecificSet->setPixmapCacheKey(QLatin1String("card_") + QString(info->getName()) + QString("_") +
|
||||
QString(set.getProperty("uuid")));
|
||||
return cardFromSpecificSet;
|
||||
}
|
||||
}
|
||||
|
|
@ -596,7 +601,8 @@ LoadStatus CardDatabase::loadCardDatabases()
|
|||
void CardDatabase::refreshPreferredPrintings()
|
||||
{
|
||||
for (const CardInfoPtr &card : cards) {
|
||||
card->setPixmapCacheKey(QLatin1String("card_") + QString(getPreferredPrintingUUIDForCard(card->getName())));
|
||||
card->setPixmapCacheKey(QLatin1String("card_") + QString(card->getName()) + QString("_") +
|
||||
QString(getPreferredPrintingProviderIdForCard(card->getName())));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -631,23 +637,48 @@ CardInfoPerSet CardDatabase::getPreferredSetForCard(const QString &cardName)
|
|||
return CardInfoPerSet(nullptr);
|
||||
}
|
||||
|
||||
QString CardDatabase::getPreferredPrintingUUIDForCard(const QString &cardName)
|
||||
CardInfoPerSet CardDatabase::getSpecificSetForCard(const QString &cardName, const QString &providerId) const
|
||||
{
|
||||
CardInfoPtr cardInfo = getCard(cardName);
|
||||
if (!cardInfo) {
|
||||
return CardInfoPerSet(nullptr);
|
||||
}
|
||||
|
||||
CardInfoPerSetMap setMap = cardInfo->getSets();
|
||||
if (setMap.empty()) {
|
||||
return CardInfoPerSet(nullptr);
|
||||
}
|
||||
|
||||
for (auto &cardInfoForSet : setMap) {
|
||||
if (cardInfoForSet.getProperty("uuid") == providerId) {
|
||||
return cardInfoForSet;
|
||||
}
|
||||
}
|
||||
|
||||
return CardInfoPerSet(nullptr);
|
||||
}
|
||||
|
||||
QString CardDatabase::getPreferredPrintingProviderIdForCard(const QString &cardName)
|
||||
{
|
||||
CardInfoPerSet preferredSetCardInfo = getPreferredSetForCard(cardName);
|
||||
QString preferredPrintingUUID = preferredSetCardInfo.getProperty(QString("uuid"));
|
||||
if (preferredPrintingUUID.isEmpty()) {
|
||||
QString preferredPrintingProviderId = preferredSetCardInfo.getProperty(QString("uuid"));
|
||||
if (preferredPrintingProviderId.isEmpty()) {
|
||||
CardInfoPtr defaultCardInfo = getCard(cardName);
|
||||
if (defaultCardInfo.isNull()) {
|
||||
return cardName;
|
||||
}
|
||||
return defaultCardInfo->getName();
|
||||
}
|
||||
return preferredPrintingUUID;
|
||||
return preferredPrintingProviderId;
|
||||
}
|
||||
|
||||
bool CardDatabase::isUuidForPreferredPrinting(const QString &cardName, const QString &uuid)
|
||||
bool CardDatabase::isProviderIdForPreferredPrinting(const QString &cardName, const QString &providerId)
|
||||
{
|
||||
return uuid == getPreferredPrintingUUIDForCard(cardName);
|
||||
if (providerId.startsWith("card_")) {
|
||||
return providerId ==
|
||||
QLatin1String("card_") + cardName + QString("_") + getPreferredPrintingProviderIdForCard(cardName);
|
||||
}
|
||||
return providerId == getPreferredPrintingProviderIdForCard(cardName);
|
||||
}
|
||||
|
||||
void CardDatabase::refreshCachedReverseRelatedCards()
|
||||
|
|
|
|||
|
|
@ -414,8 +414,6 @@ protected:
|
|||
private:
|
||||
CardInfoPtr getCardFromMap(const CardNameMap &cardMap, const QString &cardName) const;
|
||||
void checkUnknownSets();
|
||||
CardInfoPerSet getPreferredSetForCard(const QString &cardName);
|
||||
QString getPreferredPrintingUUIDForCard(const QString &cardName);
|
||||
void refreshCachedReverseRelatedCards();
|
||||
|
||||
QBasicMutex *reloadDatabaseMutex = new QBasicMutex(), *clearDatabaseMutex = new QBasicMutex(),
|
||||
|
|
@ -431,7 +429,10 @@ public:
|
|||
void removeCard(CardInfoPtr card);
|
||||
CardInfoPtr getCard(const QString &cardName) const;
|
||||
QList<CardInfoPtr> getCards(const QStringList &cardNames) const;
|
||||
CardInfoPtr getCardByNameAndUUID(const QString &cardName, const QString &uuid) const;
|
||||
CardInfoPtr getCardByNameAndProviderId(const QString &cardName, const QString &providerId) const;
|
||||
CardInfoPerSet getPreferredSetForCard(const QString &cardName);
|
||||
CardInfoPerSet getSpecificSetForCard(const QString &cardName, const QString &providerId) const;
|
||||
QString getPreferredPrintingProviderIdForCard(const QString &cardName);
|
||||
CardInfoPtr guessCard(const QString &cardName) const;
|
||||
|
||||
/*
|
||||
|
|
@ -441,7 +442,7 @@ public:
|
|||
CardInfoPtr getCardBySimpleName(const QString &cardName) const;
|
||||
|
||||
CardSetPtr getSet(const QString &setName);
|
||||
bool isUuidForPreferredPrinting(const QString &cardName, const QString &uuid);
|
||||
bool isProviderIdForPreferredPrinting(const QString &cardName, const QString &providerId);
|
||||
QList<CardInfoPtr> getCardList() const
|
||||
{
|
||||
return cards.values();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#include "card_item.h"
|
||||
|
||||
#include "../../client/tabs/tab_game.h"
|
||||
#include "../../main.h"
|
||||
#include "../../settings/cache_settings.h"
|
||||
#include "../board/arrow_item.h"
|
||||
#include "../game_scene.h"
|
||||
|
|
@ -19,13 +18,14 @@
|
|||
#include <QPainter>
|
||||
|
||||
CardItem::CardItem(Player *_owner,
|
||||
QGraphicsItem *parent,
|
||||
const QString &_name,
|
||||
const QString &_providerId,
|
||||
int _cardid,
|
||||
bool _revealedCard,
|
||||
QGraphicsItem *parent,
|
||||
CardZone *_zone)
|
||||
: AbstractCardItem(_name, _owner, _cardid, parent), zone(_zone), revealedCard(_revealedCard), attacking(false),
|
||||
destroyOnZoneChange(false), doesntUntap(false), dragItem(nullptr), attachedTo(nullptr)
|
||||
: AbstractCardItem(parent, _name, _providerId, _owner, _cardid), zone(_zone), revealedCard(_revealedCard),
|
||||
attacking(false), destroyOnZoneChange(false), doesntUntap(false), dragItem(nullptr), attachedTo(nullptr)
|
||||
{
|
||||
owner->addCard(this);
|
||||
|
||||
|
|
@ -243,6 +243,7 @@ void CardItem::processCardInfo(const ServerInfo_Card &_info)
|
|||
}
|
||||
|
||||
setId(_info.id());
|
||||
setProviderId(QString::fromStdString(_info.provider_id()));
|
||||
setName(QString::fromStdString(_info.name()));
|
||||
setAttacking(_info.attacking());
|
||||
setFaceDown(_info.face_down());
|
||||
|
|
|
|||
|
|
@ -50,10 +50,11 @@ public:
|
|||
return Type;
|
||||
}
|
||||
CardItem(Player *_owner,
|
||||
QGraphicsItem *parent = nullptr,
|
||||
const QString &_name = QString(),
|
||||
const QString &_providerId = QString(),
|
||||
int _cardid = -1,
|
||||
bool revealedCard = false,
|
||||
QGraphicsItem *parent = nullptr,
|
||||
CardZone *_zone = nullptr);
|
||||
~CardItem();
|
||||
void retranslateUi();
|
||||
|
|
|
|||
|
|
@ -2031,7 +2031,7 @@ void Player::eventCreateToken(const Event_CreateToken &event)
|
|||
return;
|
||||
}
|
||||
|
||||
CardItem *card = new CardItem(this, QString::fromStdString(event.card_name()), event.card_id());
|
||||
CardItem *card = new CardItem(this, nullptr, QString::fromStdString(event.card_name()), QString(), event.card_id());
|
||||
// use db PT if not provided in event
|
||||
if (!QString::fromStdString(event.pt()).isEmpty()) {
|
||||
card->setPT(QString::fromStdString(event.pt()));
|
||||
|
|
@ -2168,6 +2168,9 @@ void Player::eventMoveCard(const Event_MoveCard &event, const GameEventContext &
|
|||
if (event.has_card_name()) {
|
||||
card->setName(QString::fromStdString(event.card_name()));
|
||||
}
|
||||
if (event.has_new_card_provider_id()) {
|
||||
card->setProviderId(QString::fromStdString(event.new_card_provider_id()));
|
||||
}
|
||||
|
||||
if (card->getAttachedTo() && (startZone != targetZone)) {
|
||||
CardItem *parentCard = card->getAttachedTo();
|
||||
|
|
@ -2326,6 +2329,7 @@ void Player::eventDrawCards(const Event_DrawCards &event)
|
|||
for (int i = 0; i < listSize; ++i) {
|
||||
const ServerInfo_Card &cardInfo = event.cards(i);
|
||||
CardItem *card = _deck->takeCard(0, cardInfo.id());
|
||||
card->setProviderId(QString::fromStdString(cardInfo.provider_id()));
|
||||
card->setName(QString::fromStdString(cardInfo.name()));
|
||||
_hand->addCard(card, false, -1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,7 +126,8 @@ void CardZone::addCard(CardItem *card, bool reorganize, int x, int y)
|
|||
{
|
||||
for (auto *view : views) {
|
||||
if ((x <= view->getCards().size()) || (view->getNumberCards() == -1)) {
|
||||
view->addCard(new CardItem(player, card->getName(), card->getId()), reorganize, x, y);
|
||||
view->addCard(new CardItem(player, nullptr, card->getName(), card->getProviderId(), card->getId()),
|
||||
reorganize, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,9 +56,9 @@ void ZoneViewZone::initializeCards(const QList<const ServerInfo_Card *> &cardLis
|
|||
{
|
||||
if (!cardList.isEmpty()) {
|
||||
for (int i = 0; i < cardList.size(); ++i)
|
||||
addCard(
|
||||
new CardItem(player, QString::fromStdString(cardList[i]->name()), cardList[i]->id(), revealZone, this),
|
||||
false, i);
|
||||
addCard(new CardItem(player, this, QString::fromStdString(cardList[i]->name()),
|
||||
QString::fromStdString(cardList[i]->provider_id()), cardList[i]->id(), revealZone),
|
||||
false, i);
|
||||
reorganizeCards();
|
||||
} else if (!origZone->contentsKnown()) {
|
||||
Command_DumpZone cmd;
|
||||
|
|
@ -75,7 +75,8 @@ void ZoneViewZone::initializeCards(const QList<const ServerInfo_Card *> &cardLis
|
|||
int number = numberCards == -1 ? c.size() : (numberCards < c.size() ? numberCards : c.size());
|
||||
for (int i = 0; i < number; i++) {
|
||||
CardItem *card = c.at(i);
|
||||
addCard(new CardItem(player, card->getName(), card->getId(), revealZone, this), false, i);
|
||||
addCard(new CardItem(player, this, card->getName(), card->getProviderId(), card->getId(), revealZone),
|
||||
false, i);
|
||||
}
|
||||
reorganizeCards();
|
||||
}
|
||||
|
|
@ -88,7 +89,8 @@ void ZoneViewZone::zoneDumpReceived(const Response &r)
|
|||
for (int i = 0; i < respCardListSize; ++i) {
|
||||
const ServerInfo_Card &cardInfo = resp.zone_info().card_list(i);
|
||||
auto cardName = QString::fromStdString(cardInfo.name());
|
||||
auto *card = new CardItem(player, cardName, cardInfo.id(), revealZone, this, this);
|
||||
auto cardProviderId = QString::fromStdString(cardInfo.provider_id());
|
||||
auto *card = new CardItem(player, this, cardName, cardProviderId, cardInfo.id(), revealZone, this);
|
||||
cards.insert(i, card);
|
||||
}
|
||||
reorganizeCards();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue