Module:Events

local f = require('Module:Functions') local p = {} p.data = mw.loadData('Module:Events/data') p.types = mw.loadData("Module:Events/type") p.config = { currentEventPictureSizeX = 350, currentEventPictureSizeY = 200, eventTextOverflow = 'overflow: hidden;'.. 'display: -webkit-box;'.. '-webkit-line-clamp: 3;'.. '-webkit-box-orient: vertical;', eventList = 'display: flex;'.. 'flex-wrap: wrap;'.. 'justify-content: space-evenly;' }

local function checkTime(stop) local a = f.split(stop,"-") stop = os.time{hour = a[4], day = a[3], month = a[2], year = a[1]} return (os.time < stop) end

local function formatTime(t) local a = f.split(t,"-") return os.date('%A, %d. %B %Y at %H:%M UTC', os.time({year=a[1], month=a[2], day=a[3], hour=a[4], minute=0})) end

local function getAllEventsType(data) local a = "" local c = 0 for i, j in pairs(data) do 		if(c>0) then a=a..", " end a = a....j.. c = c+1 end return a end

local function requirementType(t) if(t.type ~= nil and t.type == 1) then return t.a 	else return '' end end

local function getRewards(requirements,quests) local data = "" for i, j in pairs(quests) do data = data..' '..j.name..''.. ' Requirements: '..j.requirement.." "..requirementType(requirements[j.reqType]).. ' Rewards:' for a, b in pairs(j.reward) do 			data = data..' '..b.name if(b.quantity ~= nil) then 	data = data.." x"..b.quantity end end data = data..' ' end return data end

local function eventDetails(j, hidden) local data = {} local h = "" if(hidden ~= nil and hidden == true) then h = " dn" end table.insert(data,' ') table.insert(data, ' ') table.insert(data,' '..		' '..j.name..' '..		' Event type: '..getAllEventsType(j.eventType)..		' Start date: '..formatTime(j.startDate)..		' End date: '..formatTime(j.endDate)) table.insert(data,''..j.description..' ') table.insert(data,' ') table.insert(data,' Quests ') table.insert(data,' ') table.insert(data, getRewards(j.requirements,j.quests)) table.insert(data,' ') table.insert(data,' ') table.insert(data, ' ') table.insert(data, ' ') return table.concat(data,"\n") end

function p.currentEvent(frame) local args = frame.args["fullDesc"] local data = {' '} local active = 0 local style = ' style="padding-right:10px;"' for i, j in pairs(p.data) do		if(checkTime(j.endDate)) then table.insert(data, ' ') table.insert(data,' '..j.endDate..' ') if(args ~= nil) then table.insert(data,eventDetails(j)) else table.insert(data,eventDetails(j,true)) end table.insert(data, ' ') active = active+1 end end table.insert(data, ' ') if(active == 0) then table.insert(data,'There is no active event right now') end return table.concat(data,"\n") end

function p.eventList local data = {' '} local past = {} for i, j in pairs(p.data) do		if(checkTime(j.endDate)) then table.insert(data,eventDetails(j)) else table.insert(past,eventDetails(j,true)) end end table.insert(data, ' ') table.insert(data,'==Past Events==') table.insert(data,' ') table.insert(data,table.concat(past,"/n")) table.insert(data, ' ')

return table.concat(data,"\n") end

function p.eventTypes local data = "Events" for i,j in pairs(p.types) do data = data.." · " data = data.. ..i.. end return data end

function p.eventTypesPage(frame) local data ={"__NOTITLE__", frame:expandTemplate { title = 'Navigation Events'} }	local name = f.split(mw.title.getCurrentTitle.text,"/") table.insert(data, p.types[name[2]].description)

return table.concat(data,"\n") end

return p