Support game-specific minetest.conf

This commit is contained in:
Perttu Ahola 2013-03-21 21:42:23 +02:00
parent adc52f3f3c
commit c2250d95c4
6 changed files with 30 additions and 0 deletions

View File

@ -57,6 +57,9 @@ eg.
Common mods are loaded from the pseudo-game "common".
The game directory can contain the file minetest.conf, which will be used
to set default settings when running the particular game.
Mod load path
-------------
Generic:

View File

@ -243,3 +243,12 @@ void set_default_settings(Settings *settings)
}
void override_default_settings(Settings *settings, Settings *from)
{
std::vector<std::string> names = from->getNames();
for(size_t i=0; i<names.size(); i++){
const std::string &name = names[i];
settings->setDefault(name, from->get(name));
}
}

View File

@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class Settings;
void set_default_settings(Settings *settings);
void override_default_settings(Settings *settings, Settings *from);
#endif

View File

@ -58,6 +58,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/mathconstants.h"
#include "rollback.h"
#include "util/serialize.h"
#include "defaultsettings.h"
void * ServerThread::Thread()
{
@ -687,6 +688,13 @@ Server::Server(
infostream<<"- config: "<<m_path_config<<std::endl;
infostream<<"- game: "<<m_gamespec.path<<std::endl;
// Initialize default settings and override defaults with those provided
// by the game
set_default_settings(g_settings);
Settings gamedefaults;
getGameMinetestConfig(gamespec.path, gamedefaults);
override_default_settings(g_settings, &gamedefaults);
// Create biome definition manager
m_biomedef = new BiomeDefManager(this);

View File

@ -24,6 +24,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "log.h"
#include "util/string.h"
bool getGameMinetestConfig(const std::string &game_path, Settings &conf)
{
std::string conf_path = game_path + DIR_DELIM + "minetest.conf";
return conf.readConfigFile(conf_path.c_str());
}
bool getGameConfig(const std::string &game_path, Settings &conf)
{
std::string conf_path = game_path + DIR_DELIM + "game.conf";

View File

@ -54,6 +54,9 @@ struct SubgameSpec
}
};
// minetest.conf
bool getGameMinetestConfig(const std::string &game_path, Settings &conf);
// game.conf
bool getGameConfig(const std::string &game_path, Settings &conf);
std::string getGameName(const std::string &game_path);