Change map init (maybe might work) #5
@ -2,41 +2,61 @@ local discordia=require('discordia')
|
|||||||
local API=require('./../strafes_net.lua')
|
local API=require('./../strafes_net.lua')
|
||||||
discordia.extensions()
|
discordia.extensions()
|
||||||
API.MAPS={}
|
API.MAPS={}
|
||||||
for _,game in next,API.GAMES do
|
|
||||||
if type(tonumber(game)) == 'number' then
|
local function insert(t, value)
|
||||||
local maps = {count=0}
|
local start, ending, mid, state = 1, #t, 1, 0
|
||||||
local res,headers = API:GetMaps(game)
|
|
||||||
local pages = tonumber(headers['Pagination-Count'])
|
while start <= ending do
|
||||||
maps.count=maps.count+#res
|
mid = math.floor((start + ending) / 2)
|
||||||
for _,v in next,res do
|
if #value.DisplayName < #t[mid].DisplayName then
|
||||||
maps[v.ID]=v
|
ending, state = mid - 1, 0
|
||||||
|
else
|
||||||
|
start, state = mid + 1, 1
|
||||||
end
|
end
|
||||||
if pages>1 then
|
end
|
||||||
for i=2,pages do
|
|
||||||
res,headers = API:GetMaps(game,i)
|
table.insert(t, mid + state, value)
|
||||||
maps.count=maps.count+#res
|
end
|
||||||
for _,j in next,res do
|
|
||||||
maps[j.ID]=j
|
for _, game in next, API.GAMES do
|
||||||
|
if type(tonumber(game)) == 'number' then
|
||||||
|
local count = 0 -- add into the maps table afterwards
|
||||||
|
local maps = {}
|
||||||
|
local res, headers = API:GetMaps(game)
|
||||||
|
local pages = tonumber(headers['Pagination-Count'])
|
||||||
|
|
||||||
|
count = count + #res
|
||||||
|
|
||||||
|
for _, v in next, res do
|
||||||
|
insert(maps, v)
|
||||||
|
end
|
||||||
|
|
||||||
|
if pages > 1 then
|
||||||
|
for i = 2, pages do
|
||||||
|
res, headers = API:GetMaps(game, i)
|
||||||
|
count = count + #res
|
||||||
|
|
||||||
|
for _, j in next, res do
|
||||||
|
insert(maps, j)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
setmetatable(maps,{__index=function(self,i)
|
|
||||||
if i=='count' then return self.count end
|
setmetatable(maps, {__index = function(self, k)
|
||||||
if not tonumber(i) then
|
if k=='count' then return self.count end
|
||||||
for ix,v in next,self do
|
|
||||||
if type(v)=='table' and v.DisplayName:lower():find(i:lower()) then
|
-- Just to make sure it goes in the right order
|
||||||
return v
|
for i = 1, self.count do
|
||||||
end
|
local v = self[i]
|
||||||
end
|
|
||||||
elseif tonumber(i) then
|
if type(v) == 'table' and v.DisplayName:lower():find(k:lower()) then
|
||||||
for ix,v in next,self do
|
return v
|
||||||
if type(v)=='table' and v.ID==i then
|
|
||||||
return v
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end})
|
end})
|
||||||
API.MAPS[game]=maps
|
|
||||||
print('map init done for game:',API.GAMES[game],'count:',API.MAPS[game].count)
|
maps.count = count
|
||||||
|
API.MAPS[game] = maps
|
||||||
|
print('map init done for game:', API.GAMES[game], 'count:', API.MAPS[game].count)
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user