diff options
author | Paramat <paramat@users.noreply.github.com> | 2020-10-13 00:52:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-13 00:52:53 +0100 |
commit | d6711025461b00d8c244b28d77abd09ccd7cd4b4 (patch) | |
tree | ab5ce03dfb0bab504e9dbacf4512fd9e5d45716a /builtin/mainmenu | |
parent | 272b72361acc70dbc047a90a98dbf7d2e9bfd323 (diff) | |
download | minetest-d6711025461b00d8c244b28d77abd09ccd7cd4b4.tar.gz minetest-d6711025461b00d8c244b28d77abd09ccd7cd4b4.tar.bz2 minetest-d6711025461b00d8c244b28d77abd09ccd7cd4b4.zip |
Give unnamed world names incrementing numbers. Format 'world<number>' (#10247)
Code created with help from GitHub users sirrobzeroone and pauloue, thank you.
Diffstat (limited to 'builtin/mainmenu')
-rw-r--r-- | builtin/mainmenu/dlg_create_world.lua | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/builtin/mainmenu/dlg_create_world.lua b/builtin/mainmenu/dlg_create_world.lua index b2e706b6b..7566d2409 100644 --- a/builtin/mainmenu/dlg_create_world.lua +++ b/builtin/mainmenu/dlg_create_world.lua @@ -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"]) |