Cockatrice 2025-11-30-Development-2.11.0-beta.38
A cross-platform virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
deck_loader.h
Go to the documentation of this file.
1
6
7#ifndef DECK_LOADER_H
8#define DECK_LOADER_H
9
10#include <QLoggingCategory>
11#include <QPrinter>
12#include <QTextCursor>
14
15inline Q_LOGGING_CATEGORY(DeckLoaderLog, "deck_loader")
16
17 class DeckLoader : public QObject
18{
19 Q_OBJECT
20signals:
21 void deckLoaded();
22 void loadFinished(bool success);
23
24public:
25 enum FileFormat
26 {
27 PlainTextFormat,
28 CockatriceFormat
29 };
30
37 struct LoadInfo
38 {
39 static constexpr int NON_REMOTE_ID = -1;
40
41 QString fileName = "";
42 FileFormat fileFormat = CockatriceFormat;
43 int remoteDeckId = NON_REMOTE_ID;
44 };
45
49 static const QStringList ACCEPTED_FILE_EXTENSIONS;
50
54 static const QStringList FILE_NAME_FILTERS;
55
56 enum DecklistWebsite
57 {
58 DecklistOrg,
59 DecklistXyz
60 };
61
62private:
63 DeckList *deckList;
64 LoadInfo lastLoadInfo;
65
66public:
67 DeckLoader(QObject *parent);
68 DeckLoader(QObject *parent, DeckList *_deckList);
69 DeckLoader(const DeckLoader &) = delete;
70 DeckLoader &operator=(const DeckLoader &) = delete;
71
72 const LoadInfo &getLastLoadInfo() const
73 {
74 return lastLoadInfo;
75 }
76
77 void setLastLoadInfo(const LoadInfo &info)
78 {
79 lastLoadInfo = info;
80 }
81
82 [[nodiscard]] bool hasNotBeenLoaded() const
83 {
84 return lastLoadInfo.fileName.isEmpty() && lastLoadInfo.remoteDeckId == LoadInfo::NON_REMOTE_ID;
85 }
86
87 static void clearSetNamesAndNumbers(const DeckList *deckList);
88 static FileFormat getFormatFromName(const QString &fileName);
89
90 bool loadFromFile(const QString &fileName, FileFormat fmt, bool userRequest = false);
91 bool loadFromFileAsync(const QString &fileName, FileFormat fmt, bool userRequest);
92 bool loadFromRemote(const QString &nativeString, int remoteDeckId);
93 bool saveToFile(const QString &fileName, FileFormat fmt);
94 bool updateLastLoadedTimestamp(const QString &fileName, FileFormat fmt);
95
96 static QString exportDeckToDecklist(const DeckList *deckList, DecklistWebsite website);
97
98 static void setProviderIdToPreferredPrinting(const DeckList *deckList);
99 static void resolveSetNameAndNumberToProviderID(const DeckList *deckList);
100
101 static void saveToClipboard(const DeckList *deckList, bool addComments = true, bool addSetNameAndNumber = true);
102 static bool saveToStream_Plain(QTextStream &out,
103 const DeckList *deckList,
104 bool addComments = true,
105 bool addSetNameAndNumber = true);
106
112 static void printDeckList(QPrinter *printer, const DeckList *deckList);
113
114 bool convertToCockatriceFormat(QString fileName);
115
116 DeckList *getDeckList()
117 {
118 return deckList;
119 }
120
121private:
122 static void printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node);
123 static void saveToStream_DeckHeader(QTextStream &out, const DeckList *deckList);
124
125 static void saveToStream_DeckZone(QTextStream &out,
126 const InnerDecklistNode *zoneNode,
127 bool addComments = true,
128 bool addSetNameAndNumber = true);
129 static void saveToStream_DeckZoneCards(QTextStream &out,
130 const InnerDecklistNode *zoneNode,
131 QList<DecklistCardNode *> cards,
132 bool addComments = true,
133 bool addSetNameAndNumber = true);
134
135 [[nodiscard]] static QString getCardZoneFromName(const QString &cardName, QString currentZoneName);
136 [[nodiscard]] static QString getCompleteCardName(const QString &cardName);
137};
138
139#endif
Represents a complete deck, including metadata, zones, cards, and sideboard plans.
Definition deck_list.h:127
Represents a container node in the deck list hierarchy (zones and groupings).
Definition inner_deck_list_node.h:62
Q_LOGGING_CATEGORY(TappedOutInterfaceLog, "tapped_out_interface")