From 11391a1a21c45ec1668c8caf620e1be65b6d8e66 Mon Sep 17 00:00:00 2001 From: RickyRister Date: Sat, 10 Jan 2026 02:33:03 -0800 Subject: [PATCH] add reload to DeckLoader --- .../src/interface/deck_loader/deck_loader.cpp | 16 ++++++++++++++++ .../src/interface/deck_loader/deck_loader.h | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/cockatrice/src/interface/deck_loader/deck_loader.cpp b/cockatrice/src/interface/deck_loader/deck_loader.cpp index 305cd34d9..3481e245b 100644 --- a/cockatrice/src/interface/deck_loader/deck_loader.cpp +++ b/cockatrice/src/interface/deck_loader/deck_loader.cpp @@ -91,6 +91,22 @@ void DeckLoader::loadFromFileAsync(const QString &fileName, DeckFileFormat::Form }); } +bool DeckLoader::reload() +{ + QString lastFileName = loadedDeck.lastLoadInfo.fileName; + if (lastFileName.isEmpty()) { + return false; + } + std::optional deck = loadFromFile(lastFileName, loadedDeck.lastLoadInfo.fileFormat, false); + + if (!deck) { + return false; + } + + loadedDeck = *deck; + return true; +} + std::optional DeckLoader::loadFromRemote(const QString &nativeString, int remoteDeckId) { DeckList deckList; diff --git a/cockatrice/src/interface/deck_loader/deck_loader.h b/cockatrice/src/interface/deck_loader/deck_loader.h index 1780e2706..2530b7f5d 100644 --- a/cockatrice/src/interface/deck_loader/deck_loader.h +++ b/cockatrice/src/interface/deck_loader/deck_loader.h @@ -62,6 +62,13 @@ public: */ void loadFromFileAsync(const QString &fileName, DeckFileFormat::Format fmt, bool userRequest); + /** + * @brief Loads the file that the lastLoadInfo currently points to into this instance. + * No-ops if the lastLoadInfo is missing the required info or the load fails. + * @return Whether the loaded succeeded. + */ + bool reload(); + /** * @brief Loads a deck from a local file. * @param fileName The file to load