Cockatrice 2026-10-19-Development-3.1.2-beta.2
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
OracleImporter Class Reference

#include <oracleimporter.h>

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

Signals

void setIndexChanged (int cardsImported, int setIndex, const QString &setName)
void dataReadProgress (int bytesRead, int totalBytes)

Public Member Functions

 OracleImporter (QObject *parent=nullptr)
void setProgressReporting (bool enabled)
 Controls whether readSetsFromByteArray() instruments the raw scan.
void setCardLang (const QString &lang)
const QString & getCardLang () const
bool readSetsFromByteArray (QByteArray data)
int startImport ()
void cancelImport ()
 Requests an in-flight startImport() to stop at the next set boundary.
void applyLocalizedData ()
bool saveToFile (const QString &fileName, const QString &sourceUrl, const QString &sourceVersion)
int importCardsFromSet (const CardSetPtr &currentSet, const QJsonArray &cardsList)
const FormatRulesNameMap & createDefaultMagicFormats ()
 Returns the default format rules. The result is memoized on first use and must be treated as immutable.
const CardNameMap & getCardList () const
QList< SetToDownload > & getSets ()
const QByteArray & getRawSetsData () const
void releaseSetData ()
void clear ()

Private Member Functions

CardInfoPtr addCard (QString name, const QString &text, bool isToken, QHash< QString, QString > properties, const QList< CardRelation * > &relatedCards, const PrintingInfo &printingInfo)
void collectForeignData (const QString &cardKey, const CardSetPtr &currentSet, const QJsonObject &card, bool collectText=true)

Private Attributes

CardNameMap cards
SetNameMap sets
QList< SetToDownload > allSets
QByteArray rawSetsData
bool progressReporting = true
QAtomicInt importCancelled
QString cardLang = "en"
bool localizationEnabled = false
QMap< QString, LocalizedCardEntry > localizedEntries
QMap< QString, LocalizedCardEntry > splitLocalizedTexts

Static Private Attributes

static const QRegularExpression formatRegex = QRegularExpression("^format-")

Constructor & Destructor Documentation

◆ OracleImporter()

OracleImporter::OracleImporter ( QObject * parent = nullptr)
explicit
Here is the caller graph for this function:

Member Function Documentation

◆ addCard()

CardInfoPtr OracleImporter::addCard ( QString name,
const QString & text,
bool isToken,
QHash< QString, QString > properties,
const QList< CardRelation * > & relatedCards,
const PrintingInfo & printingInfo )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ applyLocalizedData()

void OracleImporter::applyLocalizedData ( )

Applies the collected localized names/texts to the imported cards. Called automatically at the end of startImport(); exposed separately so tests can drive it after importing sets directly.

Here is the caller graph for this function:

◆ cancelImport()

void OracleImporter::cancelImport ( )
inline

Requests an in-flight startImport() to stop at the next set boundary.

Works by setting an atomic flag that startImport() polls between sets, so cancelImport() followed by a short waitForFinished() on the running future is safe the moment the wizard is about to be destroyed.

Here is the caller graph for this function:

◆ clear()

void OracleImporter::clear ( )
Here is the caller graph for this function:

◆ collectForeignData()

void OracleImporter::collectForeignData ( const QString & cardKey,
const CardSetPtr & currentSet,
const QJsonObject & card,
bool collectText = true )
private

Records the first foreignData entry matching cardLang for the given card key, keeping the entry from the highest-priority set seen so far.

Multi-face cards (split, adventure, aftermath, prepare) pass collectText = false: MTGJSON emits one foreignData entry per face with the same joined name but only that face's text, so the name is collected here while the per-face texts are joined during the split-card merge.

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

◆ createDefaultMagicFormats()

const FormatRulesNameMap & OracleImporter::createDefaultMagicFormats ( )

Returns the default format rules. The result is memoized on first use and must be treated as immutable.

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

◆ dataReadProgress

void OracleImporter::dataReadProgress ( int bytesRead,
int totalBytes )
signal
Here is the caller graph for this function:

