[DeckLoader] Refactor last load info into struct (#6366)

* [DeckLoader] Refactor last load info into struct

* Use constant

* [[nodiscard]]

* do discard, I guess.

---------

Co-authored-by: Brübach, Lukas <lukas.bruebach@student.fhws.de>
This commit is contained in:
RickyRister 2025-11-28 14:41:11 -08:00 committed by GitHub
parent 9ece4bfd9b
commit 858361e6d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 60 additions and 44 deletions

View file

@ -28,6 +28,21 @@ public:
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
*/
@ -46,9 +61,7 @@ public:
private:
DeckList *deckList;
QString lastFileName;
FileFormat lastFileFormat;
int lastRemoteDeckId;
LoadInfo lastLoadInfo;
public:
DeckLoader(QObject *parent);
@ -56,26 +69,19 @@ public:
DeckLoader(const DeckLoader &) = delete;
DeckLoader &operator=(const DeckLoader &) = delete;
[[nodiscard]] const QString &getLastFileName() const
const LoadInfo &getLastLoadInfo() const
{
return lastFileName;
return lastLoadInfo;
}
void setLastFileName(const QString &_lastFileName)
void setLastLoadInfo(const LoadInfo &info)
{
lastFileName = _lastFileName;
}
[[nodiscard]] FileFormat getLastFileFormat() const
{
return lastFileFormat;
}
[[nodiscard]] int getLastRemoteDeckId() const
{
return lastRemoteDeckId;
lastLoadInfo = info;
}
[[nodiscard]] bool hasNotBeenLoaded() const
{
return getLastFileName().isEmpty() && getLastRemoteDeckId() == -1;
return lastLoadInfo.fileName.isEmpty() && lastLoadInfo.remoteDeckId == LoadInfo::NON_REMOTE_ID;
}
static void clearSetNamesAndNumbers(const DeckList *deckList);