Add superflat "mapgen" (#52)
This commit is contained in:
parent
f91eca1e5e
commit
b3e81ae06d
@ -109,6 +109,7 @@ local function create_world_formspec(dialogdata)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local mapgens = core.get_mapgen_names()
|
local mapgens = core.get_mapgen_names()
|
||||||
|
mapgens[#mapgens + 1] = "superflat"
|
||||||
|
|
||||||
local current_seed = core.settings:get("fixed_map_seed") or ""
|
local current_seed = core.settings:get("fixed_map_seed") or ""
|
||||||
local current_mg = core.settings:get("mg_name")
|
local current_mg = core.settings:get("mg_name")
|
||||||
@ -142,13 +143,21 @@ local function create_world_formspec(dialogdata)
|
|||||||
local gameconfig = Settings(gamepath.."/game.conf")
|
local gameconfig = Settings(gamepath.."/game.conf")
|
||||||
|
|
||||||
local allowed_mapgens = (gameconfig:get("allowed_mapgens") or ""):split()
|
local allowed_mapgens = (gameconfig:get("allowed_mapgens") or ""):split()
|
||||||
for key, value in pairs(allowed_mapgens) do
|
for key, value in ipairs(allowed_mapgens) do
|
||||||
allowed_mapgens[key] = value:trim()
|
value = value:trim()
|
||||||
|
allowed_mapgens[key] = value
|
||||||
|
if value == "flat" then
|
||||||
|
allowed_mapgens[#allowed_mapgens + 1] = "superflat"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local disallowed_mapgens = (gameconfig:get("disallowed_mapgens") or ""):split()
|
local disallowed_mapgens = (gameconfig:get("disallowed_mapgens") or ""):split()
|
||||||
for key, value in pairs(disallowed_mapgens) do
|
for key, value in ipairs(disallowed_mapgens) do
|
||||||
disallowed_mapgens[key] = value:trim()
|
value = value:trim()
|
||||||
|
disallowed_mapgens[key] = value
|
||||||
|
if value == "flat" then
|
||||||
|
disallowed_mapgens[#disallowed_mapgens + 1] = "superflat"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if #allowed_mapgens > 0 then
|
if #allowed_mapgens > 0 then
|
||||||
@ -194,7 +203,7 @@ local function create_world_formspec(dialogdata)
|
|||||||
mglist = mglist:sub(1, -2)
|
mglist = mglist:sub(1, -2)
|
||||||
|
|
||||||
local mg_main_flags = function(mapgen, y)
|
local mg_main_flags = function(mapgen, y)
|
||||||
if mapgen == "singlenode" then
|
if mapgen == "singlenode" or mapgen == "superflat" then
|
||||||
return "", y
|
return "", y
|
||||||
end
|
end
|
||||||
if disallowed_mapgen_settings["mg_flags"] then
|
if disallowed_mapgen_settings["mg_flags"] then
|
||||||
@ -397,8 +406,25 @@ local function create_world_buttonhandler(this, fields)
|
|||||||
|
|
||||||
local message
|
local message
|
||||||
if not menudata.worldlist:uid_exists_raw(worldname) then
|
if not menudata.worldlist:uid_exists_raw(worldname) then
|
||||||
core.settings:set("mg_name",fields["dd_mapgen"])
|
local old_mg_flags
|
||||||
|
if fields["dd_mapgen"] == "superflat" then
|
||||||
|
core.settings:set("mg_name", "flat")
|
||||||
|
old_mg_flags = core.settings:get("mg_flags")
|
||||||
|
core.settings:set("mg_flags", "nocaves,nodungeons,nodecorations")
|
||||||
|
else
|
||||||
|
core.settings:set("mg_name", fields["dd_mapgen"])
|
||||||
|
end
|
||||||
message = core.create_world(worldname,gameindex)
|
message = core.create_world(worldname,gameindex)
|
||||||
|
|
||||||
|
-- Restore the old mg_flags setting if creating a superflat world
|
||||||
|
if fields["dd_mapgen"] == "superflat" then
|
||||||
|
core.settings:set("mg_name", "superflat")
|
||||||
|
if old_mg_flags then
|
||||||
|
core.settings:set("mg_flags", old_mg_flags)
|
||||||
|
else
|
||||||
|
core.settings:remove("mg_flags")
|
||||||
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
message = fgettext("A world named \"$1\" already exists", worldname)
|
message = fgettext("A world named \"$1\" already exists", worldname)
|
||||||
end
|
end
|
||||||
|
@ -35,17 +35,13 @@ local function create_world_formspec()
|
|||||||
local game_by_gameidx = core.get_game(gameidx)
|
local game_by_gameidx = core.get_game(gameidx)
|
||||||
if game_by_gameidx ~= nil then
|
if game_by_gameidx ~= nil then
|
||||||
local allowed_mapgens = {"v7p", "flat", "valleys"}
|
local allowed_mapgens = {"v7p", "flat", "valleys"}
|
||||||
for key, value in pairs(allowed_mapgens) do
|
for i = #mapgens, 1, -1 do
|
||||||
allowed_mapgens[key] = value:trim()
|
if table.indexof(allowed_mapgens, mapgens[i]) == -1 then
|
||||||
end
|
table.remove(mapgens, i)
|
||||||
|
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
mapgens[#mapgens + 1] = "superflat"
|
||||||
end
|
end
|
||||||
|
|
||||||
local mglist = ""
|
local mglist = ""
|
||||||
@ -106,8 +102,25 @@ local function create_world_buttonhandler(this, fields)
|
|||||||
|
|
||||||
local message
|
local message
|
||||||
if not menudata.worldlist:uid_exists_raw(worldname) then
|
if not menudata.worldlist:uid_exists_raw(worldname) then
|
||||||
core.settings:set("mg_name",fields["dd_mapgen"])
|
local old_mg_flags
|
||||||
|
if fields["dd_mapgen"] == "superflat" then
|
||||||
|
core.settings:set("mg_name", "flat")
|
||||||
|
old_mg_flags = core.settings:get("mg_flags")
|
||||||
|
core.settings:set("mg_flags", "nocaves,nodungeons,nodecorations")
|
||||||
|
else
|
||||||
|
core.settings:set("mg_name", fields["dd_mapgen"])
|
||||||
|
end
|
||||||
message = core.create_world(worldname,gameindex)
|
message = core.create_world(worldname,gameindex)
|
||||||
|
|
||||||
|
-- Restore the old mg_flags setting if creating a superflat world
|
||||||
|
if fields["dd_mapgen"] == "superflat" then
|
||||||
|
core.settings:set("mg_name", "superflat")
|
||||||
|
if old_mg_flags then
|
||||||
|
core.settings:set("mg_flags", old_mg_flags)
|
||||||
|
else
|
||||||
|
core.settings:remove("mg_flags")
|
||||||
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
message = fgettext("A world named \"$1\" already exists", worldname)
|
message = fgettext("A world named \"$1\" already exists", worldname)
|
||||||
end
|
end
|
||||||
@ -131,7 +144,6 @@ local function create_world_buttonhandler(this, fields)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
if fields["world_create_cancel"] then
|
if fields["world_create_cancel"] then
|
||||||
this:delete()
|
this:delete()
|
||||||
return true
|
return true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user