Hide mapgens from main menu not intended for end users
authorkwolekr <kwolekr@minetest.net>
Sun, 4 Oct 2015 20:37:03 +0000 (16:37 -0400)
committerkwolekr <kwolekr@minetest.net>
Sun, 4 Oct 2015 21:11:41 +0000 (17:11 -0400)
doc/menu_lua_api.txt
src/emerge.cpp
src/emerge.h
src/script/lua_api/l_mainmenu.cpp

index 7d46c652640884220b072f915a9b54bbe2191f28..d1e209187756156f6b17835a24fe74986b015a09 100644 (file)
@@ -141,8 +141,8 @@ core.get_game(index)
        addon_mods_paths = {[1] = <path>,},
 }
 core.get_games() -> table of all games in upper format (possible in async calls)
-core.get_mapgen_names() -> table of all map generator algorithms registered in
-                           the core (possible in async calls)
+core.get_mapgen_names([include_hidden=false]) -> table of map generator algorithms
+    registered in the core (possible in async calls)
 
 Favorites:
 core.get_favorites(location) -> list of favorites (possible in async calls)
index 15f264c1a2245f5d7e28fa8414bf140486badba3..bb2590641419cc3bf1ce5a30e86d8ad560dc7e83 100644 (file)
@@ -54,6 +54,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 struct MapgenDesc {
        const char *name;
        MapgenFactory *factory;
+       bool is_user_visible;
 };
 
 class EmergeThread : public Thread {
@@ -100,10 +101,10 @@ private:
 ////
 
 MapgenDesc g_reg_mapgens[] = {
-       {"v5",         new MapgenFactoryV5},
-       {"v6",         new MapgenFactoryV6},
-       {"v7",         new MapgenFactoryV7},
-       {"singlenode", new MapgenFactorySinglenode},
+       {"v5",         new MapgenFactoryV5,         true},
+       {"v6",         new MapgenFactoryV6,         true},
+       {"v7",         new MapgenFactoryV7,         true},
+       {"singlenode", new MapgenFactorySinglenode, false},
 };
 
 ////
@@ -343,10 +344,13 @@ bool EmergeManager::isBlockUnderground(v3s16 blockpos)
 }
 
 
-void EmergeManager::getMapgenNames(std::vector<const char *> *mgnames)
+void EmergeManager::getMapgenNames(
+       std::vector<const char *> *mgnames, bool include_hidden)
 {
-       for (u32 i = 0; i != ARRLEN(g_reg_mapgens); i++)
-               mgnames->push_back(g_reg_mapgens[i].name);
+       for (u32 i = 0; i != ARRLEN(g_reg_mapgens); i++) {
+               if (include_hidden || g_reg_mapgens[i].is_user_visible)
+                       mgnames->push_back(g_reg_mapgens[i].name);
+       }
 }
 
 
index 5526a4c91d0832408284b280b6b0f4711948639f..b72b2a2c35fee3e148e8e53a3fde5db86d6b5c78 100644 (file)
@@ -139,7 +139,8 @@ public:
        bool isBlockUnderground(v3s16 blockpos);
 
        static MapgenFactory *getMapgenFactory(const std::string &mgname);
-       static void getMapgenNames(std::vector<const char *> *mgnames);
+       static void getMapgenNames(
+               std::vector<const char *> *mgnames, bool include_hidden);
        static v3s16 getContainingChunk(v3s16 blockpos, s16 chunksize);
 
 private:
index d28925d5c8fa40df58fe5201b044abcb83efcca5..8478cf48a3afb07fb19cbf91cc175a3c9b95f4b5 100644 (file)
@@ -707,7 +707,7 @@ int ModApiMainMenu::l_set_topleft_text(lua_State *L)
 int ModApiMainMenu::l_get_mapgen_names(lua_State *L)
 {
        std::vector<const char *> names;
-       EmergeManager::getMapgenNames(&names);
+       EmergeManager::getMapgenNames(&names, lua_toboolean(L, 1));
 
        lua_newtable(L);
        for (size_t i = 0; i != names.size(); i++) {