Module:LTEvent

--[[ LUA script to get Limited Time Event   Parameters:        1 = short name : Event / IP short name        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                    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 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 singleEvent(sName, eType, outType, altText) local eventName = "Work In Progress" local collection = "Unknown Event" local year      = nil

local outText = eventName local dispText = ""

if lteData[eType] and lteData[eType][sName] then eventName = lteData[eType][sName][2] year      = lteData[eType][sName][3] collection = lteData[eType][sName][4] or eventName

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

if outType:match("^[ACS]$") then if outType == "A" then dispText = altText elseif outType == "C" then dispText = collection elseif outType == "S" then dispText = eventName end end if outType ~= "T" then if year then outText = outText .. " " .. year end if dispText and dispText ~="" then outText = outText .. "|" .. dispText end outText = "" .. outText .. "" end

return outText end

local function multiEvent(eType, outType, year) return "Multiple Events" end

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, year) else return singleEvent(sName, eType, outType, altText) end end

return p