Module:Events

local p = {} local event = mw.loadData('Module:Events/data')

function range(a, b, step) if not b then b = a   a = 1 end step = step or 1 local f = step > 0 and function(_, lastvalue) local nextvalue = lastvalue + step if nextvalue <= b then return nextvalue end end or   step < 0 and function(_, lastvalue) local nextvalue = lastvalue + step if nextvalue >= b then return nextvalue end end or     function(_, lastvalue) return lastvalue end return f, nil, a - step end

function compareLess(x, y)   return x[1] < y[1] end function compareMore(x, y)   return x[1] > y[1] end function tableSort(table1,table2,more) for i,v in ipairs(table1) do       table1[i] = {table1[i], table2[i]} end if more == 'less' then table.sort(table1, compareLess) else table.sort(table1, compareMore) end for i, v in ipairs(table1) do       table1[i] = v[1] table2[i] = v[2] end return table2 end function eventSorted(datas, var) local key = {} local keydata = {} local more for name, data in pairs(datas) do       if var == nil then table.insert(key, eventDate(data)) else table.insert(key, data.lvl) more='less' end table.insert(keydata, name) end return tableSort(key,keydata,more) end function eventDate(data) if data.ends[1] ~= nil then return ((((data.ends[3]*100)+data.ends[2])*100)+data.ends[1]) else return 0 end end function active local currentDate = ((((os.date('*t').year*100)+os.date('*t').month)*100)+os.date('*t').day) for name, data in pairs(event) do       if eventDate(data)-currentDate > 0 then return name end end return nil end

p.range = range p.tableSort = tableSort p.eventSorted = eventSorted p.eventDate = eventDate p.active = missingImage

function missingImage(picture) local img = '' if picture == "" then img = 'Missing.jpg' else img = picture end return img end

function check(c) if c.link ~= nil then return "" elseif c.n == "crystal" then return "" elseif c.n == "fps" then return "" else return c.n   end end

function p.infobox(frame) local event_data = event[mw.title.getCurrentTitle.text] local start_date = os.date("%a, %d %b %Y",os.time{year=event_data.starts[3], month=event_data.starts[2], day=event_data.starts[1]}) local end_date = os.date("%a, %d %b %Y",os.time{year=event_data.ends[3], month=event_data.ends[2], day=event_data.ends[1]}) local data = { image=missingImage(event_data.pic), starts=start_date, ends=end_date }   return  table.concat({frame:expandTemplate { title = 'Event infobox', args = data },event_data.text,}, "\n") end

function p.event(frame) local name = mw.title.getCurrentTitle.text local data = { '==Rewards==', '{| class="wikitable mw-datatable" style="text-align: center;"', '|-',       '! Name', '! Quantity', '|-'   }    for n, q in pairs(event[name].rewards) do         table.insert(data, '|'..check(q)) table.insert(data, '|'..q.q)       table.insert(data, '|-') end table.insert(data, '|}') return table.concat(data, "\n") end

function p.events(frame) local typ = frame.args[1] local data = {' '} local sorted = eventSorted(event) local active = active local c = 0 if active ~= nil then table.insert(data, '==Current Event==') table.insert(data, '') end for name, dat in pairs(sorted) do       event_data=event[dat] if dat ~= active then if c == 0 then table.insert(data, '==Past Event==') end c = c + 1 if c < 9 or typ~='mainPage' then table.insert(data, '') end end end table.insert(data,' ') for i, dat in pairs(data) do mw.log(dat) end return table.concat(data,"\n") end return p