Cockatrice 2026-09-01-Development-3.1.0-beta.10
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
CardInfo Class Reference

Represents a card and its associated metadata, properties, and relationships. More...

#include <card_info.h>

Inheritance diagram for CardInfo:
[legend]
Collaboration diagram for CardInfo:
[legend]

Classes

class  UiAttributes
 Attributes of the card that affect display and game logic. More...

Public Member Functions

 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.
 CardInfo (const QString &_name, const QString &_text, bool _isToken, const QByteArray &_propertiesBlob, const QList< CardRelation * > &_relatedCards, const QList< CardRelation * > &_reverseRelatedCards, SetToPrintingsMap _sets, UiAttributes _uiAttributes, QString _simpleName, QSet< QString > _altNames)
 Constructs a CardInfo from a cache snapshot with precomputed derived state.
 CardInfo (const CardInfo &other)
 Copy constructor for CardInfo.
CardInfoPtr clone () const
 Clones the current CardInfo instance.
void setSmartPointer (CardInfoPtr _ptr)
 Sets the internal smart pointer to self.
Basic Properties Accessors
const QString & getName () const
const QString & getSimpleName () const
const QSet< QString > & getAltNames ()
const QString & getText () const
void setText (const QString &_text)
bool getIsToken () const
QStringList getProperties () const
const QHash< QString, QString > & getPropertiesHash () const
QString getProperty (const QString &propertyName) const
void setProperty (const QString &_name, const QString &_value)
bool hasProperty (const QString &propertyName) const
const SetToPrintingsMapgetSets () const
const QString & getSetsNames () const
Related Cards Accessors
const QList< CardRelation * > & getRelatedCards () const
const QList< CardRelation * > & getReverseRelatedCards () const
const QList< CardRelation * > & getReverseRelatedCards2Me () const
QList< CardRelation * > getAllRelatedCards () const
void resetReverseRelatedCards2Me ()
void addReverseRelatedCards2Me (CardRelation *cardRelation)
UI Positioning
const UiAttributesgetUiAttributes () const
QChar getColorChar () const

Static Public Member Functions

static CardInfoPtr newInstance (const QString &_name)
 Creates a new instance with only the card name.
static CardInfoPtr newInstance (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)
 Creates a new instance with full initialization.
static CardInfoPtr newInstance (const QString &_name, const QString &_text, bool _isToken, QByteArray _propertiesBlob, const QList< CardRelation * > &_relatedCards, const QList< CardRelation * > &_reverseRelatedCards, SetToPrintingsMap _sets, UiAttributes _uiAttributes, QString _simpleName, QSet< QString > _altNames, bool _appendToSets=true)
 Creates a new instance from a cache snapshot with precomputed derived state.

Private Attributes

Private Card Properties

CardInfoPtr smartThis
 Smart pointer to self for safe cross-references.
QString name
 Full name of the card.
QString simpleName
 Simplified name for fuzzy matching.
QString text
 Text description or rules text of the card.
bool isToken
 Whether this card is a token or not.
LazyPropertiesHash properties
 Key-value store of dynamic card properties.
QList< CardRelation * > relatedCards
 Forward references to related cards.
QList< CardRelation * > reverseRelatedCards
 Cards that refer back to this card.
QList< CardRelation * > reverseRelatedCardsToMe
 Cards that consider this card as related.
SetToPrintingsMap setsToPrintings
 Mapping from set names to printing variations.
UiAttributes uiAttributes
 Attributes that affect display and game logic.
QString setsNames
 Cached, human-readable list of set names.
QSet< QString > altNames
 Cached set of alternate names, used when searching.

Legacy/Convenience Property Accessors

QString getCardType () const
void setCardType (const QString &value)
QString getCmc () const
QString getColors () const
void setColors (const QString &value)
QString getLoyalty () const
QString getMainCardType () const
QString getManaCost () const
QString getPowTough () const
void setPowTough (const QString &value)
QString getCorrectedName () const
 Returns a version of the card name safe for file storage or fuzzy matching.
QString getLegalityProp (const QString &format) const
 Gets the card's legality value for the given format. The legality prop for a format is stored in the property map under the key "format-<name>".
bool isLegalInFormat (const QString &format) const
 Checks if the card is legal in the given format. A card is considered legal in a format if its properties map contains an entry for "format-<name>", with value "legal" or "restricted".
void addToSet (const CardSetPtr &_set, const PrintingInfo &_info=PrintingInfo())
 Adds a printing to a specific set.
