diff options
author | Trial97 <alexandru.tripon97@gmail.com> | 2023-06-23 20:01:17 +0300 |
---|---|---|
committer | Trial97 <alexandru.tripon97@gmail.com> | 2023-06-23 20:01:17 +0300 |
commit | 69c709b05a90f342cc9d1f9337457bb5519a87a9 (patch) | |
tree | 4ff1cbe8123b627bfb171c119b3adc4e2ddaf89b /launcher/minecraft/mod/Mod.cpp | |
parent | 3e3be9ae6f902cc292ee26e4d330b078ddbb2a46 (diff) | |
parent | 046d510134a0061c0a1fa89fda80355c9e2f11ff (diff) | |
download | PrismLauncher-69c709b05a90f342cc9d1f9337457bb5519a87a9.tar.gz PrismLauncher-69c709b05a90f342cc9d1f9337457bb5519a87a9.tar.bz2 PrismLauncher-69c709b05a90f342cc9d1f9337457bb5519a87a9.zip |
Merge branch 'develop' of https://github.com/PrismLauncher/PrismLauncher into develop
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
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 c495cd47..e613ddeb 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; @@ -201,7 +203,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> { @@ -210,6 +215,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(); |