Module:LTEvent

--[[ LUA script to get Limited Time Event   Parameters:        1 = short name : Event / IP short name            for multiple set to "MULTIyyyy"            where yyyy (optional) is the year            will list all events for type for year            in order specified by sequence no in data        2 = type       : event type                    N = normal limited time event (default)                    T = Tower Challenge        3 = output     : output type                    N = Full Event Name (default)                    S = Short Name Only                    E = Event Name without year                    D = Event Name with start date                    C = Collection Name (=S if no Collection Name)                    A = Alternate Text (parameter 4)                    T = Text only Event Name without year        4 = alt text   : alternate text

Unknown Event is returned if Event is not in data. --]]

local p = {}

local lteData = mw.loadData( 'Module:LTEvent/data' )

Local Functions local function getArgs(frame) local tArgs

if frame == mw.getCurrentFrame then fParent = frame:getParent tArgs = fParent.args

if (fParent.args[1]) then tArgs = fParent.args else tArgs = frame.args end else tArgs = frame end return tArgs end

local function strDate(mon_day) local months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}

local mon = months[math.floor(mon_day/100)] local day = math.fmod(mon_day, 100) local idd = math.fmod(mon_day, 10) local nth = (idd==1 and day~=11 and "st ") or (idd==2 and day~=12 and "nd ") or (idd==3 and day~=13 and "rd ") or "th " return (day .. nth .. mon) end

local function singleEvent(sName, eType, outType, altText) local eventName = "Work In Progress" local collection = "Unknown Event" local eventYear = nil

local outText = eventName local dispText = "" local dateText = ""

if lteData[eType] and lteData[eType][sName] then eventName = lteData[eType][sName][2] eventYear = lteData[eType][sName][3] eventDate = lteData[eType][sName][4] collection = lteData[eType][sName][5] or lteData[eType][sName][2]

if eType == "T" then outText = "The Tower Challenge ("                       .. eventName                        .. ") Event" else outText = eventName .. " Event" end end

if outType:match("^[ACSED]$") then if outType == "A" then dispText = altText elseif outType == "C" then dispText = collection elseif outType == "S" then dispText = eventName elseif outType == "E" then dispText = eventName .. " Event" elseif outType == "D" then dispText = eventName .. " Event" dateText = " on " .. strDate(eventDate) .. " " .. eventYear end end

if outType ~= "T" then if eventYear then outText = outText .. " " .. eventYear end if dispText and dispText ~="" then outText = outText .. "|" .. dispText end

outText = "" .. outText .. ""

if dateText and dateText ~="" then outText = outText .. dateText end end

return outText end

local function multiEvent(eType, outType, year) local tIndex = {} local tOutput = {}

if lteData[eType] then if year and year ~= 0 then for k, v in pairs(lteData[eType]) do               if year == v[3] then table.insert(tIndex,v[1]) tOutput[v[1]] = v               end end else for k, v in pairs(lteData[eType]) do               table.insert(tIndex,v[1]) tOutput[v[1]] = v           end end end

table.sort(tIndex)

local outText = "" local sDot   = ""

for _, idx in ipairs(tIndex) do

if eType == "T" then outText = outText .. sDot .. "[[The Tower Challenge ("                       .. tOutput[idx][2]                        .. ") Event "                        .. tOutput[idx][3]        else            outText = outText .. sDot                         .. "[["                        .. tOutput[idx][2]                        .. " Event "                        .. tOutput[idx][3]        end

if outType == "S" then outText = outText .. "|" .. tOutput[idx][2] elseif outType == "C" then if tOutput[idx][5] then outText = outText .. "|" .. tOutput[idx][5] else outText = outText .. "|" .. tOutput[idx][2] end end outText = outText .. "]]"

sDot = " · " end return outText end

-- function get Limited Time Event function p.getLTE(frame)

local tArgs = getArgs(frame)

local sName   = tArgs[1] or "" local eType   = tArgs[2] local outType = tArgs[3] or "N" local altText = tArgs[4] or ""

sName = sName:lower:gsub("^%s*(.-)%s*$", "%1") or ''

if not eType or eType == "" then eType = "N" end

eType = eType:upper outType = outType:upper

local multi, year = sName:match("^(multi)(%d*)$")

if multi then return multiEvent(eType, outType, tonumber(year)) else return singleEvent(sName, eType, outType, altText) end end

-- function get previous, next navigation links function p.getNavi(frame) local tArgs = getArgs(frame)

return mw.title.getCurrentTitle.text

end

return p