Allow directly supplying world as a parameter, including world.mt

master
Perttu Ahola 2012-03-13 01:32:21 +02:00
parent 4ff36696ea
commit 71a3c2fcd1
2 changed files with 31 additions and 4 deletions

View File

@ -806,7 +806,7 @@ int main(int argc, char *argv[])
bool ret = cmd_args.parseCommandLine(argc, argv, allowed_options); bool ret = cmd_args.parseCommandLine(argc, argv, allowed_options);
if(ret == false || cmd_args.getFlag("help")) if(ret == false || cmd_args.getFlag("help") || cmd_args.exists("nonopt1"))
{ {
dstream<<"Allowed options:"<<std::endl; dstream<<"Allowed options:"<<std::endl;
for(core::map<std::string, ValueSpec>::Iterator for(core::map<std::string, ValueSpec>::Iterator
@ -979,9 +979,23 @@ int main(int argc, char *argv[])
commanded_world = cmd_args.get("world"); commanded_world = cmd_args.get("world");
else if(cmd_args.exists("map-dir")) else if(cmd_args.exists("map-dir"))
commanded_world = cmd_args.get("map-dir"); commanded_world = cmd_args.get("map-dir");
else if(cmd_args.exists("nonopt0"))
commanded_world = cmd_args.get("nonopt0");
else if(g_settings->exists("map-dir")) else if(g_settings->exists("map-dir"))
commanded_world = g_settings->get("map-dir"); commanded_world = g_settings->get("map-dir");
// Strip world.mt from commanded_world
{
std::string worldmt = "world.mt";
if(commanded_world.size() > worldmt.size() &&
commanded_world.substr(commanded_world.size()-worldmt.size())
== worldmt){
dstream<<"Supplied world.mt file - stripping it off."<<std::endl;
commanded_world = commanded_world.substr(
0, commanded_world.size()-worldmt.size());
}
}
// Gamespec // Gamespec
SubgameSpec commanded_gamespec; SubgameSpec commanded_gamespec;
if(cmd_args.exists("gameid")){ if(cmd_args.exists("gameid")){
@ -1065,7 +1079,9 @@ int main(int argc, char *argv[])
*/ */
std::string address = g_settings->get("address"); std::string address = g_settings->get("address");
if(cmd_args.exists("address")) if(commanded_world != "")
address = "";
else if(cmd_args.exists("address"))
address = cmd_args.get("address"); address = cmd_args.get("address");
else if(cmd_args.exists("world")) else if(cmd_args.exists("world"))
address = ""; address = "";
@ -1294,9 +1310,10 @@ int main(int argc, char *argv[])
std::string gameid = getWorldGameId(commanded_world, true); std::string gameid = getWorldGameId(commanded_world, true);
if(gameid == "") if(gameid == "")
gameid = g_settings->get("default_game"); gameid = g_settings->get("default_game");
WorldSpec spec(commanded_world, "--world", gameid); WorldSpec spec(commanded_world, "[--world parameter]",
gameid);
worldspecs.push_back(spec); worldspecs.push_back(spec);
menudata.selected_world = menudata.worlds.size()-1; menudata.selected_world = worldspecs.size()-1;
} }
// Copy worldspecs to menu // Copy worldspecs to menu
menudata.worlds = worldspecs; menudata.worlds = worldspecs;

View File

@ -330,6 +330,7 @@ public:
bool parseCommandLine(int argc, char *argv[], bool parseCommandLine(int argc, char *argv[],
core::map<std::string, ValueSpec> &allowed_options) core::map<std::string, ValueSpec> &allowed_options)
{ {
int nonopt_index = 0;
int i=1; int i=1;
for(;;) for(;;)
{ {
@ -338,6 +339,15 @@ public:
std::string argname = argv[i]; std::string argname = argv[i];
if(argname.substr(0, 2) != "--") if(argname.substr(0, 2) != "--")
{ {
// If option doesn't start with -, read it in as nonoptX
if(argname[0] != '-'){
std::string name = "nonopt";
name += itos(nonopt_index);
set(name, argname);
nonopt_index++;
i++;
continue;
}
errorstream<<"Invalid command-line parameter \"" errorstream<<"Invalid command-line parameter \""
<<argname<<"\": --<option> expected."<<std::endl; <<argname<<"\": --<option> expected."<<std::endl;
return false; return false;