aboutsummaryrefslogtreecommitdiff
path: root/launcher/minecraft
diff options
context:
space:
mode:
authorSefa Eyeoglu <contact@scrumplex.net>2022-02-20 20:22:12 +0100
committerSefa Eyeoglu <contact@scrumplex.net>2022-04-07 18:46:00 +0200
commit9349232bd4e6879ab11a3e8aaf5b3e056fdca2d9 (patch)
tree4da0325ed7502671c421155894a816b3dd3bd635 /launcher/minecraft
parent9eb9ddc6680244f2c10fa3ac50fbbeffefd2db29 (diff)
downloadPrismLauncher-9349232bd4e6879ab11a3e8aaf5b3e056fdca2d9.tar.gz
PrismLauncher-9349232bd4e6879ab11a3e8aaf5b3e056fdca2d9.tar.bz2
PrismLauncher-9349232bd4e6879ab11a3e8aaf5b3e056fdca2d9.zip
refactor: dynamically get best version for intermediary mappings
Diffstat (limited to 'launcher/minecraft')
-rw-r--r--launcher/minecraft/ComponentUpdateTask.cpp49
-rw-r--r--launcher/minecraft/ComponentUpdateTask.h2
2 files changed, 32 insertions, 19 deletions
diff --git a/launcher/minecraft/ComponentUpdateTask.cpp b/launcher/minecraft/ComponentUpdateTask.cpp
index a856662a..a0559232 100644
--- a/launcher/minecraft/ComponentUpdateTask.cpp
+++ b/launcher/minecraft/ComponentUpdateTask.cpp
@@ -2,7 +2,6 @@
#include "PackProfile_p.h"
#include "PackProfile.h"
-#include "Component.h"
#include "meta/Index.h"
#include "meta/VersionList.h"
#include "meta/Version.h"
@@ -495,6 +494,31 @@ static bool getTrivialComponentChanges(const ComponentIndex & index, const Requi
return succeeded;
}
+QString ComponentUpdateTask::findBestComponentVersion(const ComponentPtr component)
+{
+ auto & components = d->m_list->d->components;
+ auto versions = component->getVersionList();
+ versions->load(d->netmode);
+
+ for (auto & version : versions->versions()) {
+ if (version->isRecommended()) { // only look at recommended versions
+ bool requirementsMet = true;
+ for (auto req : version->requires()) {
+ auto requirementMet = std::any_of(components.begin(), components.end(), [&req](ComponentPtr & cmp){
+ return cmp->getID() == req.uid && cmp->getVersion() == req.equalsVersion;
+ });
+ if (!requirementMet) {
+ requirementsMet = false;
+ }
+ }
+
+ if (requirementsMet) // return first recommended version that meets all requirements
+ return version->version();
+ }
+ }
+ return nullptr;
+}
+
// FIXME, TODO: decouple dependency resolution from loading
// FIXME: This works directly with the PackProfile internals. It shouldn't! It needs richer data types than PackProfile uses.
// FIXME: throw all this away and use a graph
@@ -591,27 +615,14 @@ void ComponentUpdateTask::resolveDependencies(bool checkOnly)
{
component->m_version = "3.1.2";
}
- else if (add.uid == "net.fabricmc.intermediary")
- {
- auto minecraft = std::find_if(components.begin(), components.end(), [](ComponentPtr & cmp){
- return cmp->getID() == "net.minecraft";
- });
- if(minecraft != components.end()) {
- component->m_version = (*minecraft)->getVersion();
- }
- }
- else if (add.uid == "org.quiltmc.quilt-mappings")
+// HACK HACK HACK HACK FIXME: this is a placeholder for deciding what version to use. For now, it is hardcoded.
+// ############################################################################################################
+// below is not ugly anymore
+ else if (add.uid == "net.fabricmc.intermediary" || add.uid == "org.quiltmc.quilt-mappings")
{
- auto minecraft = std::find_if(components.begin(), components.end(), [](ComponentPtr & cmp){
- return cmp->getID() == "net.minecraft";
- });
- if(minecraft != components.end()) {
- component->m_version = (*minecraft)->getVersion() + "+build.1";
- }
+ component->m_version = findBestComponentVersion(component);
}
}
-// HACK HACK HACK HACK FIXME: this is a placeholder for deciding what version to use. For now, it is hardcoded.
-// ############################################################################################################
}
component->m_dependencyOnly = true;
// FIXME: this should not work directly with the component list
diff --git a/launcher/minecraft/ComponentUpdateTask.h b/launcher/minecraft/ComponentUpdateTask.h
index 4274cabb..4fcbbca8 100644
--- a/launcher/minecraft/ComponentUpdateTask.h
+++ b/launcher/minecraft/ComponentUpdateTask.h
@@ -2,6 +2,7 @@
#include "tasks/Task.h"
#include "net/Mode.h"
+#include "Component.h"
#include <memory>
class PackProfile;
@@ -26,6 +27,7 @@ protected:
private:
void loadComponents();
+ QString findBestComponentVersion(ComponentPtr component);
void resolveDependencies(bool checkOnly);
void remoteLoadSucceeded(size_t index);