mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2025-12-24 20:10:02 -08:00
* 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>
229 lines
5.8 KiB
C++
229 lines
5.8 KiB
C++
/***************************************************************************
|
|
* Copyright (C) 2008 by Max-Wilhelm Bruker *
|
|
* brukie@laptop *
|
|
* *
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
* This program is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
* GNU General Public License for more details. *
|
|
* *
|
|
* You should have received a copy of the GNU General Public License *
|
|
* along with this program; if not, write to the *
|
|
* Free Software Foundation, Inc., *
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
***************************************************************************/
|
|
#ifndef SERVER_CARD_H
|
|
#define SERVER_CARD_H
|
|
|
|
#include "pb/card_attributes.pb.h"
|
|
#include "pb/serverinfo_card.pb.h"
|
|
#include "server_arrowtarget.h"
|
|
|
|
#include <QMap>
|
|
#include <QString>
|
|
|
|
class Server_CardZone;
|
|
class Event_SetCardCounter;
|
|
class Event_SetCardAttr;
|
|
|
|
class Server_Card : public Server_ArrowTarget
|
|
{
|
|
Q_OBJECT
|
|
private:
|
|
Server_CardZone *zone;
|
|
int id;
|
|
int coord_x, coord_y;
|
|
QString name;
|
|
QString provider_id;
|
|
QMap<int, int> counters;
|
|
bool tapped;
|
|
bool attacking;
|
|
bool facedown;
|
|
QString color;
|
|
QString ptString;
|
|
QString annotation;
|
|
bool destroyOnZoneChange;
|
|
bool doesntUntap;
|
|
|
|
Server_Card *parentCard;
|
|
QList<Server_Card *> attachedCards;
|
|
Server_Card *stashedCard;
|
|
|
|
public:
|
|
Server_Card(QString _name,
|
|
QString _provider_id,
|
|
int _id,
|
|
int _coord_x,
|
|
int _coord_y,
|
|
Server_CardZone *_zone = nullptr);
|
|
~Server_Card() override;
|
|
|
|
Server_CardZone *getZone() const
|
|
{
|
|
return zone;
|
|
}
|
|
void setZone(Server_CardZone *_zone)
|
|
{
|
|
zone = _zone;
|
|
}
|
|
|
|
int getId() const
|
|
{
|
|
return id;
|
|
}
|
|
QString getProviderId() const
|
|
{
|
|
return provider_id;
|
|
}
|
|
int getX() const
|
|
{
|
|
return coord_x;
|
|
}
|
|
int getY() const
|
|
{
|
|
return coord_y;
|
|
}
|
|
QString getName() const
|
|
{
|
|
return name;
|
|
}
|
|
const QMap<int, int> &getCounters() const
|
|
{
|
|
return counters;
|
|
}
|
|
int getCounter(int counter_id) const
|
|
{
|
|
return counters.value(counter_id, 0);
|
|
}
|
|
bool getTapped() const
|
|
{
|
|
return tapped;
|
|
}
|
|
bool getAttacking() const
|
|
{
|
|
return attacking;
|
|
}
|
|
bool getFaceDown() const
|
|
{
|
|
return facedown;
|
|
}
|
|
QString getColor() const
|
|
{
|
|
return color;
|
|
}
|
|
QString getPT() const
|
|
{
|
|
return ptString;
|
|
}
|
|
QString getAnnotation() const
|
|
{
|
|
return annotation;
|
|
}
|
|
bool getDoesntUntap() const
|
|
{
|
|
return doesntUntap;
|
|
}
|
|
bool getDestroyOnZoneChange() const
|
|
{
|
|
return destroyOnZoneChange;
|
|
}
|
|
Server_Card *getParentCard() const
|
|
{
|
|
return parentCard;
|
|
}
|
|
const QList<Server_Card *> &getAttachedCards() const
|
|
{
|
|
return attachedCards;
|
|
}
|
|
|
|
void setId(int _id)
|
|
{
|
|
id = _id;
|
|
}
|
|
void setCoords(int x, int y)
|
|
{
|
|
coord_x = x;
|
|
coord_y = y;
|
|
}
|
|
void setName(const QString &_name)
|
|
{
|
|
name = _name;
|
|
}
|
|
void setCounter(int _id, int value, Event_SetCardCounter *event = nullptr);
|
|
void setTapped(bool _tapped)
|
|
{
|
|
tapped = _tapped;
|
|
}
|
|
void setAttacking(bool _attacking)
|
|
{
|
|
attacking = _attacking;
|
|
}
|
|
void setFaceDown(bool _facedown)
|
|
{
|
|
facedown = _facedown;
|
|
}
|
|
void setColor(const QString &_color)
|
|
{
|
|
color = _color;
|
|
}
|
|
void setPT(const QString &_pt)
|
|
{
|
|
ptString = _pt;
|
|
}
|
|
void setAnnotation(const QString &_annotation)
|
|
{
|
|
annotation = _annotation;
|
|
}
|
|
void setDestroyOnZoneChange(bool _destroy)
|
|
{
|
|
destroyOnZoneChange = _destroy;
|
|
}
|
|
void setDoesntUntap(bool _doesntUntap)
|
|
{
|
|
doesntUntap = _doesntUntap;
|
|
}
|
|
void setParentCard(Server_Card *_parentCard);
|
|
void addAttachedCard(Server_Card *card)
|
|
{
|
|
attachedCards.append(card);
|
|
}
|
|
void removeAttachedCard(Server_Card *card)
|
|
{
|
|
attachedCards.removeOne(card);
|
|
}
|
|
void setStashedCard(Server_Card *card)
|
|
{
|
|
// setStashedCard should only be called on creation of a new card, so
|
|
// there should never be an already existing stashed card.
|
|
Q_ASSERT(!stashedCard);
|
|
|
|
// Stashed cards can't themselves have stashed cards, and tokens can't
|
|
// be stashed.
|
|
if (card->stashedCard || card->getDestroyOnZoneChange()) {
|
|
stashedCard = card->takeStashedCard();
|
|
card->deleteLater();
|
|
} else {
|
|
stashedCard = card;
|
|
}
|
|
}
|
|
Server_Card *takeStashedCard()
|
|
{
|
|
Server_Card *oldStashedCard = stashedCard;
|
|
stashedCard = nullptr;
|
|
return oldStashedCard;
|
|
}
|
|
|
|
void resetState();
|
|
QString setAttribute(CardAttribute attribute, const QString &avalue, bool allCards);
|
|
QString setAttribute(CardAttribute attribute, const QString &avalue, Event_SetCardAttr *event = nullptr);
|
|
|
|
void getInfo(ServerInfo_Card *info);
|
|
};
|
|
|
|
#endif
|