feat: add verion_type / release_type to IndexedVersion
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
parent
f24211e8b5
commit
c156034069
@ -24,6 +24,56 @@
|
|||||||
|
|
||||||
namespace ModPlatform {
|
namespace ModPlatform {
|
||||||
|
|
||||||
|
static const QMap<QString, IndexedVersionType::Enum> s_indexed_version_type_names = {
|
||||||
|
{"release", IndexedVersionType::Enum::Release},
|
||||||
|
{"beta", IndexedVersionType::Enum::Beta},
|
||||||
|
{"alpha", IndexedVersionType::Enum::Alpha}
|
||||||
|
};
|
||||||
|
|
||||||
|
IndexedVersionType::IndexedVersionType(const QString& type): IndexedVersionType(enumFromString(type))
|
||||||
|
{}
|
||||||
|
|
||||||
|
IndexedVersionType::IndexedVersionType(int type)
|
||||||
|
{
|
||||||
|
m_type = static_cast<IndexedVersionType::Enum>(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
IndexedVersionType::IndexedVersionType(const IndexedVersionType::Enum& type)
|
||||||
|
{
|
||||||
|
m_type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
IndexedVersionType::IndexedVersionType(const IndexedVersionType& other)
|
||||||
|
{
|
||||||
|
m_type = other.m_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString IndexedVersionType::toString (const IndexedVersionType::Enum& type)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case IndexedVersionType::Enum::Release:
|
||||||
|
return "release";
|
||||||
|
case IndexedVersionType::Enum::Beta:
|
||||||
|
return "beta";
|
||||||
|
case IndexedVersionType::Enum::Alpha:
|
||||||
|
return "alpha";
|
||||||
|
case IndexedVersionType::Enum::UNKNOWN:
|
||||||
|
default:
|
||||||
|
return "unknown";
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const IndexedVersionType::Enum IndexedVersionType::enumFromString(const QString& type)
|
||||||
|
{
|
||||||
|
auto found = s_indexed_version_type_names.constFind(type);
|
||||||
|
if (found != s_indexed_version_type_names.constEnd()) {
|
||||||
|
return *found;
|
||||||
|
} else {
|
||||||
|
return IndexedVersionType::Enum::UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto ProviderCapabilities::name(ResourceProvider p) -> const char*
|
auto ProviderCapabilities::name(ResourceProvider p) -> const char*
|
||||||
{
|
{
|
||||||
switch (p) {
|
switch (p) {
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
class QIODevice;
|
class QIODevice;
|
||||||
|
|
||||||
@ -51,11 +52,34 @@ struct DonationData {
|
|||||||
QString url;
|
QString url;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct IndexedVersionType {
|
||||||
|
enum class Enum {
|
||||||
|
Release = 1,
|
||||||
|
Beta,
|
||||||
|
Alpha,
|
||||||
|
UNKNOWN
|
||||||
|
};
|
||||||
|
IndexedVersionType(const QString& type);
|
||||||
|
IndexedVersionType(int type);
|
||||||
|
IndexedVersionType(const IndexedVersionType::Enum& type);
|
||||||
|
IndexedVersionType(const IndexedVersionType& type);
|
||||||
|
static const QString toString (const IndexedVersionType::Enum& type);
|
||||||
|
static const IndexedVersionType::Enum enumFromString(const QString& type);
|
||||||
|
bool isValid() const {return m_type != IndexedVersionType::Enum::UNKNOWN; }
|
||||||
|
bool operator==(const IndexedVersionType& other) const { return m_type == other.m_type; }
|
||||||
|
bool operator==(const IndexedVersionType::Enum& type) const { return m_type == type; }
|
||||||
|
bool operator<(const IndexedVersionType& other) const { return m_type < other.m_type; }
|
||||||
|
bool operator<(const IndexedVersionType::Enum& type) const { return m_type < type; }
|
||||||
|
|
||||||
|
IndexedVersionType::Enum m_type;
|
||||||
|
};
|
||||||
|
|
||||||
struct IndexedVersion {
|
struct IndexedVersion {
|
||||||
QVariant addonId;
|
QVariant addonId;
|
||||||
QVariant fileId;
|
QVariant fileId;
|
||||||
QString version;
|
QString version;
|
||||||
QString version_number = {};
|
QString version_number = {};
|
||||||
|
std::optional<IndexedVersionType> verison_type = {};
|
||||||
QStringList mcVersion;
|
QStringList mcVersion;
|
||||||
QString downloadUrl;
|
QString downloadUrl;
|
||||||
QString date;
|
QString date;
|
||||||
|
@ -144,7 +144,10 @@ auto FlameAPI::getLatestVersion(VersionSearchArgs&& args) -> ModPlatform::Indexe
|
|||||||
for (auto file : arr) {
|
for (auto file : arr) {
|
||||||
auto file_obj = Json::requireObject(file);
|
auto file_obj = Json::requireObject(file);
|
||||||
auto file_tmp = FlameMod::loadIndexedPackVersion(file_obj);
|
auto file_tmp = FlameMod::loadIndexedPackVersion(file_obj);
|
||||||
if(file_tmp.date > ver_tmp.date) {
|
bool better_release = true;
|
||||||
|
if (file_tmp.verison_type.has_value() && ver_tmp.verison_type.has_value())
|
||||||
|
better_release = file_tmp.verison_type.value() < ver_tmp.verison_type.value();
|
||||||
|
if(file_tmp.date > ver_tmp.date && better_release) {
|
||||||
ver_tmp = file_tmp;
|
ver_tmp = file_tmp;
|
||||||
latest_file_obj = file_obj;
|
latest_file_obj = file_obj;
|
||||||
}
|
}
|
||||||
|
@ -94,8 +94,11 @@ void FlameMod::loadIndexedPackVersions(ModPlatform::IndexedPack& pack,
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto orderSortPredicate = [](const ModPlatform::IndexedVersion& a, const ModPlatform::IndexedVersion& b) -> bool {
|
auto orderSortPredicate = [](const ModPlatform::IndexedVersion& a, const ModPlatform::IndexedVersion& b) -> bool {
|
||||||
|
bool a_better_release = true;
|
||||||
|
if (a.verison_type.has_value() && b.verison_type.has_value())
|
||||||
|
a_better_release = a.verison_type.value() < b.verison_type.value();
|
||||||
// dates are in RFC 3339 format
|
// dates are in RFC 3339 format
|
||||||
return a.date > b.date;
|
return a.date > b.date && a_better_release;
|
||||||
};
|
};
|
||||||
std::sort(unsortedVersions.begin(), unsortedVersions.end(), orderSortPredicate);
|
std::sort(unsortedVersions.begin(), unsortedVersions.end(), orderSortPredicate);
|
||||||
pack.versions = unsortedVersions;
|
pack.versions = unsortedVersions;
|
||||||
@ -123,6 +126,9 @@ auto FlameMod::loadIndexedPackVersion(QJsonObject& obj, bool load_changelog) ->
|
|||||||
file.version = Json::requireString(obj, "displayName");
|
file.version = Json::requireString(obj, "displayName");
|
||||||
file.downloadUrl = Json::ensureString(obj, "downloadUrl");
|
file.downloadUrl = Json::ensureString(obj, "downloadUrl");
|
||||||
file.fileName = Json::requireString(obj, "fileName");
|
file.fileName = Json::requireString(obj, "fileName");
|
||||||
|
auto version_type = ModPlatform::IndexedVersionType(Json::requireInteger(obj, "releaseType"));
|
||||||
|
if (version_type.isValid())
|
||||||
|
file.verison_type = version_type;
|
||||||
|
|
||||||
auto hash_list = Json::ensureArray(obj, "hashes");
|
auto hash_list = Json::ensureArray(obj, "hashes");
|
||||||
for (auto h : hash_list) {
|
for (auto h : hash_list) {
|
||||||
|
@ -109,8 +109,11 @@ void Modrinth::loadIndexedPackVersions(ModPlatform::IndexedPack& pack,
|
|||||||
unsortedVersions.append(file);
|
unsortedVersions.append(file);
|
||||||
}
|
}
|
||||||
auto orderSortPredicate = [](const ModPlatform::IndexedVersion& a, const ModPlatform::IndexedVersion& b) -> bool {
|
auto orderSortPredicate = [](const ModPlatform::IndexedVersion& a, const ModPlatform::IndexedVersion& b) -> bool {
|
||||||
|
bool a_better_release = true;
|
||||||
|
if (a.verison_type.has_value() && b.verison_type.has_value())
|
||||||
|
a_better_release = a.verison_type.value() < b.verison_type.value();
|
||||||
// dates are in RFC 3339 format
|
// dates are in RFC 3339 format
|
||||||
return a.date > b.date;
|
return a.date > b.date && a_better_release;
|
||||||
};
|
};
|
||||||
std::sort(unsortedVersions.begin(), unsortedVersions.end(), orderSortPredicate);
|
std::sort(unsortedVersions.begin(), unsortedVersions.end(), orderSortPredicate);
|
||||||
pack.versions = unsortedVersions;
|
pack.versions = unsortedVersions;
|
||||||
@ -138,6 +141,10 @@ auto Modrinth::loadIndexedPackVersion(QJsonObject& obj, QString preferred_hash_t
|
|||||||
}
|
}
|
||||||
file.version = Json::requireString(obj, "name");
|
file.version = Json::requireString(obj, "name");
|
||||||
file.version_number = Json::requireString(obj, "version_number");
|
file.version_number = Json::requireString(obj, "version_number");
|
||||||
|
auto verison_type = ModPlatform::IndexedVersionType(Json::requireString(obj, "version_type"));
|
||||||
|
if (verison_type.isValid())
|
||||||
|
file.verison_type = verison_type;
|
||||||
|
|
||||||
file.changelog = Json::requireString(obj, "changelog");
|
file.changelog = Json::requireString(obj, "changelog");
|
||||||
|
|
||||||
auto files = Json::requireArray(obj, "files");
|
auto files = Json::requireArray(obj, "files");
|
||||||
|
Loading…
Reference in New Issue
Block a user