fix(instance components): resolve instance componants when changing minecraft version

Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
Rachel Powers 2024-06-20 19:46:14 -07:00
parent 44bf0315ad
commit a791e22853
No known key found for this signature in database
GPG key ID: E10E321EB160949B
5 changed files with 103 additions and 1 deletions

View file

@ -16,6 +16,7 @@
#include "VersionList.h"
#include <QDateTime>
#include <algorithm>
#include "Application.h"
#include "Index.h"
@ -273,4 +274,31 @@ void VersionList::waitToLoad()
task->start();
ev.exec();
}
Version::Ptr VersionList::getRecommendedForParent(const QString& uid, const QString& version)
{
auto foundExplicit = std::find_if(m_versions.begin(), m_versions.end(), [uid, version](Version::Ptr ver) -> bool {
auto& reqs = ver->requiredSet();
auto parentReq = std::find_if(reqs.begin(), reqs.end(), [uid, version](const Require& req) -> bool {
return req.uid == uid && req.equalsVersion == version;
});
return parentReq != reqs.end() && ver->isRecommended();
});
if (foundExplicit != m_versions.end()) {
return *foundExplicit;
}
Version::Ptr latestCompat = nullptr;
for (auto ver : m_versions) {
auto& reqs = ver->requiredSet();
auto parentReq = std::find_if(reqs.begin(), reqs.end(), [uid, version](const Require& req) -> bool {
return req.uid == uid && req.equalsVersion == version;
});
if (parentReq != reqs.end()) {
latestCompat = getBetterVersion(latestCompat, ver);
}
}
return latestCompat;
}
} // namespace Meta