rework parse dependency function

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2025-07-29 17:50:29 +03:00
parent 1346783c5e
commit 0f5a890051
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318

View File

@ -83,11 +83,11 @@ ModDetails ReadMCModInfo(QByteArray contents)
}; };
if (firstObj.contains("requiredMods")) { if (firstObj.contains("requiredMods")) {
for (auto dep : firstObj.value("dependencies").toArray().toVariantList()) { for (auto dep : firstObj.value("requiredMods").toArray()) {
addDep(dep.toString()); addDep(dep.toString());
} }
} else if (firstObj.contains("dependencies")) { } else if (firstObj.contains("dependencies")) {
for (auto dep : firstObj.value("dependencies").toArray().toVariantList()) { for (auto dep : firstObj.value("dependencies").toArray()) {
addDep(dep.toString()); addDep(dep.toString());
} }
} }
@ -230,19 +230,29 @@ ModDetails ReadMCModTOML(QByteArray contents)
details.icon_file = logoFile; details.icon_file = logoFile;
auto parseDep = [&details](toml::array* dependencies) { auto parseDep = [&details](toml::array* dependencies) {
if (dependencies) { static const QStringList ignoreModIds = { "", "forge", "neoforge", "minecraft" };
for (auto& dep : *dependencies) { if (!dependencies) {
auto dep_table = dep.as_table(); return;
if (dep_table) { }
auto modId = dep_table->get("modId")->value_or<std::string>(""); auto isNeoForgeDep = [](toml::table* t) {
if (modId != "forge" && modId != "neoforge" && modId != "minecraft") { auto type = (*t)["type"].as_string();
if (dep_table->contains("type") && (dep_table->get("type"))->value_or<std::string>("") == "required") { return type && type->get() == "required";
details.dependencies.append(QString::fromStdString(modId)); };
} else if (dep_table->contains("mandatory") && (dep_table->get("mandatory"))->value_or(false)) { auto isForgeDep = [](toml::table* t) {
details.dependencies.append(QString::fromStdString(modId)); auto mandatory = (*t)["mandatory"].as_boolean();
} return mandatory && mandatory->get();
} };
} for (auto& dep : *dependencies) {
auto dep_table = dep.as_table();
if (!dep_table) {
continue;
}
auto modId = (*dep_table)["modId"].as_string();
if (!modId || ignoreModIds.contains(modId->get())) {
continue;
}
if (isNeoForgeDep(dep_table) || isForgeDep(dep_table)) {
details.dependencies.append(QString::fromStdString(modId->get()));
} }
} }
}; };