mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Common mods support
Implement "common mods", includeable from {$user,$share}/games/common/$modname by using the game.conf setting common_mods = $modname,$modname2,...
This commit is contained in:
parent
9b5bb5c755
commit
306d1ab866
4 changed files with 68 additions and 7 deletions
52
src/mods.cpp
52
src/mods.cpp
|
@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "log.h"
|
||||
#include "subgame.h"
|
||||
#include "settings.h"
|
||||
#include "strfnd.h"
|
||||
|
||||
std::map<std::string, ModSpec> getModsInPath(std::string path)
|
||||
{
|
||||
|
@ -188,11 +189,58 @@ void ModConfiguration::addMods(std::vector<ModSpec> new_mods)
|
|||
}
|
||||
}
|
||||
|
||||
// If failed, returned modspec has name==""
|
||||
static ModSpec findCommonMod(const std::string &modname)
|
||||
{
|
||||
// Try to find in {$user,$share}/games/common/$modname
|
||||
std::vector<std::string> find_paths;
|
||||
find_paths.push_back(porting::path_user + DIR_DELIM + "games" +
|
||||
DIR_DELIM + "common" + DIR_DELIM + "mods" + DIR_DELIM + modname);
|
||||
find_paths.push_back(porting::path_share + DIR_DELIM + "games" +
|
||||
DIR_DELIM + "common" + DIR_DELIM + "mods" + DIR_DELIM + modname);
|
||||
for(u32 i=0; i<find_paths.size(); i++){
|
||||
const std::string &try_path = find_paths[i];
|
||||
if(fs::PathExists(try_path))
|
||||
return ModSpec(modname, try_path);
|
||||
}
|
||||
// Failed to find mod
|
||||
return ModSpec();
|
||||
}
|
||||
|
||||
ModConfiguration::ModConfiguration(std::string worldpath)
|
||||
{
|
||||
SubgameSpec gamespec = findWorldSubgame(worldpath);
|
||||
|
||||
// Add common mods without dependency handling
|
||||
std::vector<std::string> inexistent_common_mods;
|
||||
Settings gameconf;
|
||||
if(getGameConfig(gamespec.path, gameconf)){
|
||||
if(gameconf.exists("common_mods")){
|
||||
Strfnd f(gameconf.get("common_mods"));
|
||||
while(!f.atend()){
|
||||
std::string modname = trim(f.next(","));
|
||||
if(modname.empty())
|
||||
continue;
|
||||
ModSpec spec = findCommonMod(modname);
|
||||
if(spec.name.empty())
|
||||
inexistent_common_mods.push_back(modname);
|
||||
else
|
||||
m_sorted_mods.push_back(spec);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!inexistent_common_mods.empty()){
|
||||
std::string s = "Required common mods ";
|
||||
for(u32 i=0; i<inexistent_common_mods.size(); i++){
|
||||
if(i != 0) s += ", ";
|
||||
s += std::string("\"") + inexistent_common_mods[i] + "\"";
|
||||
}
|
||||
s += " could not be found.";
|
||||
throw ModError(s);
|
||||
}
|
||||
|
||||
// Add all world mods and all game mods
|
||||
addModsInPath(worldpath + DIR_DELIM + "worldmods");
|
||||
SubgameSpec gamespec = findWorldSubgame(worldpath);
|
||||
addModsInPath(gamespec.gamemods_path);
|
||||
|
||||
// check world.mt file for mods explicitely declared to be
|
||||
|
@ -217,6 +265,6 @@ ModConfiguration::ModConfiguration(std::string worldpath)
|
|||
}
|
||||
|
||||
for(std::set<std::string>::const_iterator i = gamespec.addon_mods_paths.begin();
|
||||
i != gamespec.addon_mods_paths.end(); ++i)
|
||||
i != gamespec.addon_mods_paths.end(); ++i)
|
||||
addModsInPathFiltered((*i),exclude_mod_names);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue