Skip to content

Commit fd5eaae

Browse files
davexunitsfan5
authored andcommitted
Search for subgames using $MINETEST_SUBGAME_PATH.
1 parent d221917 commit fd5eaae

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

doc/minetest.6

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ Set world path
8383
Migrate from current map backend to another. Possible values are sqlite3
8484
and leveldb. Only works when using --server.
8585

86+
.SH ENVIRONMENT VARIABLES
87+
88+
.TP
89+
MINETEST_SUBGAME_PATH
90+
Colon delimited list of directories to search for subgames.
91+
8692
.SH BUGS
8793
Please report all bugs to Perttu Ahola <celeron55@gmail.com>.
8894

src/subgame.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2222
#include "filesys.h"
2323
#include "settings.h"
2424
#include "log.h"
25+
#include "strfnd.h"
2526
#ifndef SERVER
2627
#include "tile.h" // getImagePath
2728
#endif
@@ -59,13 +60,35 @@ struct GameFindPath
5960
{}
6061
};
6162

63+
Strfnd getSubgamePathEnv() {
64+
std::string sp;
65+
char *subgame_path = getenv("MINETEST_SUBGAME_PATH");
66+
67+
if(subgame_path) {
68+
sp = std::string(subgame_path);
69+
}
70+
71+
return Strfnd(sp);
72+
}
73+
6274
SubgameSpec findSubgame(const std::string &id)
6375
{
6476
if(id == "")
6577
return SubgameSpec();
6678
std::string share = porting::path_share;
6779
std::string user = porting::path_user;
6880
std::vector<GameFindPath> find_paths;
81+
82+
Strfnd search_paths = getSubgamePathEnv();
83+
84+
while(!search_paths.atend()) {
85+
std::string path = search_paths.next(":");
86+
find_paths.push_back(GameFindPath(
87+
path + DIR_DELIM + id, false));
88+
find_paths.push_back(GameFindPath(
89+
path + DIR_DELIM + id + "_game", false));
90+
}
91+
6992
find_paths.push_back(GameFindPath(
7093
user + DIR_DELIM + "games" + DIR_DELIM + id + "_game", true));
7194
find_paths.push_back(GameFindPath(
@@ -129,6 +152,13 @@ std::set<std::string> getAvailableGameIds()
129152
std::set<std::string> gamespaths;
130153
gamespaths.insert(porting::path_share + DIR_DELIM + "games");
131154
gamespaths.insert(porting::path_user + DIR_DELIM + "games");
155+
156+
Strfnd search_paths = getSubgamePathEnv();
157+
158+
while(!search_paths.atend()) {
159+
gamespaths.insert(search_paths.next(":"));
160+
}
161+
132162
for(std::set<std::string>::const_iterator i = gamespaths.begin();
133163
i != gamespaths.end(); i++){
134164
std::vector<fs::DirListNode> dirlist = fs::GetDirListing(*i);

0 commit comments

Comments
 (0)