Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give subgames the ability to disallow specific mapgens #6792

Merged
merged 5 commits into from Dec 16, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion builtin/common/misc_helpers.lua
Expand Up @@ -551,7 +551,7 @@ end
--------------------------------------------------------------------------------
if INIT == "mainmenu" then
function core.get_game(index)
local games = game.get_games()
local games = core.get_games()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, was this a bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup.


if index > 0 and index <= #games then
return games[index]
Expand Down
36 changes: 25 additions & 11 deletions builtin/mainmenu/dlg_create_world.lua
Expand Up @@ -20,6 +20,29 @@ local function create_world_formspec(dialogdata)

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 = minetest.get_game(gameidx).path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

core.get_game

local gameconfig = Settings(gamepath.."/game.conf")

local disallowed_mapgens = gameconfig:get("disallowed_mapgens")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local disallowed_mapgens = gameconfig:get("disallowed_mapgens"):lower():split()
for key, value in pairs(disallowed_mapgens) do
     disallowed_mapgens[key] = value:trim()
end


if disallowed_mapgens then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superfluous check. string.split never returns nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rubenwardy requested it be this way. I know his commented version is a little different, but he asked me to adjust to this, so will see what he says.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't notice this aha, krock is right unfortunately. But doesn't matter too much

for i = #mapgens, 1, -1 do
if string.find(disallowed_mapgens, mapgens[i]) then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if table.indexof(disallowed, mapgens[i]:lower()) > 0 then

table.remove(mapgens, i)
end
end
end

local mglist = ""
local selindex = 1
Expand All @@ -32,17 +55,6 @@ 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 =
Expand Down Expand Up @@ -122,6 +134,8 @@ local function create_world_buttonhandler(this, fields)
end

if fields["games"] then
local gameindex = core.get_textlist_index("games")
core.settings:set("menu_last_game", gamemgr.games[gameindex].id)
return true
end

Expand Down
12 changes: 11 additions & 1 deletion doc/lua_api.txt
Expand Up @@ -53,14 +53,24 @@ 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>

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.
Expand Down