diff options
author | flow <flowlnlnln@gmail.com> | 2022-09-07 08:30:36 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-07 08:30:36 -0300 |
commit | 333dbca01ed15103b5a36a58a9faad7464ed1582 (patch) | |
tree | 744421e688d8772a9be967de4c3c6fe1cd5230cf /launcher/minecraft/mod/ResourcePack.h | |
parent | 1b0ca476824ad3d704de70720184d2f1e194d2f5 (diff) | |
parent | bedd3c50b6d3c399ccb243c9ea1a62d9b786389f (diff) | |
download | PrismLauncher-333dbca01ed15103b5a36a58a9faad7464ed1582.tar.gz PrismLauncher-333dbca01ed15103b5a36a58a9faad7464ed1582.tar.bz2 PrismLauncher-333dbca01ed15103b5a36a58a9faad7464ed1582.zip |
Merge pull request #1105 from flowln/better_resource_packs
Add basic resource pack parsing and fix issues
Diffstat (limited to 'launcher/minecraft/mod/ResourcePack.h')
-rw-r--r-- | launcher/minecraft/mod/ResourcePack.h | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/launcher/minecraft/mod/ResourcePack.h b/launcher/minecraft/mod/ResourcePack.h index c2cc8690..03121908 100644 --- a/launcher/minecraft/mod/ResourcePack.h +++ b/launcher/minecraft/mod/ResourcePack.h @@ -2,12 +2,68 @@ #include "Resource.h" +#include <QImage> +#include <QMutex> +#include <QPixmap> +#include <QPixmapCache> + +class Version; + +/* TODO: + * + * Store localized descriptions + * */ + class ResourcePack : public Resource { Q_OBJECT - public: + public: using Ptr = shared_qobject_ptr<Resource>; ResourcePack(QObject* parent = nullptr) : Resource(parent) {} ResourcePack(QFileInfo file_info) : Resource(file_info) {} + /** Gets the numerical ID of the pack format. */ + [[nodiscard]] int packFormat() const { return m_pack_format; } + /** Gets, respectively, the lower and upper versions supported by the set pack format. */ + [[nodiscard]] std::pair<Version, Version> compatibleVersions() const; + + /** Gets the description of the resource 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); + + /** Thread-safe. */ + void setPackFormat(int new_format_id); + + /** Thread-safe. */ + void setDescription(QString new_description); + + /** Thread-safe. */ + void setImage(QImage new_image); + + [[nodiscard]] auto compare(Resource const& other, SortType type) const -> std::pair<int, bool> override; + [[nodiscard]] bool applyFilter(QRegularExpression filter) const override; + + protected: + mutable QMutex m_data_lock; + + /* The 'version' of a resource pack, as defined in the pack.mcmeta file. + * See https://minecraft.fandom.com/wiki/Tutorials/Creating_a_resource_pack#Formatting_pack.mcmeta + */ + int m_pack_format = 0; + + /** The resource pack's description, as defined in the pack.mcmeta file. + */ + QString m_description; + + /** The resource 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; + } m_pack_image_cache_key; }; |