Add allowed_mapgens option in game.conf. (#9263)
authorWren Turkal <wt@penguintechs.org>
Mon, 6 Apr 2020 14:06:16 +0000 (07:06 -0700)
committerGitHub <noreply@github.com>
Mon, 6 Apr 2020 14:06:16 +0000 (16:06 +0200)
The game.conf has a disallowed_mapgens option. However, some games
require a certain mapgen to be used, like the CTF plugin. This change
adds an option to specify allowed mapgens so that the setting can be
specified in a way that needn't be updated as map generators are added
to Minetest.

builtin/mainmenu/dlg_create_world.lua
doc/lua_api.txt

index 31d41d693ce98b44ab4c4eab02482c308499a256..f28ae69609a04b4e5021f6e494c9c0c7b07a93cc 100644 (file)
@@ -39,11 +39,24 @@ local function create_world_formspec(dialogdata)
                local gamepath = game_by_gameidx.path
                local gameconfig = Settings(gamepath.."/game.conf")
 
+               local allowed_mapgens = (gameconfig:get("allowed_mapgens") or ""):split()
+               for key, value in pairs(allowed_mapgens) do
+                       allowed_mapgens[key] = value:trim()
+               end
+
                local disallowed_mapgens = (gameconfig:get("disallowed_mapgens") or ""):split()
                for key, value in pairs(disallowed_mapgens) do
                        disallowed_mapgens[key] = value:trim()
                end
 
+               if #allowed_mapgens > 0 then
+                       for i = #mapgens, 1, -1 do
+                               if table.indexof(allowed_mapgens, mapgens[i]) == -1 then
+                                       table.remove(mapgens, i)
+                               end
+                       end
+               end
+
                if disallowed_mapgens then
                        for i = #mapgens, 1, -1 do
                                if table.indexof(disallowed_mapgens, mapgens[i]) > 0 then
index d0b07a4b299536ce1bd19d3fae2872028357d87d..ce9fc61b29d9e95a5cb45d29b64039c50066a9fe 100644 (file)
@@ -64,9 +64,17 @@ The game directory can contain the following files:
 * `game.conf`, with the following keys:
     * `name`: Required, human readable name  e.g. `name = Minetest`
     * `description`: Short description to be shown in the content tab
+    * `allowed_mapgens = <comma-separated mapgens>`
+      e.g. `allowed_mapgens = v5,v6,flat`
+      Mapgens not in this list are removed from the list of mapgens for
+      the game.
+      If not specified, all mapgens are allowed.
     * `disallowed_mapgens = <comma-separated mapgens>`
       e.g. `disallowed_mapgens = v5,v6,flat`
       These mapgens are removed from the list of mapgens for the game.
+      When both `allowed_mapgens` and `disallowed_mapgens` are
+      specified, `allowed_mapgens` is applied before
+      `disallowed_mapgens`.
 * `minetest.conf`:
   Used to set default settings when running this game.
 * `settingtypes.txt`: