Data pack management

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
TheKodeToad
2023-11-28 12:30:13 +00:00
parent 40cfa145ee
commit 284e536e81
29 changed files with 943 additions and 15 deletions

View File

@@ -24,6 +24,7 @@
#include "Resource.h"
#include <QMutex>
#include <QPixmapCache>
class Version;
@@ -48,12 +49,18 @@ class DataPack : public Resource {
/** Gets the description of the data pack. */
[[nodiscard]] QString description() const { return m_description; }
/** Gets the image of the resource pack, converted to a QPixmap for drawing, and scaled to size. */
[[nodiscard]] QPixmap image(QSize size, Qt::AspectRatioMode mode = Qt::AspectRatioMode::IgnoreAspectRatio) const;
/** Thread-safe. */
void setPackFormat(int new_format_id);
/** Thread-safe. */
void setDescription(QString new_description);
/** Thread-safe. */
void setImage(QImage new_image) const;
bool valid() const override;
[[nodiscard]] auto compare(Resource const& other, SortType type) const -> std::pair<int, bool> override;
@@ -70,4 +77,14 @@ class DataPack : public Resource {
/** The data pack's description, as defined in the pack.mcmeta file.
*/
QString m_description;
/** The data pack's image file cache key, for access in the QPixmapCache global instance.
*
* The 'was_ever_used' state simply identifies whether the key was never inserted on the cache (true),
* so as to tell whether a cache entry is inexistent or if it was just evicted from the cache.
*/
struct {
QPixmapCache::Key key;
bool was_ever_used = false;
} mutable m_pack_image_cache_key;
};