1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-26 18:21:04 +00:00

Mapgen selection and init code

This commit is contained in:
Xeno333 2025-06-10 18:00:45 -05:00
parent aba2b6638e
commit f9bad58d77
14 changed files with 211 additions and 59 deletions

View file

@ -76,7 +76,12 @@ bool parseModContents(ModSpec &spec)
Settings info;
info.readConfigFile((spec.path + DIR_DELIM + "mod.conf").c_str());
if (fs::IsFile(spec.path + DIR_DELIM + "mapgen.conf")) {
info.readConfigFile((spec.path + DIR_DELIM + "mapgen.conf").c_str());
spec.is_mapgen = true;
}
else
info.readConfigFile((spec.path + DIR_DELIM + "mod.conf").c_str());
if (info.exists("name"))
spec.name = info.get("name");
@ -89,50 +94,52 @@ bool parseModContents(ModSpec &spec)
if (info.exists("release"))
spec.release = info.getS32("release");
// Attempt to load dependencies from mod.conf
bool mod_conf_has_depends = false;
if (info.exists("depends")) {
mod_conf_has_depends = true;
std::string dep = info.get("depends");
dep.erase(std::remove_if(dep.begin(), dep.end(),
static_cast<int (*)(int)>(&std::isspace)), dep.end());
for (const auto &dependency : str_split(dep, ',')) {
spec.depends.insert(dependency);
}
}
if (info.exists("optional_depends")) {
mod_conf_has_depends = true;
std::string dep = info.get("optional_depends");
dep.erase(std::remove_if(dep.begin(), dep.end(),
static_cast<int (*)(int)>(&std::isspace)), dep.end());
for (const auto &dependency : str_split(dep, ',')) {
spec.optdepends.insert(dependency);
}
}
// Fallback to depends.txt
if (!mod_conf_has_depends) {
std::vector<std::string> dependencies;
std::ifstream is((spec.path + DIR_DELIM + "depends.txt").c_str());
if (is.good())
spec.deprecation_msgs.push_back("depends.txt is deprecated, please use mod.conf instead.");
while (is.good()) {
std::string dep;
std::getline(is, dep);
dependencies.push_back(dep);
// Attempt to load dependencies from mod.conf if not mapgen
if (!spec.is_mapgen) {
bool mod_conf_has_depends = false;
if (info.exists("depends")) {
mod_conf_has_depends = true;
std::string dep = info.get("depends");
dep.erase(std::remove_if(dep.begin(), dep.end(),
static_cast<int (*)(int)>(&std::isspace)), dep.end());
for (const auto &dependency : str_split(dep, ',')) {
spec.depends.insert(dependency);
}
}
for (auto &dependency : dependencies) {
std::unordered_set<char> symbols;
if (parseDependsString(dependency, symbols)) {
if (symbols.count('?') != 0) {
spec.optdepends.insert(dependency);
} else {
spec.depends.insert(dependency);
if (info.exists("optional_depends")) {
mod_conf_has_depends = true;
std::string dep = info.get("optional_depends");
dep.erase(std::remove_if(dep.begin(), dep.end(),
static_cast<int (*)(int)>(&std::isspace)), dep.end());
for (const auto &dependency : str_split(dep, ',')) {
spec.optdepends.insert(dependency);
}
}
// Fallback to depends.txt
if (!mod_conf_has_depends) {
std::vector<std::string> dependencies;
std::ifstream is((spec.path + DIR_DELIM + "depends.txt").c_str());
if (is.good())
spec.deprecation_msgs.push_back("depends.txt is deprecated, please use mod.conf instead.");
while (is.good()) {
std::string dep;
std::getline(is, dep);
dependencies.push_back(dep);
}
for (auto &dependency : dependencies) {
std::unordered_set<char> symbols;
if (parseDependsString(dependency, symbols)) {
if (symbols.count('?') != 0) {
spec.optdepends.insert(dependency);
} else {
spec.depends.insert(dependency);
}
}
}
}