From 42890455577c8132fa34c322f234691684193f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Sun, 14 Dec 2025 09:16:49 +0100 Subject: [PATCH] [TabArchidekt] Set game format when importing Took 5 minutes --- .../deck/archidekt_api_response_deck.h | 227 ++++++++++++++++++ ...idekt_api_response_deck_display_widget.cpp | 2 + 2 files changed, 229 insertions(+) diff --git a/cockatrice/src/interface/widgets/tabs/api/archidekt/api_response/deck/archidekt_api_response_deck.h b/cockatrice/src/interface/widgets/tabs/api/archidekt/api_response/deck/archidekt_api_response_deck.h index 8cb81cac3..906e66727 100644 --- a/cockatrice/src/interface/widgets/tabs/api/archidekt/api_response/deck/archidekt_api_response_deck.h +++ b/cockatrice/src/interface/widgets/tabs/api/archidekt/api_response/deck/archidekt_api_response_deck.h @@ -12,6 +12,228 @@ #include #include +namespace ArchidektFormats +{ +enum class DeckFormat +{ + // The order is important since archidekt returns an integer + Standard, + Modern, + Commander, + Legacy, + Vintage, + Pauper, + Custom, + Frontier, + FutureStandard, + PennyDreadful, + Commander1v1, + DualCommander, + Brawl, + + // These are outside of archidekts range. + Alchemy, + Historic, + Gladiator, + Oathbreaker, + OldSchool, + PauperCommander, + Pioneer, + PreDH, + Premodern, + StandardBrawl, + Timeless, + Unknown +}; + +inline static QString formatToApiName(DeckFormat format) +{ + switch (format) { + case DeckFormat::Standard: + return "Standard"; + case DeckFormat::Modern: + return "Modern"; + case DeckFormat::Commander: + return "Commander"; + case DeckFormat::Legacy: + return "Legacy"; + case DeckFormat::Vintage: + return "Vintage"; + case DeckFormat::Pauper: + return "Pauper"; + case DeckFormat::Custom: + return "Custom"; + case DeckFormat::Frontier: + return "Frontier"; + case DeckFormat::FutureStandard: + return "Future Std"; + case DeckFormat::PennyDreadful: + return "Penny Dreadful"; + case DeckFormat::Commander1v1: + return "1v1 Commander"; + case DeckFormat::DualCommander: + return "Dual Commander"; + case DeckFormat::Brawl: + return "Brawl"; + + case DeckFormat::Alchemy: + return "Alchemy"; + case DeckFormat::Historic: + return "Historic"; + case DeckFormat::Gladiator: + return "Gladiator"; + case DeckFormat::Oathbreaker: + return "Oathbreaker"; + case DeckFormat::OldSchool: + return "Old School"; + case DeckFormat::PauperCommander: + return "Pauper Commander"; + case DeckFormat::Pioneer: + return "Pioneer"; + case DeckFormat::PreDH: + return "PreDH"; + case DeckFormat::Premodern: + return "Premodern"; + case DeckFormat::StandardBrawl: + return "Standard Brawl"; + case DeckFormat::Timeless: + return "Timeless"; + + default: + return "Unknown"; + } +} + +inline static DeckFormat apiNameToFormat(const QString &name) +{ + const QString n = name.trimmed(); + + if (n.compare("Standard", Qt::CaseInsensitive) == 0) + return DeckFormat::Standard; + if (n.compare("Modern", Qt::CaseInsensitive) == 0) + return DeckFormat::Modern; + if (n.compare("Commander", Qt::CaseInsensitive) == 0) + return DeckFormat::Commander; + if (n.compare("Legacy", Qt::CaseInsensitive) == 0) + return DeckFormat::Legacy; + if (n.compare("Vintage", Qt::CaseInsensitive) == 0) + return DeckFormat::Vintage; + if (n.compare("Pauper", Qt::CaseInsensitive) == 0) + return DeckFormat::Pauper; + if (n.compare("Custom", Qt::CaseInsensitive) == 0) + return DeckFormat::Custom; + if (n.compare("Frontier", Qt::CaseInsensitive) == 0) + return DeckFormat::Frontier; + if (n.compare("Future Std", Qt::CaseInsensitive) == 0) + return DeckFormat::FutureStandard; + if (n.compare("Penny Dreadful", Qt::CaseInsensitive) == 0) + return DeckFormat::PennyDreadful; + if (n.compare("1v1 Commander", Qt::CaseInsensitive) == 0) + return DeckFormat::Commander1v1; + if (n.compare("Dual Commander", Qt::CaseInsensitive) == 0) + return DeckFormat::DualCommander; + if (n.compare("Brawl", Qt::CaseInsensitive) == 0) + return DeckFormat::Brawl; + + if (n.compare("Alchemy", Qt::CaseInsensitive) == 0) + return DeckFormat::Alchemy; + if (n.compare("Historic", Qt::CaseInsensitive) == 0) + return DeckFormat::Historic; + if (n.compare("Gladiator", Qt::CaseInsensitive) == 0) + return DeckFormat::Gladiator; + if (n.compare("Oathbreaker", Qt::CaseInsensitive) == 0) + return DeckFormat::Oathbreaker; + if (n.compare("Old School", Qt::CaseInsensitive) == 0) + return DeckFormat::OldSchool; + if (n.compare("Pauper Commander", Qt::CaseInsensitive) == 0) + return DeckFormat::PauperCommander; + if (n.compare("Pioneer", Qt::CaseInsensitive) == 0) + return DeckFormat::Pioneer; + if (n.compare("PreDH", Qt::CaseInsensitive) == 0) + return DeckFormat::PreDH; + if (n.compare("Premodern", Qt::CaseInsensitive) == 0) + return DeckFormat::Premodern; + if (n.compare("Standard Brawl", Qt::CaseInsensitive) == 0) + return DeckFormat::StandardBrawl; + if (n.compare("Timeless", Qt::CaseInsensitive) == 0) + return DeckFormat::Timeless; + + return DeckFormat::Unknown; +} + +inline static QString formatToCockatriceName(DeckFormat format) +{ + switch (format) { + case DeckFormat::Standard: + return "standard"; + case DeckFormat::Modern: + return "modern"; + case DeckFormat::Commander: + return "commander"; + case DeckFormat::Legacy: + return "legacy"; + case DeckFormat::Vintage: + return "vintage"; + case DeckFormat::Pauper: + return "pauper"; + case DeckFormat::Brawl: + return "brawl"; + case DeckFormat::PennyDreadful: + return "penny"; + case DeckFormat::FutureStandard: + return "future"; + case DeckFormat::Commander1v1: + return "duel"; + case DeckFormat::DualCommander: + return "duel"; + case DeckFormat::Alchemy: + return "alchemy"; + case DeckFormat::Historic: + return "historic"; + case DeckFormat::Gladiator: + return "gladiator"; + case DeckFormat::Oathbreaker: + return "oathbreaker"; + case DeckFormat::OldSchool: + return "oldschool"; + case DeckFormat::PauperCommander: + return "paupercommander"; + case DeckFormat::Pioneer: + return "pioneer"; + case DeckFormat::PreDH: + return "predh"; + case DeckFormat::Premodern: + return "premodern"; + case DeckFormat::StandardBrawl: + return "standardbrawl"; + case DeckFormat::Timeless: + return "timeless"; + + default: + return {}; + } +} + +inline static DeckFormat cockatriceNameToFormat(const QString &apiName) +{ + static const QHash map = { + {"standard", DeckFormat::Standard}, {"modern", DeckFormat::Modern}, + {"commander", DeckFormat::Commander}, {"legacy", DeckFormat::Legacy}, + {"vintage", DeckFormat::Vintage}, {"pauper", DeckFormat::Pauper}, + {"brawl", DeckFormat::Brawl}, {"penny", DeckFormat::PennyDreadful}, + {"future", DeckFormat::FutureStandard}, {"duel", DeckFormat::Commander1v1}, + {"alchemy", DeckFormat::Alchemy}, {"historic", DeckFormat::Historic}, + {"gladiator", DeckFormat::Gladiator}, {"oathbreaker", DeckFormat::Oathbreaker}, + {"oldschool", DeckFormat::OldSchool}, {"paupercommander", DeckFormat::PauperCommander}, + {"pioneer", DeckFormat::Pioneer}, {"predh", DeckFormat::PreDH}, + {"premodern", DeckFormat::Premodern}, {"standardbrawl", DeckFormat::StandardBrawl}, + {"timeless", DeckFormat::Timeless}}; + + return map.value(apiName.toLower(), DeckFormat::Unknown); +} + +} // namespace ArchidektFormats + class ArchidektApiResponseDeck { public: @@ -39,6 +261,11 @@ public: return name; }; + int getDeckFormat() const + { + return deckFormat; + } + private: int id; QString name; diff --git a/cockatrice/src/interface/widgets/tabs/api/archidekt/display/archidekt_api_response_deck_display_widget.cpp b/cockatrice/src/interface/widgets/tabs/api/archidekt/display/archidekt_api_response_deck_display_widget.cpp index 63d732c9a..6c11216ca 100644 --- a/cockatrice/src/interface/widgets/tabs/api/archidekt/display/archidekt_api_response_deck_display_widget.cpp +++ b/cockatrice/src/interface/widgets/tabs/api/archidekt/display/archidekt_api_response_deck_display_widget.cpp @@ -93,6 +93,8 @@ void ArchidektApiResponseDeckDisplayWidget::actOpenInDeckEditor() loader->getDeckList()->loadFromString_Native(model->getDeckList()->writeToString_Native()); loader->getDeckList()->setName(response.getDeckName()); + loader->getDeckList()->setGameFormat( + ArchidektFormats::formatToCockatriceName(ArchidektFormats::DeckFormat(response.getDeckFormat() - 1))); emit openInDeckEditor(loader); }