Give subgames the ability to disallow specific mapgens (#6792)
authorEzhh <owlecho@live.com>
Sat, 16 Dec 2017 16:02:08 +0000 (16:02 +0000)
committerSmallJoker <SmallJoker@users.noreply.github.com>
Sat, 16 Dec 2017 16:02:08 +0000 (17:02 +0100)
builtin/common/misc_helpers.lua
builtin/mainmenu/dlg_create_world.lua
doc/lua_api.txt

index 01237f265248d3075bf5685c42e7a7fe6dd9ca22..baa9be2681f1718cf50b1f9683846938c3273da2 100644 (file)
@@ -551,7 +551,7 @@ end
 --------------------------------------------------------------------------------
 if INIT == "mainmenu" then
        function core.get_game(index)
-               local games = game.get_games()
+               local games = core.get_games()
 
                if index > 0 and index <= #games then
                        return games[index]
index 4e88ccc48a1f1205b02a5eadf1219078f96d0ba3..380f0654f5802f1e011cbf5d10f9f3c501882ede 100644 (file)
 --with this program; if not, write to the Free Software Foundation, Inc.,
 --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
+local worldname = ""
+
 local function create_world_formspec(dialogdata)
        local mapgens = core.get_mapgen_names()
 
        local current_seed = core.settings:get("fixed_map_seed") or ""
        local current_mg   = core.settings:get("mg_name")
+       local gameid = core.settings:get("menu_last_game")
+
+       local game, gameidx = nil , 0
+       if gameid ~= nil then
+               game, gameidx = gamemgr.find_by_gameid(gameid)
+               
+               if gameidx == nil then
+                       gameidx = 0
+               end
+       end
+
+       local gamepath = core.get_game(gameidx).path
+       local gameconfig = Settings(gamepath.."/game.conf")
+
+       local disallowed_mapgens = (gameconfig:get("disallowed_mapgens") or ""):split()
+       for key, value in pairs(disallowed_mapgens) do
+               disallowed_mapgens[key] = value:trim()
+       end
+
+       if disallowed_mapgens then
+               for i = #mapgens, 1, -1 do
+                       if table.indexof(disallowed_mapgens, mapgens[i]) > 0 then
+                               table.remove(mapgens, i)
+                       end
+               end
+       end
 
        local mglist = ""
        local selindex = 1
@@ -32,23 +60,12 @@ local function create_world_formspec(dialogdata)
                mglist = mglist .. v .. ","
        end
        mglist = mglist:sub(1, -2)
-       
-       local gameid = core.settings:get("menu_last_game")
-       
-       local game, gameidx = nil , 0
-       if gameid ~= nil then
-               game, gameidx = gamemgr.find_by_gameid(gameid)
-               
-               if gameidx == nil then
-                       gameidx = 0
-               end
-       end
 
        current_seed = core.formspec_escape(current_seed)
        local retval =
                "size[11.5,6.5,true]" ..
                "label[2,0;" .. fgettext("World name") .. "]"..
-               "field[4.5,0.4;6,0.5;te_world_name;;]" ..
+               "field[4.5,0.4;6,0.5;te_world_name;;" .. minetest.formspec_escape(worldname) .. "]" ..
 
                "label[2,1;" .. fgettext("Seed") .. "]"..
                "field[4.5,1.4;6,0.5;te_seed;;".. current_seed .. "]" ..
@@ -121,10 +138,14 @@ local function create_world_buttonhandler(this, fields)
                return true
        end
 
+       worldname = fields.te_world_name
+
        if fields["games"] then
+               local gameindex = core.get_textlist_index("games")
+               core.settings:set("menu_last_game", gamemgr.games[gameindex].id)
                return true
        end
-       
+
        if fields["world_create_cancel"] then
                this:delete()
                return true
@@ -135,6 +156,7 @@ end
 
 
 function create_create_world_dlg(update_worldlistfilter)
+       worldname = ""
        local retval = dialog_create("sp_create_world",
                                        create_world_formspec,
                                        create_world_buttonhandler,
index 7ffd17a42b05d615db810cdbe926bc978ae9c980..aba01fa1d07324b4df29cc55ce0a3f70f5e3f529 100644 (file)
@@ -53,7 +53,7 @@ Games are looked up from:
 
 where `gameid` is unique to each game.
 
-The game directory contains the file `game.conf`, which contains these fields:
+The game directory contains the file `game.conf`, which contains:
 
     name = <Human-readable full name of the game>
 
@@ -61,6 +61,16 @@ e.g.
 
     name = Minetest
 
+Optionally, game.conf can also contain:
+
+    disallowed_mapgens = <comma-separated mapgens>
+
+e.g.
+
+    disallowed_mapgens = v5,v6,flat
+
+These mapgens are removed from the list of mapgens for the game.
+
 The game directory can contain the file minetest.conf, which will be used
 to set default settings when running the particular game.
 It can also contain a settingtypes.txt in the same format as the one in builtin.