mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 18:13:46 +01:00
Add support for directly starting a world by name from command line
This commit is contained in:
parent
04fbf47744
commit
99f565e8f2
43
src/main.cpp
43
src/main.cpp
@ -1633,15 +1633,14 @@ int main(int argc, char *argv[])
|
|||||||
std::vector<WorldSpec> worldspecs = getAvailableWorlds();
|
std::vector<WorldSpec> worldspecs = getAvailableWorlds();
|
||||||
|
|
||||||
// If a world was commanded, append and select it
|
// If a world was commanded, append and select it
|
||||||
if (commanded_world != "") {
|
if(commanded_world != "") {
|
||||||
|
worldspec.gameid = getWorldGameId(commanded_world, true);
|
||||||
std::string gameid = getWorldGameId(commanded_world, true);
|
worldspec.name = _("[--world parameter]");
|
||||||
std::string name = _("[--world parameter]");
|
if(worldspec.gameid == "") {
|
||||||
if (gameid == "") {
|
worldspec.gameid = g_settings->get("default_game");
|
||||||
gameid = g_settings->get("default_game");
|
worldspec.name += " [new]";
|
||||||
name += " [new]";
|
|
||||||
}
|
}
|
||||||
//TODO find within worldspecs and set config
|
worldspec.path = commanded_world;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skip_main_menu == false) {
|
if (skip_main_menu == false) {
|
||||||
@ -1695,11 +1694,6 @@ int main(int argc, char *argv[])
|
|||||||
// Save settings
|
// Save settings
|
||||||
g_settings->set("name", playername);
|
g_settings->set("name", playername);
|
||||||
|
|
||||||
if ((menudata.selected_world >= 0) &&
|
|
||||||
(menudata.selected_world < (int)worldspecs.size()))
|
|
||||||
g_settings->set("selected_world_path",
|
|
||||||
worldspecs[menudata.selected_world].path);
|
|
||||||
|
|
||||||
// Break out of menu-game loop to shut down cleanly
|
// Break out of menu-game loop to shut down cleanly
|
||||||
if (device->run() == false || kill == true)
|
if (device->run() == false || kill == true)
|
||||||
break;
|
break;
|
||||||
@ -1724,22 +1718,35 @@ int main(int argc, char *argv[])
|
|||||||
ServerList::insert(server);
|
ServerList::insert(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set world path to selected one
|
if ((!skip_main_menu) &&
|
||||||
if ((menudata.selected_world >= 0) &&
|
(menudata.selected_world >= 0) &&
|
||||||
(menudata.selected_world < (int)worldspecs.size())) {
|
(menudata.selected_world < (int)worldspecs.size())) {
|
||||||
|
g_settings->set("selected_world_path",
|
||||||
|
worldspecs[menudata.selected_world].path);
|
||||||
worldspec = worldspecs[menudata.selected_world];
|
worldspec = worldspecs[menudata.selected_world];
|
||||||
infostream<<"Selected world: "<<worldspec.name
|
|
||||||
<<" ["<<worldspec.path<<"]"<<std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
infostream <<"Selected world: " << worldspec.name
|
||||||
|
<< " ["<<worldspec.path<<"]" <<std::endl;
|
||||||
|
|
||||||
|
|
||||||
// If local game
|
// If local game
|
||||||
if (current_address == "") {
|
if (current_address == "") {
|
||||||
if (menudata.selected_world == -1) {
|
if (worldspec.path == "") {
|
||||||
error_message = wgettext("No world selected and no address "
|
error_message = wgettext("No world selected and no address "
|
||||||
"provided. Nothing to do.");
|
"provided. Nothing to do.");
|
||||||
errorstream << wide_to_narrow(error_message) << std::endl;
|
errorstream << wide_to_narrow(error_message) << std::endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!fs::PathExists(worldspec.path)) {
|
||||||
|
error_message = wgettext("Provided world path doesn't exist: ")
|
||||||
|
+ narrow_to_wide(worldspec.path);
|
||||||
|
errorstream << wide_to_narrow(error_message) << std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Load gamespec for required game
|
// Load gamespec for required game
|
||||||
gamespec = findWorldSubgame(worldspec.path);
|
gamespec = findWorldSubgame(worldspec.path);
|
||||||
if (!gamespec.isValid() && !commanded_gamespec.isValid()) {
|
if (!gamespec.isValid() && !commanded_gamespec.isValid()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user