Support placing a minetest game inside $world/game to allow creating proper adventure maps
Pro-tip: You can open a world in minetest by opening the world.mt file using minetest.master
parent
c59d139eeb
commit
42323014ea
43
src/main.cpp
43
src/main.cpp
|
@ -1135,43 +1135,44 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
verbosestream<<"Using world path ["<<world_path<<"]"<<std::endl;
|
verbosestream<<"Using world path ["<<world_path<<"]"<<std::endl;
|
||||||
|
|
||||||
// We need a gameid.
|
// We need a gamespec.
|
||||||
std::string gameid;
|
SubgameSpec gamespec;
|
||||||
verbosestream<<"Determining gameid"<<std::endl;
|
verbosestream<<"Determining gameid/gamespec"<<std::endl;
|
||||||
// If world doesn't exist
|
// If world doesn't exist
|
||||||
if(!getWorldExists(world_path))
|
if(!getWorldExists(world_path))
|
||||||
{
|
{
|
||||||
// Try to take gamespec from command line
|
// Try to take gamespec from command line
|
||||||
if(commanded_gamespec.isValid()){
|
if(commanded_gamespec.isValid()){
|
||||||
gameid = commanded_gamespec.id;
|
gamespec = commanded_gamespec;
|
||||||
infostream<<"Using commanded gameid ["<<gameid<<"]"<<std::endl;
|
infostream<<"Using commanded gameid ["<<gamespec.id<<"]"<<std::endl;
|
||||||
}
|
}
|
||||||
// Otherwise we will be using "minetest"
|
// Otherwise we will be using "minetest"
|
||||||
else{
|
else{
|
||||||
gameid = g_settings->get("default_game");
|
gamespec = findSubgame(g_settings->get("default_game"));
|
||||||
infostream<<"Using default gameid ["<<gameid<<"]"<<std::endl;
|
infostream<<"Using default gameid ["<<gamespec.id<<"]"<<std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If world exists
|
// World exists
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Otherwise read from the world
|
|
||||||
std::string world_gameid = getWorldGameId(world_path, is_legacy_world);
|
std::string world_gameid = getWorldGameId(world_path, is_legacy_world);
|
||||||
gameid = world_gameid;
|
// If commanded to use a gameid, do so
|
||||||
if(commanded_gamespec.isValid() &&
|
if(commanded_gamespec.isValid()){
|
||||||
commanded_gamespec.id != world_gameid){
|
gamespec = commanded_gamespec;
|
||||||
gameid = commanded_gamespec.id;
|
if(commanded_gamespec.id != world_gameid){
|
||||||
errorstream<<"WARNING: Using commanded gameid ["<<gameid<<"]"
|
errorstream<<"WARNING: Using commanded gameid ["
|
||||||
<<" instead of world gameid ["<<world_gameid
|
<<gamespec.id<<"]"<<" instead of world gameid ["
|
||||||
<<"]"<<std::endl;
|
<<world_gameid<<"]"<<std::endl;
|
||||||
|
}
|
||||||
} else{
|
} else{
|
||||||
infostream<<"Using world gameid ["<<gameid<<"]"<<std::endl;
|
// If world contains an embedded game, use it;
|
||||||
|
// Otherwise find world from local system.
|
||||||
|
gamespec = findWorldSubgame(world_path);
|
||||||
|
infostream<<"Using world gameid ["<<gamespec.id<<"]"<<std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
verbosestream<<"Finding subgame ["<<gameid<<"]"<<std::endl;
|
|
||||||
SubgameSpec gamespec = findSubgame(gameid);
|
|
||||||
if(!gamespec.isValid()){
|
if(!gamespec.isValid()){
|
||||||
errorstream<<"Subgame ["<<gameid<<"] could not be found."
|
errorstream<<"Subgame ["<<gamespec.id<<"] could not be found."
|
||||||
<<std::endl;
|
<<std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -1602,7 +1603,7 @@ int main(int argc, char *argv[])
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Load gamespec for required game
|
// Load gamespec for required game
|
||||||
gamespec = findSubgame(worldspec.gameid);
|
gamespec = findWorldSubgame(worldspec.path);
|
||||||
if(!gamespec.isValid() && !commanded_gamespec.isValid()){
|
if(!gamespec.isValid() && !commanded_gamespec.isValid()){
|
||||||
error_message = L"Could not find or load game \""
|
error_message = L"Could not find or load game \""
|
||||||
+ narrow_to_wide(worldspec.gameid) + L"\"";
|
+ narrow_to_wide(worldspec.gameid) + L"\"";
|
||||||
|
|
|
@ -87,6 +87,24 @@ SubgameSpec findSubgame(const std::string &id)
|
||||||
return SubgameSpec(id, game_path, mods_paths, game_name);
|
return SubgameSpec(id, game_path, mods_paths, game_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.mods_paths.insert(world_gamepath + DIR_DELIM + "mods");
|
||||||
|
gamespec.name = getGameName(world_gamepath);
|
||||||
|
if(gamespec.name == "")
|
||||||
|
gamespec.name = "unknown";
|
||||||
|
return gamespec;
|
||||||
|
}
|
||||||
|
return findSubgame(world_gameid);
|
||||||
|
}
|
||||||
|
|
||||||
std::set<std::string> getAvailableGameIds()
|
std::set<std::string> getAvailableGameIds()
|
||||||
{
|
{
|
||||||
std::set<std::string> gameids;
|
std::set<std::string> gameids;
|
||||||
|
|
|
@ -47,7 +47,10 @@ struct SubgameSpec
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::string getGameName(const std::string &game_path);
|
||||||
|
|
||||||
SubgameSpec findSubgame(const std::string &id);
|
SubgameSpec findSubgame(const std::string &id);
|
||||||
|
SubgameSpec findWorldSubgame(const std::string &world_path);
|
||||||
|
|
||||||
std::set<std::string> getAvailableGameIds();
|
std::set<std::string> getAvailableGameIds();
|
||||||
std::vector<SubgameSpec> getAvailableGames();
|
std::vector<SubgameSpec> getAvailableGames();
|
||||||
|
|
Loading…
Reference in New Issue