Cockatrice 2026-09-01-Development-3.1.0-beta.10
A 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
7
8#include <QDate>
9#include <QHash>
10#include <QList>
11#include <QLoggingCategory>
12#include <QMap>
13#include <QMetaType>
14#include <QMutex>
15#include <QSharedPointer>
16#include <QVariant>
17#include <utility>
18
19inline Q_LOGGING_CATEGORY(CardInfoLog, "card_info");
20
21class CardInfo;
22class CardSet;
23class CardRelation;
25
26typedef QSharedPointer<CardInfo> CardInfoPtr;
27typedef QSharedPointer<CardSet> CardSetPtr;
28typedef QSharedPointer<FormatRules> FormatRulesPtr;
29typedef QMap<QString, QList<PrintingInfo>> SetToPrintingsMap;
30
31typedef QHash<QString, CardInfoPtr> CardNameMap;
32typedef QHash<QString, CardSetPtr> SetNameMap;
33typedef QHash<QString, FormatRulesPtr> FormatRulesNameMap;
34
35Q_DECLARE_METATYPE(CardInfoPtr)
36
37
50class CardInfo : public QObject
51{
52 Q_OBJECT
53
54public:
62 {
63 bool cipt = false;
64 bool landscapeOrientation = false;
65 int tableRow = 0;
66 bool upsideDownArt = false;
67 };
68
69private:
75 QString name;
76 QString simpleName;
77 QString text;
78 bool isToken;
79
81
82 QList<CardRelation *> relatedCards;
83 QList<CardRelation *> reverseRelatedCards;
84 QList<CardRelation *> reverseRelatedCardsToMe;
87 QString setsNames;
88 QSet<QString> altNames;
90
91public:
104 explicit CardInfo(const QString &_name,
105 const QString &_text,
106 bool _isToken,
107 const QHash<QString, QString> &_properties,
108 const QList<CardRelation *> &_relatedCards,
109 const QList<CardRelation *> &_reverseRelatedCards,
110 SetToPrintingsMap _sets,
111 UiAttributes _uiAttributes);
112
134 explicit CardInfo(const QString &_name,
135 const QString &_text,
136 bool _isToken,
137 const QByteArray &_propertiesBlob,
138 const QList<CardRelation *> &_relatedCards,
139 const QList<CardRelation *> &_reverseRelatedCards,
140 SetToPrintingsMap _sets,
141 UiAttributes _uiAttributes,
142 QString _simpleName,
143 QSet<QString> _altNames);
144
152 CardInfo(const CardInfo &other)
153 : QObject(other.parent()), name(other.name), simpleName(other.simpleName), text(other.text),
157 altNames(other.altNames)
158 {
159 }
160
169 static CardInfoPtr newInstance(const QString &_name);
170
184 static CardInfoPtr newInstance(const QString &_name,
185 const QString &_text,
186 bool _isToken,
187 const QHash<QString, QString> &_properties,
188 const QList<CardRelation *> &_relatedCards,
189 const QList<CardRelation *> &_reverseRelatedCards,
190 SetToPrintingsMap _sets,
191 UiAttributes _uiAttributes);
192
213 static CardInfoPtr newInstance(const QString &_name,
214 const QString &_text,
215 bool _isToken,
216 QByteArray _propertiesBlob,
217 const QList<CardRelation *> &_relatedCards,
218 const QList<CardRelation *> &_reverseRelatedCards,
219 SetToPrintingsMap _sets,
220 UiAttributes _uiAttributes,
221 QString _simpleName,
222 QSet<QString> _altNames,
223 bool _appendToSets = true);
224
232 [[nodiscard]] CardInfoPtr clone() const
233 {
234 auto newCardInfo = CardInfoPtr(new CardInfo(*this));
235 newCardInfo->setSmartPointer(newCardInfo); // Set the smart pointer for the new instance
236 return newCardInfo;
237 }
238
247 {
248 smartThis = std::move(_ptr);
249 }
250 //@{
252 [[nodiscard]] inline const QString &getName() const
253 {
254 return name;
255 }
256 [[nodiscard]] const QString &getSimpleName() const
257 {
258 return simpleName;
259 }
260 const QSet<QString> &getAltNames()
261 {
262 return altNames;
263 }
264 [[nodiscard]] const QString &getText() const
265 {
266 return text;
267 }
268 void setText(const QString &_text)
269 {
270 text = _text;
272 }
273 [[nodiscard]] bool getIsToken() const
274 {
275 return isToken;
276 }
277 [[nodiscard]] QStringList getProperties() const
278 {
279 return getPropertiesHash().keys();
280 }
281 [[nodiscard]] const QHash<QString, QString> &getPropertiesHash() const;
282
283 [[nodiscard]] QString getProperty(const QString &propertyName) const
284 {
285 return getPropertiesHash().value(propertyName);
286 }
287 void setProperty(const QString &_name, const QString &_value);
288 [[nodiscard]] bool hasProperty(const QString &propertyName) const
289 {
290 return getPropertiesHash().contains(propertyName);
291 }
292 [[nodiscard]] const SetToPrintingsMap &getSets() const
293 {
294 return setsToPrintings;
295 }
296 [[nodiscard]] const QString &getSetsNames() const
297 {
298 return setsNames;
299 }
300
301 //@{
303 [[nodiscard]] const QList<CardRelation *> &getRelatedCards() const
304 {
305 return relatedCards;
306 }
307 [[nodiscard]] const QList<CardRelation *> &getReverseRelatedCards() const
308 {
309 return reverseRelatedCards;
310 }
311 [[nodiscard]] const QList<CardRelation *> &getReverseRelatedCards2Me() const
312 {
314 }
315 [[nodiscard]] QList<CardRelation *> getAllRelatedCards() const
316 {
317 QList<CardRelation *> result;
318 result.append(getRelatedCards());
319 result.append(getReverseRelatedCards2Me());
320 return result;
321 }
322 void resetReverseRelatedCards2Me();
324 {
325 reverseRelatedCardsToMe.append(cardRelation);
326 }
327
328 //@{
330 [[nodiscard]] const UiAttributes &getUiAttributes() const
331 {
332 return uiAttributes;
333 }
334
335
336 [[nodiscard]] QChar getColorChar() const;
337 //@{
339 [[nodiscard]] QString getCardType() const;
340 void setCardType(const QString &value);
341 [[nodiscard]] QString getCmc() const;
342 [[nodiscard]] QString getColors() const;
343 void setColors(const QString &value);
344 [[nodiscard]] QString getLoyalty() const;
345 [[nodiscard]] QString getMainCardType() const;
346 [[nodiscard]] QString getManaCost() const;
347 [[nodiscard]] QString getPowTough() const;
348 void setPowTough(const QString &value);
350
358 [[nodiscard]] QString getCorrectedName() const;
359
366 [[nodiscard]] QString getLegalityProp(const QString &format) const;
367
375 [[nodiscard]] bool isLegalInFormat(const QString &format) const;
376
385 void addToSet(const CardSetPtr &_set, const PrintingInfo &_info = PrintingInfo());
386
394 void combineLegalities(const QHash<QString, QString> &props);
395
401 void refreshCachedSets();
402
411 static QString simplifyName(const QString &name);
412
413private:
419 void refreshCachedSetNames();
420
426 void refreshCachedAltNames();
427
428signals:
434 void pixmapUpdated(const PrintingInfo &printing);
435
442};
443#endif
QSharedPointer< CardInfo > CardInfoPtr
Definition card_info.cpp:19
QMap< QString, QList< PrintingInfo > > SetToPrintingsMap
Definition card_info.h:29
QHash< QString, FormatRulesPtr > FormatRulesNameMap
Definition card_info.h:33
QSharedPointer< FormatRules > FormatRulesPtr
Definition card_info.h:28
QSharedPointer< CardSet > CardSetPtr
Definition card_info.h:27
QHash< QString, CardSetPtr > SetNameMap
Definition card_info.h:32
QSharedPointer< CardInfo > CardInfoPtr
Definition card_info.h:26
Q_LOGGING_CATEGORY(CardInfoLog, "card_info")
QHash< QString, CardInfoPtr > CardNameMap
Definition card_info.h:31
Represents a card and its associated metadata, properties, and relationships.
Definition card_info.h:51
bool hasProperty(const QString &propertyName) const
Definition card_info.h:288
QString simpleName
Simplified name for fuzzy matching.
Definition card_info.h:76
void setSmartPointer(CardInfoPtr _ptr)
Sets the internal smart pointer to self.
Definition card_info.h:246
const SetToPrintingsMap & getSets() const
Definition card_info.h:292
void setText(const QString &_text)
Definition card_info.h:268
CardInfo(const QString &_name, const QString &_text, bool _isToken, const QHash< QString, QString > &_properties, const QList< CardRelation * > &_relatedCards, const QList< CardRelation * > &_reverseRelatedCards, SetToPrintingsMap _sets, UiAttributes _uiAttributes)
Constructs a CardInfo with full initialization.
Definition card_info.cpp:36
UiAttributes uiAttributes
Attributes that affect display and game logic.
Definition card_info.h:86
const QList< CardRelation * > & getReverseRelatedCards() const
Definition card_info.h:307
const QString & getSimpleName() const
Definition card_info.h:256
const QList< CardRelation * > & getRelatedCards() const
Definition card_info.h:303
QList< CardRelation * > reverseRelatedCards
Cards that refer back to this card.
Definition card_info.h:83
const UiAttributes & getUiAttributes() const
Definition card_info.h:330
CardInfoPtr smartThis
Smart pointer to self for safe cross-references.
Definition card_info.h:74
const QList< CardRelation * > & getReverseRelatedCards2Me() const
Definition card_info.h:311
QSet< QString > altNames
Cached set of alternate names, used when searching.
Definition card_info.h:88
const QString & getSetsNames() const
Definition card_info.h:296
QString name
Full name of the card.
Definition card_info.h:75
QList< CardRelation * > relatedCards
Forward references to related cards.
Definition card_info.h:82
SetToPrintingsMap setsToPrintings
Mapping from set names to printing variations.
Definition card_info.h:85
const QSet< QString > & getAltNames()
Definition card_info.h:260
QString getProperty(const QString &propertyName) const
Definition card_info.h:283
CardInfo(const CardInfo &other)
Copy constructor for CardInfo.
Definition card_info.h:152
LazyPropertiesHash properties
Key-value store of dynamic card properties.
Definition card_info.h:80
QList< CardRelation * > reverseRelatedCardsToMe
Cards that consider this card as related.
Definition card_info.h:84
void addReverseRelatedCards2Me(CardRelation *cardRelation)
Definition card_info.h:323
CardInfoPtr clone() const
Clones the current CardInfo instance.
Definition card_info.h:232
void cardInfoChanged(CardInfoPtr card)
Emitted when card properties or state have changed.
const QString & getText() const
Definition card_info.h:264
QString setsNames
Cached, human-readable list of set names.
Definition card_info.h:87
bool getIsToken() const
Definition card_info.h:273
const QHash< QString, QString > & getPropertiesHash() const
Definition card_info.cpp:21
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:315
bool isToken
Whether this card is a token or not.
Definition card_info.h:78
QStringList getProperties() const
Definition card_info.h:277
QString text
Text description or rules text of the card.
Definition card_info.h:77
const QString & getName() const
Definition card_info.h:252
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:21
A property map that can lazily deserialize blobs to avoid loading overhead.
Definition lazy_properties_hash.h:17
Represents metadata for a specific variation of a card within a set.
Definition printing_info.h:28
static QString getMainCardType(const QStringList &typeList)
Definition oracleimporter.cpp:95
Attributes of the card that affect display and game logic.
Definition card_info.h:62
int tableRow
Row index in a table or visual representation.
Definition card_info.h:65
bool landscapeOrientation
Orientation flag for rendering.
Definition card_info.h:64
bool cipt
Positioning flag used by UI.
Definition card_info.h:63
bool upsideDownArt
Whether artwork is flipped for visual purposes.
Definition card_info.h:66