diff options
author | PandaNinjas <admin@malwarefight.wip.la> | 2023-07-04 16:41:34 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-04 16:41:34 -0400 |
commit | 4509fde410beab8687d605d0a7fd39038ab94183 (patch) | |
tree | 1835295bdd4a1293a3547f2abef6e0b4cd364278 /launcher/minecraft/mod/Mod.cpp | |
parent | 34cf28712c254ba378bdbf728471d0dfbb4ab58f (diff) | |
parent | dedc9e4edc2769c62f33b6564f3009414245d9f3 (diff) | |
download | PrismLauncher-4509fde410beab8687d605d0a7fd39038ab94183.tar.gz PrismLauncher-4509fde410beab8687d605d0a7fd39038ab94183.tar.bz2 PrismLauncher-4509fde410beab8687d605d0a7fd39038ab94183.zip |
Merge branch 'develop' into fix-implicit-fallthrough
Signed-off-by: PandaNinjas <admin@malwarefight.wip.la>
Diffstat (limited to 'launcher/minecraft/mod/Mod.cpp')
-rw-r--r-- | launcher/minecraft/mod/Mod.cpp | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/launcher/minecraft/mod/Mod.cpp b/launcher/minecraft/mod/Mod.cpp index 6cda6185..f8af9d8f 100644 --- a/launcher/minecraft/mod/Mod.cpp +++ b/launcher/minecraft/mod/Mod.cpp @@ -41,9 +41,11 @@ #include <QString> #include <QRegularExpression> +#include "MTPixmapCache.h" #include "MetadataHandler.h" #include "Version.h" #include "minecraft/mod/ModDetails.h" +#include "minecraft/mod/tasks/LocalModParseTask.h" static ModPlatform::ProviderCapabilities ProviderCaps; @@ -204,7 +206,10 @@ void Mod::finishResolvingWithDetails(ModDetails&& details) m_local_details = std::move(details); if (metadata) setMetadata(std::move(metadata)); -}; + if (!iconPath().isEmpty()) { + m_pack_image_cache_key.was_read_attempt = false; + } +} auto Mod::provider() const -> std::optional<QString> { @@ -213,6 +218,56 @@ auto Mod::provider() const -> std::optional<QString> return {}; } +auto Mod::licenses() const -> const QList<ModLicense>& +{ + return details().licenses; +} + + auto Mod::issueTracker() const -> QString +{ + return details().issue_tracker; +} + +void Mod::setIcon(QImage new_image) const +{ + QMutexLocker locker(&m_data_lock); + + Q_ASSERT(!new_image.isNull()); + + if (m_pack_image_cache_key.key.isValid()) + PixmapCache::remove(m_pack_image_cache_key.key); + + // scale the image to avoid flooding the pixmapcache + auto pixmap = QPixmap::fromImage(new_image.scaled({64, 64}, Qt::AspectRatioMode::KeepAspectRatioByExpanding)); + + m_pack_image_cache_key.key = PixmapCache::insert(pixmap); + m_pack_image_cache_key.was_ever_used = true; + m_pack_image_cache_key.was_read_attempt = true; +} + +QPixmap Mod::icon(QSize size, Qt::AspectRatioMode mode) const +{ + QPixmap cached_image; + if (PixmapCache::find(m_pack_image_cache_key.key, &cached_image)) { + if (size.isNull()) + return cached_image; + return cached_image.scaled(size, mode); + } + + // No valid image we can get + if ((!m_pack_image_cache_key.was_ever_used && m_pack_image_cache_key.was_read_attempt) || iconPath().isEmpty()) + return {}; + + if (m_pack_image_cache_key.was_ever_used) { + qDebug() << "Mod" << name() << "Had it's icon evicted form the cache. reloading..."; + PixmapCache::markCacheMissByEviciton(); + } + // Image got evicted from the cache or an attempt to load it has not been made. load it and retry. + m_pack_image_cache_key.was_read_attempt = true; + ModUtils::loadIconFile(*this); + return icon(size); +} + bool Mod::valid() const { return !m_local_details.mod_id.isEmpty(); |