◆ getCardLang()

const QString & OracleImporter::getCardLang ( ) const
inline

◆ getCardList()

const CardNameMap & OracleImporter::getCardList ( ) const
inline
Here is the caller graph for this function:

◆ getRawSetsData()

const QByteArray & OracleImporter::getRawSetsData ( ) const
inline

◆ getSets()

QList< SetToDownload > & OracleImporter::getSets ( )
inline
Here is the caller graph for this function:

◆ importCardsFromSet()

int OracleImporter::importCardsFromSet ( const CardSetPtr & currentSet,
const QJsonArray & cardsList )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readSetsFromByteArray()

bool OracleImporter::readSetsFromByteArray ( QByteArray data)

Scans the given JSON document for set metadata. Takes the data by value so the wizard can hand over its decompressed buffer without copying it.

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

◆ releaseSetData()

void OracleImporter::releaseSetData ( )
Here is the caller graph for this function:

◆ saveToFile()

bool OracleImporter::saveToFile ( const QString & fileName,
const QString & sourceUrl,
const QString & sourceVersion )
Here is the call graph for this function:

◆ setCardLang()

void OracleImporter::setCardLang ( const QString & lang)

Selects the ISO-639 language code whose foreignData is imported. English (the default) and unsupported codes disable localization.

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

◆ setIndexChanged

void OracleImporter::setIndexChanged ( int cardsImported,
int setIndex,
const QString & setName )
signal
Here is the caller graph for this function:

◆ setProgressReporting()

void OracleImporter::setProgressReporting ( bool enabled)
inline

Controls whether readSetsFromByteArray() instruments the raw scan.

When enabled (the default) the raw scanner reports progress via dataReadProgress(), which the wizard streams to stdout (so the hosting Cockatrice client can show it) and also displays on its own progress bar. Switch it off only when nothing will consume scan progress.

◆ startImport()

int OracleImporter::startImport ( )
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ allSets

QList<SetToDownload> OracleImporter::allSets
private

◆ cardLang

QString OracleImporter::cardLang = "en"
private

The ISO-639 language code whose foreignData is imported; "en" by default.

◆ cards

CardNameMap OracleImporter::cards
private

The cards, indexed by name.

◆ formatRegex

const QRegularExpression OracleImporter::formatRegex = QRegularExpression("^format-")
staticprivate

◆ importCancelled

QAtomicInt OracleImporter::importCancelled
private

Atomic "please stop importing" flag. startImport() checks it between sets so a wizard being closed mid-import can be torn down without waiting for the whole import (or racing it).

◆ localizationEnabled

bool OracleImporter::localizationEnabled = false
private

Whether cardLang is a supported language other than English, so per-card foreignData scanning can be skipped entirely when disabled.

◆ localizedEntries

QMap<QString, LocalizedCardEntry> OracleImporter::localizedEntries
private

Localized name/text collected per imported card key while parsing sets, applied to the CardInfo objects by applyLocalizedData() once all printings have been seen so the best-priority one wins.

◆ progressReporting

bool OracleImporter::progressReporting = true
private

Whether readSetsFromByteArray() should report scan progress via dataReadProgress. The wizard streams that signal to stdout (for the hosting Cockatrice client to parse) in both interactive and background runs; the flag exists to skip the scanner instrumentation entirely when no consumer needs it.

◆ rawSetsData

QByteArray OracleImporter::rawSetsData
private

The raw JSON text of the source document, retained for lazy per-set parsing during startImport(). Frees the card data as each set is imported.

◆ sets

SetNameMap OracleImporter::sets
private

The sets, indexed by short name.

◆ splitLocalizedTexts

QMap<QString, LocalizedCardEntry> OracleImporter::splitLocalizedTexts
private

cardLang rules text collected for split-card names while parsing sets, applied by applyLocalizedData(). Kept apart from localizedEntries because MTGJSON emits each split face as its own card object with the joined name on every foreignData entry: names and the per-face text join have different completeness and must not overwrite each other under the same key.


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