mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 08:14:47 -07:00
[DeckLoader] Make save/load methods static (#6476)
* const * [DeckLoader] make methods static * use static methods * add docs * add docs
This commit is contained in:
parent
c7c7bf550a
commit
d579c82cb9
11 changed files with 209 additions and 166 deletions
|
|
@ -20,7 +20,6 @@ class DeckLoader : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
signals:
|
||||
void deckLoaded();
|
||||
void loadFinished(bool success);
|
||||
|
||||
public:
|
||||
|
|
@ -53,11 +52,60 @@ public:
|
|||
return loadedDeck.lastLoadInfo.isEmpty();
|
||||
}
|
||||
|
||||
bool loadFromFile(const QString &fileName, DeckFileFormat::Format fmt, bool userRequest = false);
|
||||
bool loadFromFileAsync(const QString &fileName, DeckFileFormat::Format fmt, bool userRequest);
|
||||
bool loadFromRemote(const QString &nativeString, int remoteDeckId);
|
||||
bool saveToFile(const QString &fileName, DeckFileFormat::Format fmt);
|
||||
bool updateLastLoadedTimestamp(const QString &fileName, DeckFileFormat::Format fmt);
|
||||
/**
|
||||
* @brief Asynchronously loads a deck from a local file into this DeckLoader.
|
||||
* The `loadFinished` signal will be emitted when the load finishes.
|
||||
* Once the loading finishes, the deck can be accessed with `getDeck`
|
||||
* @param fileName The file to load
|
||||
* @param fmt The format of the file to load
|
||||
* @param userRequest Whether the load was manually requested by the user, instead of being done in the background.
|
||||
*/
|
||||
void loadFromFileAsync(const QString &fileName, DeckFileFormat::Format fmt, bool userRequest);
|
||||
|
||||
/**
|
||||
* @brief Loads a deck from a local file.
|
||||
* @param fileName The file to load
|
||||
* @param fmt The format of the file to load
|
||||
* @param userRequest Whether the load was manually requested by the user, instead of being done in the background.
|
||||
* @return An optional containing the LoadedDeck, or empty if the load failed.
|
||||
*/
|
||||
static std::optional<LoadedDeck>
|
||||
loadFromFile(const QString &fileName, DeckFileFormat::Format fmt, bool userRequest = false);
|
||||
|
||||
/**
|
||||
* @brief Loads a deck from the response of a remote deck request
|
||||
* @param nativeString The deck string, in cod format
|
||||
* @param remoteDeckId The remote deck id
|
||||
* @return An optional containing the LoadedDeck, or empty if the load failed.
|
||||
*/
|
||||
static std::optional<LoadedDeck> loadFromRemote(const QString &nativeString, int remoteDeckId);
|
||||
|
||||
/**
|
||||
* @brief Saves a DeckList to a local file.
|
||||
* @param deck The DeckList
|
||||
* @param fileName The file to write to
|
||||
* @param fmt The deck file format to use
|
||||
* @return An optional containing the LoadInfo for the new file, or empty if the save failed.
|
||||
*/
|
||||
static std::optional<LoadedDeck::LoadInfo>
|
||||
saveToFile(const DeckList &deck, const QString &fileName, DeckFileFormat::Format fmt);
|
||||
|
||||
/**
|
||||
* @brief Saves a LoadedDeck to a local file.
|
||||
* Uses the lastLoadInfo in the LoadedDeck to determine where to save to.
|
||||
* @param deck The LoadedDeck to save. Should have valid lastLoadInfo.
|
||||
* @return Whether the save succeeded.
|
||||
*/
|
||||
static bool saveToFile(const LoadedDeck &deck);
|
||||
|
||||
/**
|
||||
* @brief Saves a LoadedDeck to a new local file.
|
||||
* @param deck The LoadedDeck to save. Will update the lastLoadInfo.
|
||||
* @param fileName The file to write to
|
||||
* @param fmt The deck file format to use
|
||||
* @return Whether the save succeeded.
|
||||
*/
|
||||
static bool saveToNewFile(LoadedDeck &deck, const QString &fileName, DeckFileFormat::Format fmt);
|
||||
|
||||
static QString exportDeckToDecklist(const DeckList &deckList, DecklistWebsite website);
|
||||
|
||||
|
|
@ -74,7 +122,13 @@ public:
|
|||
*/
|
||||
static void printDeckList(QPrinter *printer, const DeckList &deckList);
|
||||
|
||||
bool convertToCockatriceFormat(const QString &fileName);
|
||||
/**
|
||||
* Converts the given deck's file to the cockatrice file format.
|
||||
* Uses the lastLoadInfo in the LoadedDeck to determine the current name of the file and where to save to.
|
||||
* @param deck The deck to convert. Should have valid lastLoadInfo. Will update the lastLoadInfo.
|
||||
* @return Whether the conversion succeeded.
|
||||
*/
|
||||
static bool convertToCockatriceFormat(LoadedDeck &deck);
|
||||
|
||||
LoadedDeck &getDeck()
|
||||
{
|
||||
|
|
@ -90,6 +144,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
static bool updateLastLoadedTimestamp(LoadedDeck &deck);
|
||||
static void printDeckListNode(QTextCursor *cursor, const InnerDecklistNode *node);
|
||||
static void saveToStream_DeckHeader(QTextStream &out, const DeckList &deckList);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue