![]() |
Cockatrice 2026-10-19-Development-3.1.2-beta.2
A virtual tabletop for multiplayer card games
|
#include <oracleimporter.h>
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 ¤tSet, 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 ¤tSet, 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-") |
|
explicit |
|
private |
| 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.
|
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.
| void OracleImporter::clear | ( | ) |
|
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.
| const FormatRulesNameMap & OracleImporter::createDefaultMagicFormats | ( | ) |
Returns the default format rules. The result is memoized on first use and must be treated as immutable.
|
signal |
|
inline |
|
inline |
|
inline |
|
inline |
| int OracleImporter::importCardsFromSet | ( | const CardSetPtr & | currentSet, |
| const QJsonArray & | cardsList ) |
| 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.
| void OracleImporter::releaseSetData | ( | ) |
| bool OracleImporter::saveToFile | ( | const QString & | fileName, |
| const QString & | sourceUrl, | ||
| const QString & | sourceVersion ) |
| void OracleImporter::setCardLang | ( | const QString & | lang | ) |
Selects the ISO-639 language code whose foreignData is imported. English (the default) and unsupported codes disable localization.
|
signal |
|
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.
| int OracleImporter::startImport | ( | ) |
|
private |
|
private |
The ISO-639 language code whose foreignData is imported; "en" by default.
|
private |
The cards, indexed by name.
|
staticprivate |
|
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).
|
private |
Whether cardLang is a supported language other than English, so per-card foreignData scanning can be skipped entirely when disabled.
|
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.
|
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.
|
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.
|
private |
The sets, indexed by short name.
|
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.