Cockatrice 2026-01-14-Development-2.11.0-beta.46
A cross-platform virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
card_info.h
Go to the documentation of this file.
1#ifndef CARD_INFO_H
2#define CARD_INFO_H
3
6
7#include <QDate>
8#include <QHash>
9#include <QList>
10#include <QLoggingCategory>
11#include <QMap>
12#include <QMetaType>
13#include <QSharedPointer>
14#include <QVariant>
15#include <utility>
16
17inline Q_LOGGING_CATEGORY(CardInfoLog, "card_info");
18
19class CardInfo;
20class CardSet;
21class CardRelation;
23
24typedef QSharedPointer<CardInfo> CardInfoPtr;
25typedef QSharedPointer<CardSet> CardSetPtr;
26typedef QSharedPointer<FormatRules> FormatRulesPtr;
27typedef QMap<QString, QList<PrintingInfo>> SetToPrintingsMap;
28
29typedef QHash<QString, CardInfoPtr> CardNameMap;
30typedef QHash<QString, CardSetPtr> SetNameMap;
31typedef QHash<QString, FormatRulesPtr> FormatRulesNameMap;
32
33Q_DECLARE_METATYPE(CardInfoPtr)
34
35
48class CardInfo : public QObject
49{
50 Q_OBJECT
51
52public:
60 {
61 bool cipt = false;
62 bool landscapeOrientation = false;
63 int tableRow = 0;
64 bool upsideDownArt = false;
65 };
66
67private:
73 QString name;
74 QString simpleName;
75 QString text;
76 bool isToken;
77 QVariantHash properties;
78 QList<CardRelation *> relatedCards;
79 QList<CardRelation *> reverseRelatedCards;
80 QList<CardRelation *> reverseRelatedCardsToMe;
83 QString setsNames;
84 QSet<QString> altNames;
86
87public:
100 explicit CardInfo(const QString &_name,
101 const QString &_text,
102 bool _isToken,
103 QVariantHash _properties,
104 const QList<CardRelation *> &_relatedCards,
105 const QList<CardRelation *> &_reverseRelatedCards,
106 SetToPrintingsMap _sets,
107 UiAttributes _uiAttributes);
108
116 CardInfo(const CardInfo &other)
117 : QObject(other.parent()), name(other.name), simpleName(other.simpleName), text(other.text),
121 altNames(other.altNames)
122 {
123 }
124
133 static CardInfoPtr newInstance(const QString &_name);
134
148 static CardInfoPtr newInstance(const QString &_name,
149 const QString &_text,
150 bool _isToken,
151 QVariantHash _properties,
152 const QList<CardRelation *> &_relatedCards,
153 const QList<CardRelation *> &_reverseRelatedCards,
154 SetToPrintingsMap _sets,
155 UiAttributes _uiAttributes);
156
164 [[nodiscard]] CardInfoPtr clone() const
165 {
166 auto newCardInfo = CardInfoPtr(new CardInfo(*this));
167 newCardInfo->setSmartPointer(newCardInfo); // Set the smart pointer for the new instance
168 return newCardInfo;
169 }
170
179 {
180 smartThis = std::move(_ptr);
181 }
182 //@{
184 [[nodiscard]] inline const QString &getName() const
185 {
186 return name;
187 }
188 [[nodiscard]] const QString &getSimpleName() const
189 {
190 return simpleName;
191 }
192 const QSet<QString> &getAltNames()
193 {
194 return altNames;
195 }
196 [[nodiscard]] const QString &getText() const
197 {
198 return text;
199 }
200 void setText(const QString &_text)
201 {
202 text = _text;
204 }
205 [[nodiscard]] bool getIsToken() const
206 {
207 return isToken;
208 }
209 [[nodiscard]] QStringList getProperties() const
210 {
211 return properties.keys();
212 }
213 [[nodiscard]] QString getProperty(const QString &propertyName) const
214 {
215 return properties.value(propertyName).toString();
216 }
217 void setProperty(const QString &_name, const QString &_value)
218 {
219 properties.insert(_name, _value);
221 }
222 [[nodiscard]] bool hasProperty(const QString &propertyName) const
223 {
224 return properties.contains(propertyName);
225 }
226 [[nodiscard]] const SetToPrintingsMap &getSets() const
227 {
228 return setsToPrintings;
229 }
230 [[nodiscard]] const QString &getSetsNames() const
231 {
232 return setsNames;
233 }
234
235 //@{
237 [[nodiscard]] const QList<CardRelation *> &getRelatedCards() const
238 {
239 return relatedCards;
240 }
241 [[nodiscard]] const QList<CardRelation *> &getReverseRelatedCards() const
242 {
243 return reverseRelatedCards;
244 }
245 [[nodiscard]] const QList<CardRelation *> &getReverseRelatedCards2Me() const
246 {
248 }
249 [[nodiscard]] QList<CardRelation *> getAllRelatedCards() const
250 {
251 QList<CardRelation *> result;
252 result.append(getRelatedCards());
253 result.append(getReverseRelatedCards2Me());
254 return result;
255 }
256 void resetReverseRelatedCards2Me();
258 {
259 reverseRelatedCardsToMe.append(cardRelation);
260 }
261
262 //@{
264 [[nodiscard]] const UiAttributes &getUiAttributes() const
265 {
266 return uiAttributes;
267 }
268
269
270 [[nodiscard]] QChar getColorChar() const;
271 //@{
273 [[nodiscard]] QString getCardType() const;
274 void setCardType(const QString &value);
275 [[nodiscard]] QString getCmc() const;
276 [[nodiscard]] QString getColors() const;
277 void setColors(const QString &value);
278 [[nodiscard]] QString getLoyalty() const;
279 [[nodiscard]] QString getMainCardType() const;
280 [[nodiscard]] QString getManaCost() const;
281 [[nodiscard]] QString getPowTough() const;
282 void setPowTough(const QString &value);
284
292 [[nodiscard]] QString getCorrectedName() const;
293
301 [[nodiscard]] bool isLegalInFormat(const QString &format) const;
302
311 void addToSet(const CardSetPtr &_set, const PrintingInfo &_info = PrintingInfo());
312
320 void combineLegalities(const QVariantHash &props);
321
327 void refreshCachedSets();
328
337 static QString simplifyName(const QString &name);
338
339private:
345 void refreshCachedSetNames();
346
352 void refreshCachedAltNames();
353
354signals:
360 void pixmapUpdated(const PrintingInfo &printing);
361
368};
369#endif
QSharedPointer< CardInfo > CardInfoPtr
Definition card_info.cpp:20
QMap< QString, QList< PrintingInfo > > SetToPrintingsMap
Definition card_info.h:27
QHash< QString, FormatRulesPtr > FormatRulesNameMap
Definition card_info.h:31
QSharedPointer< FormatRules > FormatRulesPtr
Definition card_info.h:26
QSharedPointer< CardSet > CardSetPtr
Definition card_info.h:25
QHash< QString, CardSetPtr > SetNameMap
Definition card_info.h:30
QSharedPointer< CardInfo > CardInfoPtr
Definition card_info.h:24
Q_LOGGING_CATEGORY(CardInfoLog, "card_info")
QHash< QString, CardInfoPtr > CardNameMap
Definition card_info.h:29
Represents a card and its associated metadata, properties, and relationships.
Definition card_info.h:49
bool hasProperty(const QString &propertyName) const
Definition card_info.h:222
QString simpleName
Simplified name for fuzzy matching.
Definition card_info.h:74
void setSmartPointer(CardInfoPtr _ptr)
Sets the internal smart pointer to self.
Definition card_info.h:178
const SetToPrintingsMap & getSets() const
Definition card_info.h:226
void setText(const QString &_text)
Definition card_info.h:200
UiAttributes uiAttributes
Attributes that affect display and game logic.
Definition card_info.h:82
const QList< CardRelation * > & getReverseRelatedCards() const
Definition card_info.h:241
const QString & getSimpleName() const
Definition card_info.h:188
const QList< CardRelation * > & getRelatedCards() const
Definition card_info.h:237
QList< CardRelation * > reverseRelatedCards
Cards that refer back to this card.
Definition card_info.h:79
const UiAttributes & getUiAttributes() const
Definition card_info.h:264
CardInfoPtr smartThis
Smart pointer to self for safe cross-references.
Definition card_info.h:72
const QList< CardRelation * > & getReverseRelatedCards2Me() const
Definition card_info.h:245
QSet< QString > altNames
Cached set of alternate names, used when searching.
Definition card_info.h:84
const QString & getSetsNames() const
Definition card_info.h:230
QString name
Full name of the card.
Definition card_info.h:73
QList< CardRelation * > relatedCards
Forward references to related cards.
Definition card_info.h:78
SetToPrintingsMap setsToPrintings
Mapping from set names to printing variations.
Definition card_info.h:81
void setProperty(const QString &_name, const QString &_value)
Definition card_info.h:217
QVariantHash properties
Key-value store of dynamic card properties.
Definition card_info.h:77
CardInfo(const QString &_name, const QString &_text, bool _isToken, QVariantHash _properties, const QList< CardRelation * > &_relatedCards, const QList< CardRelation * > &_reverseRelatedCards, SetToPrintingsMap _sets, UiAttributes _uiAttributes)
Constructs a CardInfo with full initialization.
Definition card_info.cpp:22
const QSet< QString > & getAltNames()
Definition card_info.h:192
QString getProperty(const QString &propertyName) const
Definition card_info.h:213
CardInfo(const CardInfo &other)
Copy constructor for CardInfo.
Definition card_info.h:116
QList< CardRelation * > reverseRelatedCardsToMe
Cards that consider this card as related.
Definition card_info.h:80
void addReverseRelatedCards2Me(CardRelation *cardRelation)
Definition card_info.h:257
CardInfoPtr clone() const
Clones the current CardInfo instance.
Definition card_info.h:164
void cardInfoChanged(CardInfoPtr card)
Emitted when card properties or state have changed.
const QString & getText() const
Definition card_info.h:196
QString setsNames
Cached, human-readable list of set names.
Definition card_info.h:83
bool getIsToken() const
Definition card_info.h:205
void pixmapUpdated(const PrintingInfo &printing)
Emitted when a pixmap for this card has been updated or finished loading.
QList< CardRelation * > getAllRelatedCards() const
Definition card_info.h:249
bool isToken
Whether this card is a token or not.
Definition card_info.h:76
QStringList getProperties() const
Definition card_info.h:209
QString text
Text description or rules text of the card.
Definition card_info.h:75
const QString & getName() const
Definition card_info.h:184
Represents a relationship between two cards.
Definition card_relation.h:24
A collection of cards grouped under a common identifier.
Definition card_set.h:35
Defines the base parser interface (ICardDatabaseParser) for all card database parsers.
Definition card_database_parser.h:20
Represents metadata for a specific variation of a card within a set.
Definition printing_info.h:27
static QString getMainCardType(const QStringList &typeList)
Definition oracleimporter.cpp:96
Attributes of the card that affect display and game logic.
Definition card_info.h:60
int tableRow
Row index in a table or visual representation.
Definition card_info.h:63
bool landscapeOrientation
Orientation flag for rendering.
Definition card_info.h:62
bool cipt
Positioning flag used by UI.
Definition card_info.h:61
bool upsideDownArt
Whether artwork is flipped for visual purposes.
Definition card_info.h:64