mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-09-08 03:18:37 -04:00
rework parse dependency function
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
1346783c5e
commit
0f5a890051
@ -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()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user