void combineLegalities (const QHash< QString, QString > &props)
 Combines legality properties from a provided map.
void refreshCachedSets ()
 Refreshes all cached fields that are calculated from the contained sets and printings.
static QString simplifyName (const QString &name)
 Simplifies a name for fuzzy matching.
void refreshCachedSetNames ()
 Refreshes the cached, human-readable list of set names.
void refreshCachedAltNames ()
 Refreshes the cached list of alt names for the card.
void pixmapUpdated (const PrintingInfo &printing)
 Emitted when a pixmap for this card has been updated or finished loading.
void cardInfoChanged (CardInfoPtr card)
 Emitted when card properties or state have changed.

Detailed Description

Represents a card and its associated metadata, properties, and relationships.

CardInfo holds both static information (name, text, flags) and dynamic data (properties, set memberships, relationships). It also integrates with signals/slots, allowing observers to react to property or visual updates.

Each CardInfo may belong to multiple sets through its printings, and can be related to other cards through defined relationships.

Constructor & Destructor Documentation

◆ CardInfo() [1/3]

CardInfo::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 )
explicit

Constructs a CardInfo with full initialization.

Parameters
_nameThe name of the card.
_textRules text or description of the card.
_isTokenFlag indicating whether the card is a token.
_propertiesArbitrary key-value properties.
_relatedCardsForward references to related cards.
_reverseRelatedCardsBackward references to related cards.
_setsMap of set names to printing information.
_uiAttributesAttributes that affect display and game logic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CardInfo() [2/3]

CardInfo::CardInfo ( const QString & _name,
const QString & _text,
bool _isToken,
const QByteArray & _propertiesBlob,
const QList< CardRelation * > & _relatedCards,
const QList< CardRelation * > & _reverseRelatedCards,
SetToPrintingsMap _sets,
UiAttributes _uiAttributes,
QString _simpleName,
QSet< QString > _altNames )
explicit

Constructs a CardInfo from a cache snapshot with precomputed derived state.

Used by the binary cache reader to skip recomputing _simpleName and _altNames (which otherwise require a Unicode normalization and a full printing scan). Properties are supplied as a pre-serialized _propertiesBlob so the QHash<QString, QString> is not built at load time (it is materialized on first query).

Parameters
_nameThe card name.
_textRules text or description of the card.
_isTokenToken flag.
_propertiesBlobPre-serialized properties blob (as written by the cache).
_relatedCardsForward relationships.
_reverseRelatedCardsReverse relationships.
_setsPrinting information per set.
_uiAttributesAttributes that affect display and game logic.
_simpleNamePrecomputed simplified name.
_altNamesPrecomputed alternate names.
Here is the call graph for this function:

◆ CardInfo() [3/3]

CardInfo::CardInfo ( const CardInfo & other)
inline

Copy constructor for CardInfo.

Performs a deep copy of properties, sets, and related card lists.

Parameters
otherAnother CardInfo to copy.
Here is the call graph for this function:

Member Function Documentation

◆ addReverseRelatedCards2Me()

void CardInfo::addReverseRelatedCards2Me ( CardRelation * cardRelation)
inline

◆ addToSet()

void CardInfo::addToSet ( const CardSetPtr & _set,
const PrintingInfo & _info = PrintingInfo() )

Adds a printing to a specific set.

Updates the mapping and refreshes the cached list of set names.

Parameters
_setThe set to which the card should be added.
_infoOptional printing information.
Here is the call graph for this function:

◆ cardInfoChanged

void CardInfo::cardInfoChanged ( CardInfoPtr card)
signal

Emitted when card properties or state have changed.

Parameters
cardShared pointer to the CardInfo instance that changed.
Here is the caller graph for this function:

◆ clone()

CardInfoPtr CardInfo::clone ( ) const
inlinenodiscard

Clones the current CardInfo instance.

Uses the copy constructor and ensures the smart pointer is properly set.

Returns
Shared pointer to the cloned CardInfo.
Here is the call graph for this function:

◆ combineLegalities()

void CardInfo::combineLegalities ( const QHash< QString, QString > & props)

Combines legality properties from a provided map.

Useful for merging format legality flags from multiple sources.

Parameters
propsKey-value mapping of format legalities.
Here is the call graph for this function:

◆ getAllRelatedCards()

QList< CardRelation * > CardInfo::getAllRelatedCards ( ) const
inlinenodiscard
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAltNames()

const QSet< QString > & CardInfo::getAltNames ( )
inline

◆ getCardType()

QString CardInfo::getCardType ( ) const
nodiscard
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCmc()

