Cockatrice/oracle/src/oraclewizard.h
BruebachL 6138fbd0a0
[Card] Add Scryfall Tagger tag search and filtering (#7337)
* [Card] Import Scryfall Tagger tags from MTGJson

* [Card] Search cards by Scryfall Tagger tag

* [Card] Add a Tag attribute to the card filter tree

* [Card] Add a Tags filter to the visual card database

* [Oracle] Add a script to inject Scryfall tags into AllPrintings

* [Card] Elide long tag lists in the card info and drop the Scryfall label from the tag filter tooltip

* [Oracle] Load card tags from a tag database during import

Add a TagDatabase loader that understands Scryfall's Oracle Tags bulk data and user-supplied tag files (tag objects, flat oracle-id or name maps, optional manifest, JSON or JSONL, gzip/xz/zip). The importer joins the slugs on identifiers.scryfallOracleId while the identifiers are still available, falls back to the card name, and unions them with any tags the source already provides. Split-card faces merge through the existing tag union path.

This replaces oracle/scripts/inject_scryfall_tags.py, which patched AllPrintings.json before import. Loading during import keeps tags on by default for every source and lets users pair Oracle with any tag database.

* [Oracle] Add a tag data step to the import wizard

Insert a Tags page between set selection and the import. It downloads Scryfall's Oracle Tags by default (or a user-supplied file/URL), can include parent tags, and persists tagsenabled, tagssource and tagsparents in oracle.ini. The page loads asynchronously and soft-fails in background mode, so a tag download or parse error never aborts the card database import.

* [Help] Describe tag search without naming Scryfall

Tags can come from Scryfall's Oracle Tags or any user-supplied tag database, so the search help should not claim a single source.

* [Oracle] Fix Scryfall tag requests and the retry loop

api.scryfall.com rejects requests that lack an Accept header with HTTP 400, and QNetworkAccessManager does not add one. Send application/json for the bulk metadata request and */* for the tag file, and surface the URL plus Scryfall's JSON error body when a request fails.

A failed tag load used to call next(), which re-ran validatePage() and started the same failing download again, trapping the user in an error loop. Stay on the page instead, drop the unusable database, and tell the user they can retry, change the source, or untick the option to import without tags. Also explain parent tags inline with a real Scryfall hierarchy example.

* [Oracle] Give the parent-tag explainer room to breathe

The wrapped explainer sat flush under the checkbox with no separation from the status label, which made the paragraph look cramped. Indent it under the checkbox and add a little vertical margin.

* [Oracle] Stop the parent-tag explainer from being clipped

A word-wrapped QLabel reports a one-line sizeHint, so the wizard page reserved too little height and the explanation lost its top and bottom lines. Pin the vertical size policy to Minimum on the explainer and on the status label, so the wrapped height becomes part of the page minimum. Verified with a layout probe: the label went from 28 px tall (needed 56) to its full height.

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
2026-11-08 20:57:45 +01:00

103 lines
2.4 KiB
C++

#ifndef ORACLEWIZARD_H
#define ORACLEWIZARD_H
#include <QByteArray>
#include <QString>
#include <QWizard>
#include <memory>
#include <qtmetamacros.h>
#include <utility>
class QNetworkAccessManager;
class OracleImporter;
class QLocalServer;
class QSettings;
class TagDatabase;
class QWidget;
class OracleWizard : public QWizard
{
Q_OBJECT
public:
explicit OracleWizard(QWidget *parent = nullptr);
void accept() override;
void reject() override;
bool wasCancelled()
{
return cancelled;
}
/** @brief Records that the card database was written to disk, so a later cancel still counts as an update. */
void markDatabaseSaved()
{
databaseSaved = true;
}
bool hasSavedDatabase()
{
return databaseSaved;
}
void enableButtons();
void disableButtons();
void retranslateUi();
void setTokensData(QByteArray _tokensData)
{
tokensData = std::move(_tokensData);
}
bool hasTokensData()
{
return !tokensData.isEmpty();
}
void setCardSourceUrl(const QString &sourceUrl)
{
cardSourceUrl = sourceUrl;
}
void setCardSourceVersion(const QString &sourceVersion)
{
cardSourceVersion = sourceVersion;
}
const QString &getCardSourceUrl() const
{
return cardSourceUrl;
}
const QString &getCardSourceVersion() const
{
return cardSourceVersion;
}
bool saveTokensToFile(const QString &fileName);
void runInBackground();
public:
OracleImporter *importer;
QSettings *settings;
QNetworkAccessManager *nam;
/** @brief Tag data loaded by the Tags page, consumed by the importer. */
std::shared_ptr<TagDatabase> tagDatabase;
bool downloadedPlainXml = false;
QByteArray xmlData;
bool backgroundMode = false;
private slots:
void updateLanguage();
void handleRaiseRequest();
private:
QByteArray tokensData;
QString cardSourceUrl;
QString cardSourceVersion;
bool cancelled = false;
bool databaseSaved = false;
void migrateOracleSettings();
/**
* @brief Starts the local socket the hosting Cockatrice client uses to bring this wizard forward.
*/
void startRaiseServer();
/** @brief Shows, raises and activates the wizard window. */
void raiseWizard();
QLocalServer *raiseServer = nullptr; ///< listens for raise requests from the hosting client
protected:
void changeEvent(QEvent *event) override;
};
#endif