From d5a29d14218b919856172b83dd6f61d8c8c6e6bc Mon Sep 17 00:00:00 2001 From: RickyRister Date: Sat, 6 Dec 2025 23:04:05 -0800 Subject: [PATCH] [DeckLoader] Extract LoadedDeck struct --- cockatrice/CMakeLists.txt | 1 + .../src/interface/deck_loader/deck_loader.h | 27 ++-------- .../src/interface/deck_loader/loaded_deck.cpp | 19 +++++++ .../src/interface/deck_loader/loaded_deck.h | 50 +++++++++++++++++++ 4 files changed, 74 insertions(+), 23 deletions(-) create mode 100644 cockatrice/src/interface/deck_loader/loaded_deck.cpp create mode 100644 cockatrice/src/interface/deck_loader/loaded_deck.h diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index 1dbeddc5e..83a30462c 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -20,6 +20,7 @@ set(cockatrice_SOURCES src/client/settings/shortcut_treeview.cpp src/client/settings/shortcuts_settings.cpp src/interface/deck_loader/deck_loader.cpp + src/interface/deck_loader/loaded_deck.cpp src/interface/widgets/dialogs/dlg_connect.cpp src/interface/widgets/dialogs/dlg_convert_deck_to_cod_format.cpp src/interface/widgets/dialogs/dlg_create_game.cpp diff --git a/cockatrice/src/interface/deck_loader/deck_loader.h b/cockatrice/src/interface/deck_loader/deck_loader.h index 00136e6bb..1da397045 100644 --- a/cockatrice/src/interface/deck_loader/deck_loader.h +++ b/cockatrice/src/interface/deck_loader/deck_loader.h @@ -7,14 +7,16 @@ #ifndef DECK_LOADER_H #define DECK_LOADER_H +#include "loaded_deck.h" + #include #include #include #include -inline Q_LOGGING_CATEGORY(DeckLoaderLog, "deck_loader") +inline Q_LOGGING_CATEGORY(DeckLoaderLog, "deck_loader"); - class DeckLoader : public QObject +class DeckLoader : public QObject { Q_OBJECT signals: @@ -22,27 +24,6 @@ signals: void loadFinished(bool success); public: - enum FileFormat - { - PlainTextFormat, - CockatriceFormat - }; - - /** - * @brief Information about where the deck was loaded from. - * - * For local decks, the remoteDeckId field will always be -1. - * For remote decks, fileName will be empty and fileFormat will always be CockatriceFormat - */ - struct LoadInfo - { - static constexpr int NON_REMOTE_ID = -1; - - QString fileName = ""; - FileFormat fileFormat = CockatriceFormat; - int remoteDeckId = NON_REMOTE_ID; - }; - /** * Supported file extensions for decklist files */ diff --git a/cockatrice/src/interface/deck_loader/loaded_deck.cpp b/cockatrice/src/interface/deck_loader/loaded_deck.cpp new file mode 100644 index 000000000..f42c2a300 --- /dev/null +++ b/cockatrice/src/interface/deck_loader/loaded_deck.cpp @@ -0,0 +1,19 @@ +#include "loaded_deck.h" + +LoadedDeck::FileFormat LoadedDeck::getFormatFromName(const QString &fileName) +{ + if (fileName.endsWith(".cod", Qt::CaseInsensitive)) { + return CockatriceFormat; + } + return PlainTextFormat; +} + +bool LoadedDeck::LoadInfo::isEmpty() const +{ + return fileName.isEmpty() && remoteDeckId == NON_REMOTE_ID; +} + +bool LoadedDeck::isEmpty() const +{ + return deckList.isEmpty() && lastLoadInfo.isEmpty(); +} \ No newline at end of file diff --git a/cockatrice/src/interface/deck_loader/loaded_deck.h b/cockatrice/src/interface/deck_loader/loaded_deck.h new file mode 100644 index 000000000..123f3d062 --- /dev/null +++ b/cockatrice/src/interface/deck_loader/loaded_deck.h @@ -0,0 +1,50 @@ +#ifndef COCKATRICE_LOADED_DECK_H +#define COCKATRICE_LOADED_DECK_H +#include "libcockatrice/deck_list/deck_list.h" + +#include + +/** + * @brief Represents a deck that was loaded from somewhere. + * Contains the DeckList itself, as well as info about where it was loaded from. + */ +struct LoadedDeck +{ + enum FileFormat + { + PlainTextFormat, + CockatriceFormat + }; + + /** + * Determines what deck file format the given filename corresponds to. + * + * @param fileName The filename + * @return The deck format + */ + static FileFormat getFormatFromName(const QString &fileName); + + /** + * @brief Information about where the deck was loaded from. + * + * For local decks, the remoteDeckId field will always be -1. + * For remote decks, fileName will be empty and fileFormat will always be CockatriceFormat + */ + struct LoadInfo + { + static constexpr int NON_REMOTE_ID = -1; + + QString fileName = ""; + FileFormat fileFormat = CockatriceFormat; + int remoteDeckId = NON_REMOTE_ID; + + bool isEmpty() const; + }; + + DeckList deckList; ///< The decklist itself + LoadInfo lastLoadInfo; ///< info about where the deck was loaded from + + bool isEmpty() const; +}; + +#endif // COCKATRICE_LOADED_DECK_H