QString CardInfo::getCmc ( ) const
nodiscard
Here is the call graph for this function:

◆ getColorChar()

QChar CardInfo::getColorChar ( ) const
nodiscard
Here is the call graph for this function:

◆ getColors()

QString CardInfo::getColors ( ) const
nodiscard
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCorrectedName()

QString CardInfo::getCorrectedName ( ) const
nodiscard

Returns a version of the card name safe for file storage or fuzzy matching.

Removes invalid characters, replaces spacing markers, and normalizes diacritics.

Returns
Corrected card name as a QString.
Here is the caller graph for this function:

◆ getIsToken()

bool CardInfo::getIsToken ( ) const
inlinenodiscard
Here is the caller graph for this function:

◆ getLegalityProp()

QString CardInfo::getLegalityProp ( const QString & format) const
nodiscard

Gets the card's legality value for the given format. The legality prop for a format is stored in the property map under the key "format-<name>".

Parameters
formatThe format's name.
Returns
The card's legality value for the format. Empty if not found.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getLoyalty()

QString CardInfo::getLoyalty ( ) const
nodiscard
Here is the call graph for this function:

◆ getMainCardType()

QString CardInfo::getMainCardType ( ) const
nodiscard
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getManaCost()

QString CardInfo::getManaCost ( ) const
nodiscard
Here is the call graph for this function:

◆ getName()

const QString & CardInfo::getName ( ) const
inlinenodiscard
Here is the caller graph for this function:

◆ getPowTough()

QString CardInfo::getPowTough ( ) const
nodiscard
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getProperties()

QStringList CardInfo::getProperties ( ) const
inlinenodiscard
Here is the call graph for this function:

◆ getPropertiesHash()

const QHash< QString, QString > & CardInfo::getPropertiesHash ( ) const
nodiscard
Here is the caller graph for this function:

◆ getProperty()

QString CardInfo::getProperty ( const QString & propertyName) const
inlinenodiscard
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getRelatedCards()

const QList< CardRelation * > & CardInfo::getRelatedCards ( ) const
inlinenodiscard
Here is the caller graph for this function:

◆ getReverseRelatedCards()

const QList< CardRelation * > & CardInfo::getReverseRelatedCards ( ) const
inlinenodiscard

◆ getReverseRelatedCards2Me()

const QList< CardRelation * > & CardInfo::getReverseRelatedCards2Me ( ) const
inlinenodiscard
Here is the caller graph for this function:

◆ getSets()

const SetToPrintingsMap & CardInfo::getSets ( ) const
inlinenodiscard
Here is the caller graph for this function:

◆ getSetsNames()

const QString & CardInfo::getSetsNames ( ) const
inlinenodiscard

◆ getSimpleName()

const QString & CardInfo::getSimpleName ( ) const
inlinenodiscard

◆ getText()

const QString & CardInfo::getText ( ) const
inlinenodiscard
Here is the caller graph for this function:

◆ getUiAttributes()

const UiAttributes & CardInfo::getUiAttributes ( ) const
inlinenodiscard
Here is the caller graph for this function:

◆ hasProperty()

bool CardInfo::hasProperty ( const QString & propertyName) const
inlinenodiscard
Here is the call graph for this function:

◆ isLegalInFormat()

bool CardInfo::isLegalInFormat ( const QString & format) const
nodiscard

Checks if the card is legal in the given format. A card is considered legal in a format if its properties map contains an entry for "format-<name>", with value "legal" or "restricted".

Parameters
formatThe format's name. If empty, will always return true.
Returns
Whether the card is legal in the given format.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ newInstance() [1/3]

CardInfoPtr CardInfo::newInstance ( const QString & _name)
static

Creates a new instance with only the card name.

All other fields are set to defaults.

Parameters
_nameThe card name.
Returns
Shared pointer to the new CardInfo instance.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ newInstance() [2/3]

CardInfoPtr CardInfo::newInstance ( 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 )
static

Creates a new instance with full initialization.

Parameters
_nameName of the card.
_textRules text or description.
_isTokenToken flag.
_propertiesArbitrary properties.
_relatedCardsForward relationships.
_reverseRelatedCardsReverse relationships.
_setsPrinting information per set.
_uiAttributesAttributes that affect display and game logic
Returns
Shared pointer to the new CardInfo instance.
Here is the call graph for this function:

◆ newInstance() [3/3]

