aboutsummaryrefslogtreecommitdiff
path: root/launcher/minecraft/mod/Mod.cpp
diff options
context:
space:
mode:
authorTrial97 <alexandru.tripon97@gmail.com>2023-06-25 10:12:29 +0300
committerTrial97 <alexandru.tripon97@gmail.com>2023-06-25 10:12:29 +0300
commit54d7477679d4be05ce69dfe7d3ff21b0de46e8af (patch)
tree8a3eb84a1d352ed4c57e7f06cd9772f1de08e384 /launcher/minecraft/mod/Mod.cpp
parentba609f3600e17704f358b28dd3d5ee14319cc98c (diff)
parentbcf45c74a1b0b3389c05927637bf8aa95b8e43cf (diff)
downloadPrismLauncher-54d7477679d4be05ce69dfe7d3ff21b0de46e8af.tar.gz
PrismLauncher-54d7477679d4be05ce69dfe7d3ff21b0de46e8af.tar.bz2
PrismLauncher-54d7477679d4be05ce69dfe7d3ff21b0de46e8af.zip
Merge branch 'develop' of https://github.com/PrismLauncher/PrismLauncher into visit_mod_page
Diffstat (limited to 'launcher/minecraft/mod/Mod.cpp')
-rw-r--r--launcher/minecraft/mod/Mod.cpp57
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();