2022-08-10 23:18:34 +05:30
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Resource.h"
|
|
|
|
|
2022-08-29 17:45:06 +05:30
|
|
|
#include <QImage>
|
2022-08-29 06:59:52 +05:30
|
|
|
#include <QMutex>
|
2022-08-29 17:45:06 +05:30
|
|
|
#include <QPixmap>
|
2022-08-31 02:36:13 +05:30
|
|
|
#include <QPixmapCache>
|
2022-08-29 06:59:52 +05:30
|
|
|
|
|
|
|
class Version;
|
|
|
|
|
|
|
|
/* TODO:
|
|
|
|
*
|
|
|
|
* Store localized descriptions
|
|
|
|
* */
|
|
|
|
|
2022-08-10 23:18:34 +05:30
|
|
|
class ResourcePack : public Resource {
|
|
|
|
Q_OBJECT
|
2022-08-29 06:59:52 +05:30
|
|
|
public:
|
2022-08-10 23:18:34 +05:30
|
|
|
using Ptr = shared_qobject_ptr<Resource>;
|
|
|
|
|
|
|
|
ResourcePack(QObject* parent = nullptr) : Resource(parent) {}
|
|
|
|
ResourcePack(QFileInfo file_info) : Resource(file_info) {}
|
|
|
|
|
2022-08-29 06:59:52 +05:30
|
|
|
/** 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; }
|
|
|
|
|
2022-08-29 17:45:06 +05:30
|
|
|
/** Gets the image of the resource pack, converted to a QPixmap for drawing, and scaled to size. */
|
2022-08-31 02:36:13 +05:30
|
|
|
[[nodiscard]] QPixmap image(QSize size);
|
2022-08-29 17:45:06 +05:30
|
|
|
|
2022-08-29 06:59:52 +05:30
|
|
|
/** Thread-safe. */
|
|
|
|
void setPackFormat(int new_format_id);
|
|
|
|
|
|
|
|
/** Thread-safe. */
|
|
|
|
void setDescription(QString new_description);
|
|
|
|
|
2022-08-29 17:45:06 +05:30
|
|
|
/** Thread-safe. */
|
|
|
|
void setImage(QImage new_image);
|
|
|
|
|
2022-08-29 07:22:29 +05:30
|
|
|
[[nodiscard]] auto compare(Resource const& other, SortType type) const -> std::pair<int, bool> override;
|
2022-08-29 07:28:43 +05:30
|
|
|
[[nodiscard]] bool applyFilter(QRegularExpression filter) const override;
|
2022-08-29 07:22:29 +05:30
|
|
|
|
2022-08-29 06:59:52 +05:30
|
|
|
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;
|
2022-08-29 17:45:06 +05:30
|
|
|
|
2022-08-31 02:36:13 +05:30
|
|
|
/** 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.
|
2022-08-29 17:45:06 +05:30
|
|
|
*/
|
2022-08-31 02:36:13 +05:30
|
|
|
struct {
|
|
|
|
QPixmapCache::Key key;
|
|
|
|
bool was_ever_used = false;
|
|
|
|
} m_pack_image_cache_key;
|
2022-08-10 23:18:34 +05:30
|
|
|
};
|