CardInfoPtr CardInfo::newInstance ( const QString & _name,
const QString & _text,
bool _isToken,
QByteArray _propertiesBlob,
const QList< CardRelation * > & _relatedCards,
const QList< CardRelation * > & _reverseRelatedCards,
SetToPrintingsMap _sets,
UiAttributes _uiAttributes,
QString _simpleName,
QSet< QString > _altNames,
bool _appendToSets = true )
static

Creates a new instance from a cache snapshot with precomputed derived state.

Parameters
_nameName of the card.
_textRules text or description.
_isTokenToken flag.
_propertiesBlobPre-serialized properties blob (as written by the cache).
_relatedCardsForward relationships.
_reverseRelatedCardsReverse relationships.
_setsPrinting information per set.
_uiAttributesAttributes that affect display and game logic.
_simpleNamePrecomputed simplified name.
_altNamesPrecomputed alternate names.
_appendToSetsWhen true (default), the card is appended to each of its CardSets. Pass false when building cards in parallel so the (non-thread-safe) set membership is populated in a later single-threaded pass.
Returns
Shared pointer to the new CardInfo instance.
Here is the call graph for this function:

◆ pixmapUpdated

void CardInfo::pixmapUpdated ( const PrintingInfo & printing)
signal

Emitted when a pixmap for this card has been updated or finished loading.

Parameters
printingSpecific printing for which the pixmap has updated.
Here is the caller graph for this function:

◆ refreshCachedAltNames()

void CardInfo::refreshCachedAltNames ( )
private

Refreshes the cached list of alt names for the card.

Typically called after adding or modifying the contained printings.

Here is the caller graph for this function:

◆ refreshCachedSetNames()

void CardInfo::refreshCachedSetNames ( )
private

Refreshes the cached, human-readable list of set names.

Typically called after adding or modifying set memberships.

Here is the caller graph for this function:

◆ refreshCachedSets()

void CardInfo::refreshCachedSets ( )

Refreshes all cached fields that are calculated from the contained sets and printings.

Typically called after adding or modifying set memberships or printings.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resetReverseRelatedCards2Me()

void CardInfo::resetReverseRelatedCards2Me ( )
Here is the call graph for this function:

◆ setCardType()

void CardInfo::setCardType ( const QString & value)
Here is the call graph for this function:

◆ setColors()

void CardInfo::setColors ( const QString & value)
Here is the call graph for this function:

◆ setPowTough()

void CardInfo::setPowTough ( const QString & value)
Here is the call graph for this function:

◆ setProperty()

void CardInfo::setProperty ( const QString & _name,
const QString & _value )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSmartPointer()

void CardInfo::setSmartPointer ( CardInfoPtr _ptr)
inline

Sets the internal smart pointer to self.

Used internally to allow safe cross-references among CardInfo and CardSet.

Parameters
_ptrShared pointer pointing to this instance.

◆ setText()

void CardInfo::setText ( const QString & _text)
inline
Here is the call graph for this function:

◆ simplifyName()

QString CardInfo::simplifyName ( const QString & name)
static

Simplifies a name for fuzzy matching.

Converts to lowercase, removes punctuation/spacing.

Parameters
nameOriginal name string.
Returns
Simplified name string.
Here is the caller graph for this function:

Member Data Documentation

◆ altNames

QSet<QString> CardInfo::altNames
private

Cached set of alternate names, used when searching.

◆ isToken

bool CardInfo::isToken
private

Whether this card is a token or not.

◆ name

QString CardInfo::name
private

Full name of the card.

◆ properties

LazyPropertiesHash CardInfo::properties
private

Key-value store of dynamic card properties.

◆ relatedCards

QList<CardRelation *> CardInfo::relatedCards
private

Forward references to related cards.

◆ reverseRelatedCards

QList<CardRelation *> CardInfo::reverseRelatedCards
private

Cards that refer back to this card.

◆ reverseRelatedCardsToMe

QList<CardRelation *> CardInfo::reverseRelatedCardsToMe
private

Cards that consider this card as related.

◆ setsNames

QString CardInfo::setsNames
private

Cached, human-readable list of set names.

◆ setsToPrintings

SetToPrintingsMap CardInfo::setsToPrintings
private

Mapping from set names to printing variations.

◆ simpleName

QString CardInfo::simpleName
private

Simplified name for fuzzy matching.

◆ smartThis

CardInfoPtr CardInfo::smartThis
private

Smart pointer to self for safe cross-references.

◆ text

QString CardInfo::text
private

Text description or rules text of the card.

◆ uiAttributes

UiAttributes CardInfo::uiAttributes
private

Attributes that affect display and game logic.


The documentation for this class was generated from the following files: