fix: use more robust method of finding matches for major version
This uses the proper version list to find all MC versions matching the
major number (_don't say anything about SemVer_ 🔫).
Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
cf8a76be6b
commit
2666beafb1
@ -140,6 +140,13 @@ VersionPtr VersionList::getVersion(const QString &version)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool VersionList::hasVersion(QString version) const
|
||||||
|
{
|
||||||
|
auto ver = std::find_if(m_versions.constBegin(), m_versions.constEnd(),
|
||||||
|
[&](Meta::VersionPtr const& a){ return a->version() == version; });
|
||||||
|
return (ver != m_versions.constEnd());
|
||||||
|
}
|
||||||
|
|
||||||
void VersionList::setName(const QString &name)
|
void VersionList::setName(const QString &name)
|
||||||
{
|
{
|
||||||
m_name = name;
|
m_name = name;
|
||||||
|
@ -66,6 +66,7 @@ public:
|
|||||||
QString humanReadable() const;
|
QString humanReadable() const;
|
||||||
|
|
||||||
VersionPtr getVersion(const QString &version);
|
VersionPtr getVersion(const QString &version);
|
||||||
|
bool hasVersion(QString version) const;
|
||||||
|
|
||||||
QVector<VersionPtr> versions() const
|
QVector<VersionPtr> versions() const
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include "ModFilterWidget.h"
|
#include "ModFilterWidget.h"
|
||||||
#include "ui_ModFilterWidget.h"
|
#include "ui_ModFilterWidget.h"
|
||||||
|
|
||||||
|
#include "Application.h"
|
||||||
|
|
||||||
ModFilterWidget::ModFilterWidget(Version def, QWidget* parent)
|
ModFilterWidget::ModFilterWidget(Version def, QWidget* parent)
|
||||||
: QTabWidget(parent), m_filter(new Filter()), ui(new Ui::ModFilterWidget)
|
: QTabWidget(parent), m_filter(new Filter()), ui(new Ui::ModFilterWidget)
|
||||||
{
|
{
|
||||||
@ -16,6 +18,24 @@ ModFilterWidget::ModFilterWidget(Version def, QWidget* parent)
|
|||||||
|
|
||||||
m_filter->versions.push_front(def);
|
m_filter->versions.push_front(def);
|
||||||
|
|
||||||
|
m_version_list = APPLICATION->metadataIndex()->get("net.minecraft");
|
||||||
|
if (!m_version_list->isLoaded()) {
|
||||||
|
QEventLoop load_version_list_loop;
|
||||||
|
|
||||||
|
auto task = m_version_list->getLoadTask();
|
||||||
|
|
||||||
|
connect(task.get(), &Task::failed, [this]{
|
||||||
|
ui->majorVersionButton->setText(tr("Major version match (failed to get version index)"));
|
||||||
|
disableVersionButton(VersionButtonID::Major);
|
||||||
|
});
|
||||||
|
connect(task.get(), &Task::finished, &load_version_list_loop, &QEventLoop::quit);
|
||||||
|
|
||||||
|
if (!task->isRunning())
|
||||||
|
task->start();
|
||||||
|
|
||||||
|
load_version_list_loop.exec();
|
||||||
|
}
|
||||||
|
|
||||||
setHidden(true);
|
setHidden(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +96,7 @@ void ModFilterWidget::onVersionFilterChanged(int id)
|
|||||||
//ui->lowerVersionComboBox->setEnabled(id == VersionButtonID::Between);
|
//ui->lowerVersionComboBox->setEnabled(id == VersionButtonID::Between);
|
||||||
//ui->upperVersionComboBox->setEnabled(id == VersionButtonID::Between);
|
//ui->upperVersionComboBox->setEnabled(id == VersionButtonID::Between);
|
||||||
|
|
||||||
int index = 0;
|
int index = 1;
|
||||||
|
|
||||||
auto cast_id = (VersionButtonID) id;
|
auto cast_id = (VersionButtonID) id;
|
||||||
if (cast_id != m_version_id) {
|
if (cast_id != m_version_id) {
|
||||||
@ -93,10 +113,15 @@ void ModFilterWidget::onVersionFilterChanged(int id)
|
|||||||
break;
|
break;
|
||||||
case(VersionButtonID::Major): {
|
case(VersionButtonID::Major): {
|
||||||
auto versionSplit = mcVersionStr().split(".");
|
auto versionSplit = mcVersionStr().split(".");
|
||||||
for(auto i = Version(QString("%1.%2").arg(versionSplit[0], versionSplit[1])); i <= mcVersion(); index++){
|
|
||||||
m_filter->versions.push_front(i);
|
auto major_version = QString("%1.%2").arg(versionSplit[0], versionSplit[1]);
|
||||||
i = Version(QString("%1.%2.%3").arg(versionSplit[0], versionSplit[1], QString("%1").arg(index)));
|
QString version_str = major_version;
|
||||||
|
|
||||||
|
while (m_version_list->hasVersion(version_str)) {
|
||||||
|
m_filter->versions.emplace_back(version_str);
|
||||||
|
version_str = QString("%1.%2").arg(major_version, QString::number(index++));
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(VersionButtonID::All):
|
case(VersionButtonID::All):
|
||||||
|
@ -4,6 +4,10 @@
|
|||||||
#include <QButtonGroup>
|
#include <QButtonGroup>
|
||||||
|
|
||||||
#include "Version.h"
|
#include "Version.h"
|
||||||
|
|
||||||
|
#include "meta/Index.h"
|
||||||
|
#include "meta/VersionList.h"
|
||||||
|
|
||||||
#include "minecraft/MinecraftInstance.h"
|
#include "minecraft/MinecraftInstance.h"
|
||||||
#include "minecraft/PackProfile.h"
|
#include "minecraft/PackProfile.h"
|
||||||
|
|
||||||
@ -61,8 +65,12 @@ private:
|
|||||||
|
|
||||||
MinecraftInstance* m_instance = nullptr;
|
MinecraftInstance* m_instance = nullptr;
|
||||||
|
|
||||||
|
|
||||||
|
/* Version stuff */
|
||||||
QButtonGroup m_mcVersion_buttons;
|
QButtonGroup m_mcVersion_buttons;
|
||||||
|
|
||||||
|
Meta::VersionListPtr m_version_list;
|
||||||
|
|
||||||
/* Used to tell if the filter was changed since the last getFilter() call */
|
/* Used to tell if the filter was changed since the last getFilter() call */
|
||||||
VersionButtonID m_last_version_id = VersionButtonID::Strict;
|
VersionButtonID m_last_version_id = VersionButtonID::Strict;
|
||||||
VersionButtonID m_version_id = VersionButtonID::Strict;
|
VersionButtonID m_version_id = VersionButtonID::Strict;
|
||||||
|
Loading…
Reference in New Issue
Block a user