mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Allow game to specify first and last mod in mod loading order (#14177)
Co-authored-by: Lars Mueller <appgurulars@gmx.de> Co-authored-by: sfan5 <sfan5@live.de>
This commit is contained in:
parent
a4768d1638
commit
140b9e5a5a
12 changed files with 141 additions and 64 deletions
|
@ -94,6 +94,50 @@ std::string getSubgamePathEnv()
|
|||
return "";
|
||||
}
|
||||
|
||||
static SubgameSpec getSubgameSpec(const std::string &game_id,
|
||||
const std::string &game_path,
|
||||
const std::unordered_map<std::string, std::string> &mods_paths,
|
||||
const std::string &menuicon_path)
|
||||
{
|
||||
const auto gamemods_path = game_path + DIR_DELIM + "mods";
|
||||
// Get meta
|
||||
const std::string conf_path = game_path + DIR_DELIM + "game.conf";
|
||||
Settings conf;
|
||||
conf.readConfigFile(conf_path.c_str());
|
||||
|
||||
std::string game_title;
|
||||
if (conf.exists("title"))
|
||||
game_title = conf.get("title");
|
||||
else if (conf.exists("name"))
|
||||
game_title = conf.get("name");
|
||||
else
|
||||
game_title = game_id;
|
||||
|
||||
std::string game_author;
|
||||
if (conf.exists("author"))
|
||||
game_author = conf.get("author");
|
||||
|
||||
int game_release = 0;
|
||||
if (conf.exists("release"))
|
||||
game_release = conf.getS32("release");
|
||||
|
||||
std::string first_mod;
|
||||
if (conf.exists("first_mod"))
|
||||
first_mod = conf.get("first_mod");
|
||||
|
||||
std::string last_mod;
|
||||
if (conf.exists("last_mod"))
|
||||
last_mod = conf.get("last_mod");
|
||||
|
||||
SubgameSpec spec(game_id, game_path, gamemods_path, mods_paths, game_title,
|
||||
menuicon_path, game_author, game_release, first_mod, last_mod);
|
||||
|
||||
if (conf.exists("name") && !conf.exists("title"))
|
||||
spec.deprecation_msgs.push_back("\"name\" setting in game.conf is deprecated, please use \"title\" instead");
|
||||
|
||||
return spec;
|
||||
}
|
||||
|
||||
SubgameSpec findSubgame(const std::string &id)
|
||||
{
|
||||
if (id.empty())
|
||||
|
@ -137,8 +181,6 @@ SubgameSpec findSubgame(const std::string &id)
|
|||
if (game_path.empty())
|
||||
return SubgameSpec();
|
||||
|
||||
std::string gamemod_path = game_path + DIR_DELIM + "mods";
|
||||
|
||||
// Find mod directories
|
||||
std::unordered_map<std::string, std::string> mods_paths;
|
||||
mods_paths["mods"] = user + DIR_DELIM + "mods";
|
||||
|
@ -149,40 +191,13 @@ SubgameSpec findSubgame(const std::string &id)
|
|||
mods_paths[fs::AbsolutePath(mod_path)] = mod_path;
|
||||
}
|
||||
|
||||
// Get meta
|
||||
std::string conf_path = game_path + DIR_DELIM + "game.conf";
|
||||
Settings conf;
|
||||
conf.readConfigFile(conf_path.c_str());
|
||||
|
||||
std::string game_title;
|
||||
if (conf.exists("title"))
|
||||
game_title = conf.get("title");
|
||||
else if (conf.exists("name"))
|
||||
game_title = conf.get("name");
|
||||
else
|
||||
game_title = id;
|
||||
|
||||
std::string game_author;
|
||||
if (conf.exists("author"))
|
||||
game_author = conf.get("author");
|
||||
|
||||
int game_release = 0;
|
||||
if (conf.exists("release"))
|
||||
game_release = conf.getS32("release");
|
||||
|
||||
std::string menuicon_path;
|
||||
#ifndef SERVER
|
||||
menuicon_path = getImagePath(
|
||||
game_path + DIR_DELIM + "menu" + DIR_DELIM + "icon.png");
|
||||
#endif
|
||||
|
||||
SubgameSpec spec(id, game_path, gamemod_path, mods_paths, game_title,
|
||||
menuicon_path, game_author, game_release);
|
||||
|
||||
if (conf.exists("name") && !conf.exists("title"))
|
||||
spec.deprecation_msgs.push_back("\"name\" setting in game.conf is deprecated, please use \"title\" instead");
|
||||
|
||||
return spec;
|
||||
return getSubgameSpec(id, game_path, mods_paths, menuicon_path);
|
||||
}
|
||||
|
||||
SubgameSpec findWorldSubgame(const std::string &world_path)
|
||||
|
@ -190,25 +205,8 @@ SubgameSpec findWorldSubgame(const std::string &world_path)
|
|||
std::string world_gameid = getWorldGameId(world_path, true);
|
||||
// See if world contains an embedded game; if so, use it.
|
||||
std::string world_gamepath = world_path + DIR_DELIM + "game";
|
||||
if (fs::PathExists(world_gamepath)) {
|
||||
SubgameSpec gamespec;
|
||||
gamespec.id = world_gameid;
|
||||
gamespec.path = world_gamepath;
|
||||
gamespec.gamemods_path = world_gamepath + DIR_DELIM + "mods";
|
||||
|
||||
Settings conf;
|
||||
std::string conf_path = world_gamepath + DIR_DELIM + "game.conf";
|
||||
conf.readConfigFile(conf_path.c_str());
|
||||
|
||||
if (conf.exists("title"))
|
||||
gamespec.title = conf.get("title");
|
||||
else if (conf.exists("name"))
|
||||
gamespec.title = conf.get("name");
|
||||
else
|
||||
gamespec.title = world_gameid;
|
||||
|
||||
return gamespec;
|
||||
}
|
||||
if (fs::PathExists(world_gamepath))
|
||||
return getSubgameSpec(world_gameid, world_gamepath, {}, "");
|
||||
return findSubgame(world_gameid);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue