Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Give unnamed world names incrementing numbers. Format 'world<number>' (
…#10247)

Code created with help from GitHub users sirrobzeroone and pauloue, thank you.
  • Loading branch information
paramat committed Oct 12, 2020
1 parent 272b723 commit d671102
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions builtin/mainmenu/dlg_create_world.lua
Expand Up @@ -363,10 +363,18 @@ local function create_world_buttonhandler(this, fields)
local gameindex = core.get_textlist_index("games")

if gameindex ~= nil then
-- For unnamed worlds use the generated name 'world<number>',
-- where the number increments: it is set to 1 larger than the largest
-- generated name number found.
if worldname == "" then
local random_number = math.random(10000, 99999)
local random_world_name = "Unnamed" .. random_number
worldname = random_world_name
local worldnum_max = 0
for _, world in ipairs(menudata.worldlist:get_list()) do
if world.name:match("^world%d+$") then
local worldnum = tonumber(world.name:sub(6))
worldnum_max = math.max(worldnum_max, worldnum)
end
end
worldname = "world" .. worldnum_max + 1
end

core.settings:set("fixed_map_seed", fields["te_seed"])
Expand Down

0 comments on commit d671102

Please sign in to comment.