aboutsummaryrefslogtreecommitdiff
path: root/launcher/ui
diff options
context:
space:
mode:
authorSefa Eyeoglu <contact@scrumplex.net>2022-03-29 11:24:12 +0200
committerGitHub <noreply@github.com>2022-03-29 11:24:12 +0200
commit5f2e7683764461dd70e5a3593a6bab1cc3e6146d (patch)
tree2d16bd4de9b99e22270d7f1614b525c44afe1833 /launcher/ui
parent575c92ec479e555fe7cb5ead98794b78c260f820 (diff)
parentd00c320c0041421e67d5d8ec6deb4427d0f8020c (diff)
downloadPrismLauncher-5f2e7683764461dd70e5a3593a6bab1cc3e6146d.tar.gz
PrismLauncher-5f2e7683764461dd70e5a3593a6bab1cc3e6146d.tar.bz2
PrismLauncher-5f2e7683764461dd70e5a3593a6bab1cc3e6146d.zip
Merge pull request #356 from flowln/version_optimize
Improve mod versions request to Modrinth
Diffstat (limited to 'launcher/ui')
-rw-r--r--launcher/ui/pages/modplatform/ModModel.cpp33
-rw-r--r--launcher/ui/pages/modplatform/ModModel.h3
2 files changed, 24 insertions, 12 deletions
diff --git a/launcher/ui/pages/modplatform/ModModel.cpp b/launcher/ui/pages/modplatform/ModModel.cpp
index cc3c5326..0a147584 100644
--- a/launcher/ui/pages/modplatform/ModModel.cpp
+++ b/launcher/ui/pages/modplatform/ModModel.cpp
@@ -16,7 +16,6 @@ auto ListModel::debugName() const -> QString
return m_parent->debugName();
}
-
/******** Make data requests ********/
void ListModel::fetchMore(const QModelIndex& parent)
@@ -61,19 +60,14 @@ auto ListModel::data(const QModelIndex& index, int role) const -> QVariant
void ListModel::requestModVersions(ModPlatform::IndexedPack const& current)
{
- m_parent->apiProvider()->getVersions(this, current.addonId.toString());
+ m_parent->apiProvider()->getVersions(this,
+ { current.addonId.toString(), getMineVersions(), hasFabric() ? ModAPI::ModLoaderType::Fabric : ModAPI::ModLoaderType::Forge });
}
void ListModel::performPaginatedSearch()
{
- QString mcVersion = (dynamic_cast<MinecraftInstance*>((dynamic_cast<ModPage*>(parent()))->m_instance))->getPackProfile()->getComponentVersion("net.minecraft");
- bool hasFabric = !(dynamic_cast<MinecraftInstance*>((dynamic_cast<ModPage*>(parent()))->m_instance))
- ->getPackProfile()
- ->getComponentVersion("net.fabricmc.fabric-loader")
- .isEmpty();
-
- m_parent->apiProvider()->searchMods(
- this, { nextSearchOffset, currentSearchTerm, getSorts()[currentSort], hasFabric ? ModAPI::Fabric : ModAPI::Forge, mcVersion });
+ m_parent->apiProvider()->searchMods(this,
+ { nextSearchOffset, currentSearchTerm, getSorts()[currentSort], hasFabric() ? ModAPI::Fabric : ModAPI::Forge, getMineVersions().at(0) });
}
void ListModel::searchWithTerm(const QString& term, const int sort)
@@ -131,7 +125,6 @@ void ListModel::requestLogo(QString logo, QString url)
m_loadingLogos.append(logo);
}
-
/******** Request callbacks ********/
void ListModel::logoLoaded(QString logo, QIcon out)
@@ -208,7 +201,7 @@ void ListModel::versionRequestSucceeded(QJsonDocument doc, QString addonId)
{
auto& current = m_parent->getCurrent();
if (addonId != current.addonId) { return; }
-
+
QJsonArray arr = doc.array();
try {
loadIndexedPackVersions(current, arr);
@@ -221,3 +214,19 @@ void ListModel::versionRequestSucceeded(QJsonDocument doc, QString addonId)
}
} // namespace ModPlatform
+
+/******** Helpers ********/
+auto ModPlatform::ListModel::hasFabric() const -> bool
+{
+ return !(dynamic_cast<MinecraftInstance*>((dynamic_cast<ModPage*>(parent()))->m_instance))
+ ->getPackProfile()
+ ->getComponentVersion("net.fabricmc.fabric-loader")
+ .isEmpty();
+}
+
+auto ModPlatform::ListModel::getMineVersions() const -> QList<QString>
+{
+ return { (dynamic_cast<MinecraftInstance*>((dynamic_cast<ModPage*>(parent()))->m_instance))
+ ->getPackProfile()
+ ->getComponentVersion("net.minecraft") };
+}
diff --git a/launcher/ui/pages/modplatform/ModModel.h b/launcher/ui/pages/modplatform/ModModel.h
index 02be6049..64cfa71e 100644
--- a/launcher/ui/pages/modplatform/ModModel.h
+++ b/launcher/ui/pages/modplatform/ModModel.h
@@ -62,6 +62,9 @@ class ListModel : public QAbstractListModel {
void requestLogo(QString file, QString url);
+ inline auto hasFabric() const -> bool;
+ inline auto getMineVersions() const -> QList<QString>;
+
protected:
ModPage* m_parent;