fix: do modrinth changes on flame too

Also fix a dumb moment
This commit is contained in:
flow 2022-05-13 11:42:08 -03:00 committed by flow
parent 2fc1b99911
commit 42f8ec5b14
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
3 changed files with 45 additions and 35 deletions

View File

@ -53,9 +53,28 @@ void FlameMod::loadIndexedPackVersions(ModPlatform::IndexedPack& pack,
for (auto versionIter : arr) {
auto obj = versionIter.toObject();
auto file = loadIndexedPackVersion(obj);
if(!file.addonId.isValid())
file.addonId = pack.addonId;
if(file.fileId.isValid()) // Heuristic to check if the returned value is valid
unsortedVersions.append(file);
}
auto orderSortPredicate = [](const ModPlatform::IndexedVersion& a, const ModPlatform::IndexedVersion& b) -> bool {
// dates are in RFC 3339 format
return a.date > b.date;
};
std::sort(unsortedVersions.begin(), unsortedVersions.end(), orderSortPredicate);
pack.versions = unsortedVersions;
pack.versionsLoaded = true;
}
auto FlameMod::loadIndexedPackVersion(QJsonObject& obj) -> ModPlatform::IndexedVersion
{
auto versionArray = Json::requireArray(obj, "gameVersions");
if (versionArray.isEmpty()) {
continue;
return {};
}
ModPlatform::IndexedVersion file;
@ -66,7 +85,7 @@ void FlameMod::loadIndexedPackVersions(ModPlatform::IndexedPack& pack,
file.mcVersion.append(str);
}
file.addonId = pack.addonId;
file.addonId = Json::requireInteger(obj, "modId");
file.fileId = Json::requireInteger(obj, "id");
file.date = Json::requireString(obj, "fileDate");
file.version = Json::requireString(obj, "displayName");
@ -84,15 +103,5 @@ void FlameMod::loadIndexedPackVersions(ModPlatform::IndexedPack& pack,
break;
}
}
unsortedVersions.append(file);
}
auto orderSortPredicate = [](const ModPlatform::IndexedVersion& a, const ModPlatform::IndexedVersion& b) -> bool {
// dates are in RFC 3339 format
return a.date > b.date;
};
std::sort(unsortedVersions.begin(), unsortedVersions.end(), orderSortPredicate);
pack.versions = unsortedVersions;
pack.versionsLoaded = true;
return file;
}

View File

@ -16,5 +16,6 @@ void loadIndexedPackVersions(ModPlatform::IndexedPack& pack,
QJsonArray& arr,
const shared_qobject_ptr<QNetworkAccessManager>& network,
BaseInstance* inst);
auto loadIndexedPackVersion(QJsonObject& obj) -> ModPlatform::IndexedVersion;
} // namespace FlameMod

View File

@ -58,8 +58,8 @@ auto V1::createModFormat(QDir& index_dir, ModPlatform::IndexedPack& mod_pack, Mo
mod.hash = mod_version.hash;
mod.provider = mod_pack.provider;
mod.file_id = mod_pack.addonId;
mod.project_id = mod_version.fileId;
mod.file_id = mod_version.fileId;
mod.project_id = mod_pack.addonId;
return mod;
}