Worldlist fixes

Add alphabeticaly sorted worldlists
Select world after creation
Move worldlist handling to separate file
Merge world selection of singleplayer/server tab
Remove some useless code
This commit is contained in:
sapier 2013-07-09 23:17:38 +02:00 committed by PilzAdam
parent e8f201cefa
commit 52beafff53
2 changed files with 309 additions and 199 deletions

@ -2,6 +2,7 @@ os.setlocale("C", "numeric")
local scriptpath = engine.get_scriptdir() local scriptpath = engine.get_scriptdir()
dofile(scriptpath .. DIR_DELIM .. "mainmenu_worldlist.lua")
dofile(scriptpath .. DIR_DELIM .. "modmgr.lua") dofile(scriptpath .. DIR_DELIM .. "modmgr.lua")
dofile(scriptpath .. DIR_DELIM .. "modstore.lua") dofile(scriptpath .. DIR_DELIM .. "modstore.lua")
dofile(scriptpath .. DIR_DELIM .. "gamemgr.lua") dofile(scriptpath .. DIR_DELIM .. "gamemgr.lua")
@ -151,12 +152,16 @@ end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
function menu.update_gametype() function menu.update_gametype()
if (menu.game_last_check == nil or if (menu.game_last_check == nil or
menu.game_last_check ~= menu.last_game) and menu.game_last_check ~= menu.last_game) and
tabbuilder.current_tab == "singleplayer" then tabbuilder.current_tab == "singleplayer" then
local gamedetails = menu.lastgame() local gamedetails = menu.lastgame()
engine.set_topleft_text(gamedetails.name) engine.set_topleft_text(gamedetails.name)
worldlist.set_gamefilter(gamedetails.id)
--background --background
local background_set = false local background_set = false
@ -198,6 +203,7 @@ end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
function menu.reset_gametype() function menu.reset_gametype()
worldlist.set_gamefilter(nil)
menu.game_last_check = nil menu.game_last_check = nil
local path_background_texture = menu.basetexturedir .. "menu_background.png" local path_background_texture = menu.basetexturedir .. "menu_background.png"
@ -295,77 +301,30 @@ function update_menu()
end end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
function menu.filtered_game_list() function menu.render_world_list()
local retval = "" local retval = ""
local current_game = menu.lastgame()
for i=1,#menu.worldlist,1 do local current_worldlist = worldlist.get_list()
if menu.worldlist[i].gameid == current_game.id then
if retval ~= "" then
retval = retval ..","
end
retval = retval .. menu.worldlist[i].name ..
" \\[" .. menu.worldlist[i].gameid .. "\\]"
end
end
return retval for i,v in ipairs(current_worldlist) do
end if retval ~= "" then
retval = retval ..","
--------------------------------------------------------------------------------
function menu.filtered_game_list_raw()
local retval = {}
local current_game = menu.lastgame()
for i=1,#menu.worldlist,1 do
if menu.worldlist[i].gameid == current_game.id then
table.insert(retval,menu.worldlist[i])
end
end
return retval
end
--------------------------------------------------------------------------------
function menu.filtered_index_to_plain(filtered_index)
local current_game = menu.lastgame()
local temp_idx = 0
if menu.worldlist == nil then
return -1
end
for i=1,#menu.worldlist,1 do
if menu.worldlist[i].gameid == current_game.id then
temp_idx = temp_idx +1
end end
if temp_idx == filtered_index then retval = retval .. v.name ..
return i " \\[" .. v.gameid .. "\\]"
end
end end
return -1
return retval
end end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
function menu.init() function menu.init()
--init menu data --init menu data
gamemgr.update_gamelist() gamemgr.update_gamelist()
menu.worldlist = engine.get_worlds()
menu.last_world = tonumber(engine.setting_get("main_menu_last_world_idx"))
menu.last_game = tonumber(engine.setting_get("main_menu_last_game_idx")) menu.last_game = tonumber(engine.setting_get("main_menu_last_game_idx"))
if type(menu.last_world) ~= "number" then
menu.last_world = 1
end
if type(menu.last_game) ~= "number" then if type(menu.last_game) ~= "number" then
menu.last_game = 1 menu.last_game = 1
end end
@ -405,41 +364,50 @@ function menu.lastgame()
end end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
function menu.lastworld() function menu.update_last_game()
if menu.last_world ~= nil and
menu.last_world > 0 and local current_world = worldlist.get_raw_world(
menu.last_world <= #menu.worldlist then engine.setting_get("mainmenu_last_selected_world")
return menu.worldlist[menu.last_world] )
if current_world == nil then
return
end end
if #menu.worldlist >= 1 then for i=1,#gamemgr.games,1 do
menu.last_world = 1 if gamemgr.games[i].id == current_world.gameid then
return menu.worldlist[menu.last_world] menu.last_game = i
engine.setting_set("main_menu_last_game_idx",menu.last_game)
break
end
end end
--error case!!
return nil
end end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
function menu.update_last_game(world_idx) function menu.handle_key_up_down(fields,textlist,settingname)
if gamedata.selected_world <= #menu.worldlist then
local world = menu.worldlist[gamedata.selected_world] if fields["key_up"] then
local oldidx = engine.get_textlist_index(textlist)
if world == nil then if oldidx > 1 then
return local newidx = oldidx -1
engine.setting_set(settingname,
worldlist.get_engine_index(newidx))
end end
end
if fields["key_down"] then
local oldidx = engine.get_textlist_index(textlist)
for i=1,#gamemgr.games,1 do if oldidx < worldlist.size() then
if gamemgr.games[i].id == world.gameid then local newidx = oldidx + 1
menu.last_game = i engine.setting_set(settingname,
engine.setting_set("main_menu_last_game_idx",menu.last_game) worldlist.get_engine_index(newidx))
break
end
end end
end end
end end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
function menubar.handle_buttons(fields) function menubar.handle_buttons(fields)
for i=1,#menubar.buttons,1 do for i=1,#menubar.buttons,1 do
@ -535,7 +503,7 @@ end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
function tabbuilder.dialog_delete_world() function tabbuilder.dialog_delete_world()
return "label[2,2;Delete World \"" .. menu.lastworld().name .. "\"?]".. return "label[2,2;Delete World \"" .. worldlist.get_raw_list()[menu.world_to_del].name .. "\"?]"..
"button[3.5,4.2;2.6,0.5;world_delete_confirm;Yes]" .. "button[3.5,4.2;2.6,0.5;world_delete_confirm;Yes]" ..
"button[6,4.2;2.8,0.5;world_delete_cancel;No]" "button[6,4.2;2.8,0.5;world_delete_cancel;No]"
end end
@ -594,19 +562,10 @@ function tabbuilder.handle_create_world_buttons(fields)
if gameindex > 0 and if gameindex > 0 and
worldname ~= "" then worldname ~= "" then
menu.worldlist = engine.get_worlds()
local found = false
for i=1,#menu.worldlist,1 do
if menu.worldlist[i].name == worldname then
found = true
break
end
end
local message = nil local message = nil
if not found then if not worldlist.exists(worldname) then
engine.setting_set("mg_name",fields["dd_mapgen"]) engine.setting_set("mg_name",fields["dd_mapgen"])
message = engine.create_world(worldname,gameindex) message = engine.create_world(worldname,gameindex)
else else
@ -618,25 +577,10 @@ function tabbuilder.handle_create_world_buttons(fields)
else else
menu.last_game = gameindex menu.last_game = gameindex
engine.setting_set("main_menu_last_game_idx",gameindex) engine.setting_set("main_menu_last_game_idx",gameindex)
menu.worldlist = engine.get_worlds()
local worldlist = menu.worldlist worldlist.refresh()
engine.setting_set("mainmenu_last_selected_world",
if tabbuilder.current_tab == "singleplayer" then worldlist.engine_index_by_name(worldname))
worldlist = menu.filtered_game_list_raw()
end
local index = 0
for i=1,#worldlist,1 do
if worldlist[i].name == worldname then
index = i
break
end
end
engine.setting_set("main_menu_singleplayer_world_idx", index)
menu.last_world = index
end end
else else
gamedata.errormessage = "No worldname given or no game selected" gamedata.errormessage = "No worldname given or no game selected"
@ -648,6 +592,7 @@ function tabbuilder.handle_create_world_buttons(fields)
return return
end end
--close dialog
tabbuilder.is_dialog = false tabbuilder.is_dialog = false
tabbuilder.show_buttons = true tabbuilder.show_buttons = true
tabbuilder.current_tab = engine.setting_get("main_menu_tab") tabbuilder.current_tab = engine.setting_get("main_menu_tab")
@ -657,11 +602,11 @@ end
function tabbuilder.handle_delete_world_buttons(fields) function tabbuilder.handle_delete_world_buttons(fields)
if fields["world_delete_confirm"] then if fields["world_delete_confirm"] then
if menu.last_world > 0 and if menu.world_to_del > 0 and
menu.last_world <= #menu.worldlist then menu.world_to_del <= #worldlist.get_raw_list() then
engine.delete_world(menu.last_world) engine.delete_world(menu.world_to_del)
menu.worldlist = engine.get_worlds() menu.world_to_del = 0
menu.last_world = 1 worldlist.refresh()
end end
end end
@ -811,27 +756,12 @@ function tabbuilder.handle_server_buttons(fields)
world_doubleclick = true world_doubleclick = true
end end
if event.typ == "CHG" then if event.typ == "CHG" then
engine.setting_set("main_menu_last_world_idx",engine.get_textlist_index("srv_worlds")) engine.setting_set("mainmenu_last_selected_world",
worldlist.get_engine_index(engine.get_textlist_index("srv_worlds")))
end end
end end
if fields["key_up"] then menu.handle_key_up_down(fields,"srv_worlds","mainmenu_last_selected_world")
local oldidx = engine.get_textlist_index("srv_worlds")
if oldidx > 1 then
local newidx = oldidx -1
engine.setting_set("main_menu_last_world_idx",newidx)
end
end
if fields["key_down"] then
local oldidx = engine.get_textlist_index("srv_worlds")
if oldidx < #menu.worldlist then
local newidx = oldidx + 1
engine.setting_set("main_menu_last_world_idx",newidx)
end
end
if fields["cb_creative_mode"] then if fields["cb_creative_mode"] then
engine.setting_setbool("creative_mode",tabbuilder.tobool(fields["cb_creative_mode"])) engine.setting_setbool("creative_mode",tabbuilder.tobool(fields["cb_creative_mode"]))
@ -845,21 +775,16 @@ function tabbuilder.handle_server_buttons(fields)
engine.setting_setbool("server_announce",tabbuilder.tobool(fields["cb_server_announce"])) engine.setting_setbool("server_announce",tabbuilder.tobool(fields["cb_server_announce"]))
end end
if fields["start_server"] ~= nil or if fields["start_server"] ~= nil or
world_doubleclick or world_doubleclick or
fields["key_enter"] then fields["key_enter"] then
local selected = engine.get_textlist_index("srv_worlds") local selected = engine.get_textlist_index("srv_worlds")
if selected > 0 then if selected > 0 then
gamedata.playername = fields["te_playername"] gamedata.playername = fields["te_playername"]
gamedata.password = fields["te_passwd"] gamedata.password = fields["te_passwd"]
gamedata.port = fields["te_serverport"] gamedata.port = fields["te_serverport"]
gamedata.address = "" gamedata.address = ""
gamedata.selected_world = selected gamedata.selected_world = worldlist.get_engine_index(selected)
engine.setting_set("main_menu_tab",tabbuilder.current_tab)
engine.setting_set("main_menu_last_world_idx",gamedata.selected_world)
menu.update_last_game(gamedata.selected_world) menu.update_last_game(gamedata.selected_world)
engine.start() engine.start()
@ -874,16 +799,18 @@ function tabbuilder.handle_server_buttons(fields)
if fields["world_delete"] ~= nil then if fields["world_delete"] ~= nil then
local selected = engine.get_textlist_index("srv_worlds") local selected = engine.get_textlist_index("srv_worlds")
if selected > 0 then if selected > 0 and
menu.last_world = engine.get_textlist_index("srv_worlds") selected <= worldlist.size() then
if menu.lastworld() ~= nil and local world = worldlist.get_list()[selected]
menu.lastworld().name ~= nil and if world ~= nil and
menu.lastworld().name ~= "" then world.name ~= nil and
world.name ~= "" then
menu.world_to_del = worldlist.get_engine_index(selected)
tabbuilder.current_tab = "dialog_delete_world" tabbuilder.current_tab = "dialog_delete_world"
tabbuilder.is_dialog = true tabbuilder.is_dialog = true
tabbuilder.show_buttons = false tabbuilder.show_buttons = false
else else
menu.last_world = 0 menu.world_to_del = 0
end end
end end
end end
@ -891,7 +818,7 @@ function tabbuilder.handle_server_buttons(fields)
if fields["world_configure"] ~= nil then if fields["world_configure"] ~= nil then
selected = engine.get_textlist_index("srv_worlds") selected = engine.get_textlist_index("srv_worlds")
if selected > 0 then if selected > 0 then
modmgr.world_config_selected_world = selected modmgr.world_config_selected_world = worldlist.get_engine_index(selected)
if modmgr.init_worldconfig() then if modmgr.init_worldconfig() then
tabbuilder.current_tab = "dialog_configure_world" tabbuilder.current_tab = "dialog_configure_world"
tabbuilder.is_dialog = true tabbuilder.is_dialog = true
@ -970,27 +897,12 @@ function tabbuilder.handle_singleplayer_buttons(fields)
end end
if event.typ == "CHG" then if event.typ == "CHG" then
engine.setting_set("main_menu_singleplayer_world_idx",engine.get_textlist_index("sp_worlds")) engine.setting_set("mainmenu_last_selected_world",
worldlist.get_engine_index(engine.get_textlist_index("sp_worlds")))
end end
end end
if fields["key_up"] then menu.handle_key_up_down(fields,"sp_worlds","mainmenu_last_selected_world")
local oldidx = engine.get_textlist_index("sp_worlds")
if oldidx > 1 then
local newidx = oldidx -1
engine.setting_set("main_menu_singleplayer_world_idx",newidx)
end
end
if fields["key_down"] then
local oldidx = engine.get_textlist_index("sp_worlds")
if oldidx < #menu.filtered_game_list_raw() then
local newidx = oldidx + 1
engine.setting_set("main_menu_singleplayer_world_idx",newidx)
end
end
if fields["cb_creative_mode"] then if fields["cb_creative_mode"] then
engine.setting_setbool("creative_mode",tabbuilder.tobool(fields["cb_creative_mode"])) engine.setting_setbool("creative_mode",tabbuilder.tobool(fields["cb_creative_mode"]))
@ -1005,11 +917,8 @@ function tabbuilder.handle_singleplayer_buttons(fields)
fields["key_enter"] then fields["key_enter"] then
local selected = engine.get_textlist_index("sp_worlds") local selected = engine.get_textlist_index("sp_worlds")
if selected > 0 then if selected > 0 then
gamedata.selected_world = menu.filtered_index_to_plain(selected) gamedata.selected_world = worldlist.get_engine_index(selected)
gamedata.singleplayer = true gamedata.singleplayer = true
engine.setting_set("main_menu_tab",tabbuilder.current_tab)
engine.setting_set("main_menu_singleplayer_world_idx",selected)
menu.update_last_game(gamedata.selected_world) menu.update_last_game(gamedata.selected_world)
@ -1025,16 +934,18 @@ function tabbuilder.handle_singleplayer_buttons(fields)
if fields["world_delete"] ~= nil then if fields["world_delete"] ~= nil then
local selected = engine.get_textlist_index("sp_worlds") local selected = engine.get_textlist_index("sp_worlds")
if selected > 0 then if selected > 0 and
menu.last_world = menu.filtered_index_to_plain(selected) selected <= worldlist.size() then
if menu.lastworld() ~= nil and local world = worldlist.get_list()[selected]
menu.lastworld().name ~= nil and if world ~= nil and
menu.lastworld().name ~= "" then world.name ~= nil and
world.name ~= "" then
menu.world_to_del = worldlist.get_engine_index(selected)
tabbuilder.current_tab = "dialog_delete_world" tabbuilder.current_tab = "dialog_delete_world"
tabbuilder.is_dialog = true tabbuilder.is_dialog = true
tabbuilder.show_buttons = false tabbuilder.show_buttons = false
else else
menu.last_world = 0 menu.world_to_del = 0
end end
end end
end end
@ -1042,7 +953,7 @@ function tabbuilder.handle_singleplayer_buttons(fields)
if fields["world_configure"] ~= nil then if fields["world_configure"] ~= nil then
selected = engine.get_textlist_index("sp_worlds") selected = engine.get_textlist_index("sp_worlds")
if selected > 0 then if selected > 0 then
modmgr.world_config_selected_world = menu.filtered_index_to_plain(selected) modmgr.world_config_selected_world = worldlist.get_engine_index(selected)
if modmgr.init_worldconfig() then if modmgr.init_worldconfig() then
tabbuilder.current_tab = "dialog_configure_world" tabbuilder.current_tab = "dialog_configure_world"
tabbuilder.is_dialog = true tabbuilder.is_dialog = true
@ -1180,11 +1091,10 @@ end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
function tabbuilder.tab_server() function tabbuilder.tab_server()
local index = engine.setting_get("main_menu_last_world_idx")
local index = worldlist.get_current_index(
if index == nil then tonumber(engine.setting_get("mainmenu_last_selected_world"))
index = 0 )
end
local retval = local retval =
"button[4,4.15;2.6,0.5;world_delete;Delete]" .. "button[4,4.15;2.6,0.5;world_delete;Delete]" ..
@ -1203,20 +1113,9 @@ function tabbuilder.tab_server()
engine.setting_get("name") .. "]" .. engine.setting_get("name") .. "]" ..
"pwdfield[0.8,4.2;3,0.5;te_passwd;Password]" .. "pwdfield[0.8,4.2;3,0.5;te_passwd;Password]" ..
"field[0.8,5.2;3,0.5;te_serverport;Server Port;30000]" .. "field[0.8,5.2;3,0.5;te_serverport;Server Port;30000]" ..
"textlist[4,0.25;7.5,3.7;srv_worlds;" "textlist[4,0.25;7.5,3.7;srv_worlds;" ..
menu.render_world_list() ..
if #menu.worldlist > 0 then ";" .. index .. "]"
retval = retval .. menu.worldlist[1].name ..
" \\[" .. menu.worldlist[1].gameid .. "\\]"
for i=2,#menu.worldlist,1 do
retval = retval .. "," .. menu.worldlist[i].name ..
" \\[" .. menu.worldlist[i].gameid .. "\\]"
end
retval = retval .. ";" .. index .. "]"
else
retval = retval .. ";0]"
end
return retval return retval
end end
@ -1244,12 +1143,10 @@ end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
function tabbuilder.tab_singleplayer() function tabbuilder.tab_singleplayer()
local index = engine.setting_get("main_menu_singleplayer_world_idx")
local index = worldlist.get_current_index(
if index == nil or tonumber(engine.setting_get("mainmenu_last_selected_world"))
#menu.filtered_game_list_raw() == 0 then )
index = 0
end
return "button[4,4.15;2.6,0.5;world_delete;Delete]" .. return "button[4,4.15;2.6,0.5;world_delete;Delete]" ..
"button[6.5,4.15;2.8,0.5;world_create;New]" .. "button[6.5,4.15;2.8,0.5;world_create;New]" ..
@ -1262,7 +1159,7 @@ function tabbuilder.tab_singleplayer()
"checkbox[0.5,0.7;cb_enable_damage;Enable Damage;" .. "checkbox[0.5,0.7;cb_enable_damage;Enable Damage;" ..
dump(engine.setting_getbool("enable_damage")) .. "]".. dump(engine.setting_getbool("enable_damage")) .. "]"..
"textlist[4,0.25;7.5,3.7;sp_worlds;" .. "textlist[4,0.25;7.5,3.7;sp_worlds;" ..
menu.filtered_game_list() .. menu.render_world_list() ..
";" .. index .. "]" .. ";" .. index .. "]" ..
menubar.formspec menubar.formspec
end end
@ -1406,8 +1303,10 @@ end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
init_globals() init_globals()
worldlist.init()
menu.init() menu.init()
tabbuilder.init() tabbuilder.init()
menubar.refresh() menubar.refresh()
modstore.init() modstore.init()
update_menu() update_menu()

@ -0,0 +1,211 @@
worldlist = {}
--------------------------------------------------------------------------------
function worldlist.refresh()
worldlist.m_raw_worldlist = engine.get_worlds()
worldlist.process()
end
--------------------------------------------------------------------------------
function worldlist.init()
worldlist.m_gamefilter = nil
worldlist.m_sortmode = "alphabetic"
worldlist.m_processed_worldlist = nil
worldlist.m_raw_worldlist = engine.get_worlds()
worldlist.process()
end
--------------------------------------------------------------------------------
function worldlist.set_gamefilter(gameid)
if gameid == worldlist.m_gamefilter then
return
end
worldlist.m_gamefilter = gameid
worldlist.process()
end
--------------------------------------------------------------------------------
function worldlist.get_gamefilter()
return worldlist.m_gamefilter
end
--------------------------------------------------------------------------------
--supported sort mode "alphabetic|none"
function worldlist.set_sortmode(mode)
if (mode == worldlist.m_sortmode) then
return
end
worldlist.m_sortmode = mode
worldlist.process()
end
--------------------------------------------------------------------------------
function worldlist.get_list()
return worldlist.m_processed_worldlist
end
--------------------------------------------------------------------------------
function worldlist.get_raw_list()
return worldlist.m_raw_worldlist
end
--------------------------------------------------------------------------------
function worldlist.get_raw_world(idx)
if type(idx) ~= "number" then
idx = tonumber(idx)
end
if idx ~= nil and idx > 0 and idx < #worldlist.m_raw_worldlist then
return worldlist.m_raw_worldlist[idx]
end
return nil
end
--------------------------------------------------------------------------------
function worldlist.get_engine_index(worldlistindex)
assert(worldlist.m_processed_worldlist ~= nil)
if worldlistindex ~= nil and worldlistindex > 0 and
worldlistindex <= #worldlist.m_processed_worldlist then
local entry = worldlist.m_processed_worldlist[worldlistindex]
for i,v in ipairs(worldlist.m_raw_worldlist) do
if worldlist.compare(v,entry) then
return i
end
end
end
return 0
end
--------------------------------------------------------------------------------
function worldlist.get_current_index(worldlistindex)
assert(worldlist.m_processed_worldlist ~= nil)
if worldlistindex ~= nil and worldlistindex > 0 and
worldlistindex <= #worldlist.m_raw_worldlist then
local entry = worldlist.m_raw_worldlist[worldlistindex]
for i,v in ipairs(worldlist.m_processed_worldlist) do
if worldlist.compare(v,entry) then
return i
end
end
end
return 0
end
--------------------------------------------------------------------------------
function worldlist.process()
assert(worldlist.m_raw_worldlist ~= nil)
if worldlist.m_sortmode == "none" and
worldlist.m_gamefilter == nil then
worldlist.m_processed_worldlist = worldlist.m_raw_worldlist
return
end
worldlist.m_processed_worldlist = {}
for i,v in ipairs(worldlist.m_raw_worldlist) do
if worldlist.m_gamefilter == nil or
v.gameid == worldlist.m_gamefilter then
table.insert(worldlist.m_processed_worldlist,v)
end
end
if worldlist.m_sortmode == "none" then
return
end
if worldlist.m_sortmode == "alphabetic" then
worldlist.sort_alphabetic()
end
end
--------------------------------------------------------------------------------
function worldlist.compare(world1,world2)
if world1.path ~= world2.path then
return false
end
if world1.name ~= world2.name then
return false
end
if world1.gameid ~= world2.gameid then
return false
end
return true
end
--------------------------------------------------------------------------------
function worldlist.size()
if worldlist.m_processed_worldlist == nil then
return 0
end
return #worldlist.m_processed_worldlist
end
--------------------------------------------------------------------------------
function worldlist.exists(worldname)
for i,v in ipairs(worldlist.m_raw_worldlist) do
if v.name == worldname then
return true
end
end
return false
end
--------------------------------------------------------------------------------
function worldlist.engine_index_by_name(worldname)
local worldcount = 0
local worldidx = 0
for i,v in ipairs(worldlist.m_raw_worldlist) do
if v.name == worldname then
worldcount = worldcount +1
worldidx = i
end
end
-- If there are more worlds than one with same name we can't decide which
-- one is meant. This shouldn't be possible but just for sure.
if worldcount > 1 then
worldidx=0
end
return worldidx
end
--------------------------------------------------------------------------------
function worldlist.sort_alphabetic()
table.sort(worldlist.m_processed_worldlist, function(a, b)
local n1 = a.name
local n2 = b.name
local count = math.min(#n1, #n2)
for i=1,count do
if n1:sub(i, i):lower() < n2:sub(i, i):lower() then
return true
elseif n1:sub(i, i):lower() > n2:sub(i, i):lower() then
return false
end
end
return (#n1 <= #n2)
end)
end