Give unnamed world names incrementing numbers. Format 'world<number>' (#10247)

Code created with help from GitHub users sirrobzeroone and pauloue, thank you.
This commit is contained in:
Paramat 2020-10-13 00:52:53 +01:00 committed by GitHub
parent 272b72361a
commit d671102546
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -363,10 +363,18 @@ local function create_world_buttonhandler(this, fields)
local gameindex = core.get_textlist_index("games") local gameindex = core.get_textlist_index("games")
if gameindex ~= nil then 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 if worldname == "" then
local random_number = math.random(10000, 99999) local worldnum_max = 0
local random_world_name = "Unnamed" .. random_number for _, world in ipairs(menudata.worldlist:get_list()) do
worldname = random_world_name 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 end
core.settings:set("fixed_map_seed", fields["te_seed"]) core.settings:set("fixed_map_seed", fields["te_seed"])