3 --------------------------------------------------------------------------------
4 function worldlist.refresh()
5 worldlist.m_raw_worldlist = engine.get_worlds()
9 --------------------------------------------------------------------------------
10 function worldlist.init()
11 worldlist.m_gamefilter = nil
12 worldlist.m_sortmode = "alphabetic"
14 worldlist.m_processed_worldlist = nil
15 worldlist.m_raw_worldlist = engine.get_worlds()
20 --------------------------------------------------------------------------------
21 function worldlist.set_gamefilter(gameid)
22 if gameid == worldlist.m_gamefilter then
25 worldlist.m_gamefilter = gameid
29 --------------------------------------------------------------------------------
30 function worldlist.get_gamefilter()
31 return worldlist.m_gamefilter
34 --------------------------------------------------------------------------------
35 --supported sort mode "alphabetic|none"
36 function worldlist.set_sortmode(mode)
37 if (mode == worldlist.m_sortmode) then
40 worldlist.m_sortmode = mode
44 --------------------------------------------------------------------------------
45 function worldlist.get_list()
46 return worldlist.m_processed_worldlist
49 --------------------------------------------------------------------------------
50 function worldlist.get_raw_list()
51 return worldlist.m_raw_worldlist
54 --------------------------------------------------------------------------------
55 function worldlist.get_raw_world(idx)
56 if type(idx) ~= "number" then
60 if idx ~= nil and idx > 0 and idx < #worldlist.m_raw_worldlist then
61 return worldlist.m_raw_worldlist[idx]
67 --------------------------------------------------------------------------------
68 function worldlist.get_engine_index(worldlistindex)
69 assert(worldlist.m_processed_worldlist ~= nil)
71 if worldlistindex ~= nil and worldlistindex > 0 and
72 worldlistindex <= #worldlist.m_processed_worldlist then
73 local entry = worldlist.m_processed_worldlist[worldlistindex]
75 for i,v in ipairs(worldlist.m_raw_worldlist) do
77 if worldlist.compare(v,entry) then
86 --------------------------------------------------------------------------------
87 function worldlist.get_current_index(worldlistindex)
88 assert(worldlist.m_processed_worldlist ~= nil)
90 if worldlistindex ~= nil and worldlistindex > 0 and
91 worldlistindex <= #worldlist.m_raw_worldlist then
92 local entry = worldlist.m_raw_worldlist[worldlistindex]
94 for i,v in ipairs(worldlist.m_processed_worldlist) do
96 if worldlist.compare(v,entry) then
105 --------------------------------------------------------------------------------
106 function worldlist.process()
107 assert(worldlist.m_raw_worldlist ~= nil)
109 if worldlist.m_sortmode == "none" and
110 worldlist.m_gamefilter == nil then
111 worldlist.m_processed_worldlist = worldlist.m_raw_worldlist
115 worldlist.m_processed_worldlist = {}
117 for i,v in ipairs(worldlist.m_raw_worldlist) do
119 if worldlist.m_gamefilter == nil or
120 v.gameid == worldlist.m_gamefilter then
121 table.insert(worldlist.m_processed_worldlist,v)
125 if worldlist.m_sortmode == "none" then
129 if worldlist.m_sortmode == "alphabetic" then
130 worldlist.sort_alphabetic()
135 --------------------------------------------------------------------------------
136 function worldlist.compare(world1,world2)
138 if world1.path ~= world2.path then
142 if world1.name ~= world2.name then
146 if world1.gameid ~= world2.gameid then
153 --------------------------------------------------------------------------------
154 function worldlist.size()
155 if worldlist.m_processed_worldlist == nil then
159 return #worldlist.m_processed_worldlist
162 --------------------------------------------------------------------------------
163 function worldlist.exists(worldname)
164 for i,v in ipairs(worldlist.m_raw_worldlist) do
165 if v.name == worldname then
173 --------------------------------------------------------------------------------
174 function worldlist.engine_index_by_name(worldname)
177 for i,v in ipairs(worldlist.m_raw_worldlist) do
178 if v.name == worldname then
179 worldcount = worldcount +1
185 -- If there are more worlds than one with same name we can't decide which
186 -- one is meant. This shouldn't be possible but just for sure.
187 if worldcount > 1 then
194 --------------------------------------------------------------------------------
195 function worldlist.sort_alphabetic()
197 table.sort(worldlist.m_processed_worldlist, function(a, b)
200 local count = math.min(#n1, #n2)
203 if n1:sub(i, i):lower() < n2:sub(i, i):lower() then
205 elseif n1:sub(i, i):lower() > n2:sub(i, i):lower() then