Module:LTEvent

--[[ Lua script to get Limited Time Event information

getLTE: get Limited Time Event based on input parameters 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 C = Cascading Creatures 3 = output    : output type N = Full Event Name (default) S = Short Name Only E = Event Name without year D = Event Name with start date R = Only Event start and end date C = Collection Name (=S if no Collection Name) A = Alternate Text (parameter 4) T = Text only Event Name without year P = Event Name with Event Period (start-end dates) K = Event Key (abbreviated Event Name) 4 = alt text  : alternate text

Unknown Event is returned if Event is not in data.

getNavi: get Previous and Next event from current Event Page Parameter: none

getLastLTE: get Last X Events (formatted for main page) Parameter: 1 = Count  : return Last Count Events (default 5) --]]

local p = {}

local date = require('Dev:Date') local util = require("Module:Utility")

-- Get Event Start Time from util module local dayStart = util.dayStart

---[==[ local lteData = mw.loadData( 'Module:LTEvent/data' ) --[===[]==] local lteData = { ["N"] = { ["nbc"]       = {2, "This Is Halloween", "2016/10/13",   	                    "Nightmare Before Christmas", 21, nil, "NBC"}, },   ["C"] = { ["nbc2"]      = {34, "Welcome Shock", "2020/10/23",   	                    "Nightmare Before Christmas", 9, 2, "NBC"}, },   ["T"] = { ["nbc"]       = {16, "Nightmare Before Christmas", "2018/10/18", nil, 15, 3}, } } --]===]

Local Functions

local function singleEvent(sName, eType, outType, altText) local eData = {0, "Unknown", "", "Unknown", 0, nil, "???"}

if eType == "N" then if lteData["N"] and lteData["N"][sName] then eData = lteData["N"][sName] elseif lteData["C"] and lteData["C"][sName] then eType = "C" eData = lteData["C"][sName] end else if lteData[eType] and lteData[eType][sName] then eData = lteData[eType][sName] end end

local tRetText = {}

if outType == "R" then table.insert(tRetText, util.strDate(eData[3], eData[5])) elseif outType == "K" then if eType == "T" then table.insert(tRetText, "TTC ") elseif eType == "C" then table.insert(tRetText, "CC ") end table.insert(tRetText, eData[7] or sName:upper) elseif outType == "U" then table.insert(tRetText, "'''") table.insert(tRetText, eData[2]) table.insert(tRetText, " Event") table.insert(tRetText, "''' is the ") table.insert(tRetText, util.wordinal(eData[1])) table.insert(tRetText, " major event of Disney Magic Kingdoms") if eData[6] then table.insert(tRetText, ", and the ") table.insert(tRetText, util.wordinal(eData[6])) if eType == "T" then table.insert(tRetText, " Tower Challenge") elseif eType == "C" then table.insert(tRetText, " Cascading Critters") end table.insert(tRetText, " event") end table.insert(tRetText, ". It") table.insert(tRetText, util.strDate(eData[3], eData[5], nil, nil, true)) table.insert(tRetText, ".") else tRetText = {"", "", eData[2], "", " Event", "", "", "", "", "",					"", "", "", "", "",					"",					}

if outType ~= "T" then tRetText[1] = ""			tRetText[6]  = " "			tRetText[7]  = string.sub(eData[3], 1, 4)			tRetText[14] = "" if outType ~= "N" then tRetText[8] = "|" end end

if eType == "T" then tRetText[2] = "The Tower Challenge ("			tRetText[4]  = ")" end

if outType == "S" then if eType == "T" then tRetText[9] = eData[2] tRetText[10] = "'s Tower Challenge" else tRetText[9] = eData[2] tRetText[10] = " Event" end elseif outType == "D" then if altText ~= "" then tRetText[9] = altText else tRetText[9] = eData[2] tRetText[13] = " Event" if eType == "T" then tRetText[10] = "'" if not eData[2]:match("s$") then tRetText[11] = "s" end tRetText[12] = " Tower Challenge" end end tRetText[15] = " on " tRetText[16] = util.strDate(eData[3], 0) elseif outType == "A" then tRetText[9] = (altText ~= "") and altText or eData[2] elseif outType == "E" then tRetText[9] = (eType == "T") and "The Tower Challenge" or eData[2] tRetText[10] = " Event" elseif outType == "C" then tRetText[9] = eData[4] or eData[2] elseif outType == "P" then tRetText[9] = eData[2] if eType == "T" then tRetText[10] = "'" if not eData[2]:match("s$") then tRetText[11] = "s" end tRetText[12] = " Tower Challenge" end tRetText[15] = " " tRetText[16] = util.strDate(eData[3], eData[5]) end end

return table.concat(tRetText) end

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

if lteData[eType] then for _, v in pairs(lteData[eType]) do	       if year == "" or year == string.sub(v[3],1,4) then table.insert(tIndex,v) end end end

table.sort(tIndex, function(a,b) return a[1] < b[1] end)

local outText = {} local sDot   = ""

for _, tData in ipairs(tIndex) do		local tItem = {sDot, "", "", tData[2], "",						" Event ", string.sub(tData[3],1,4),						"", "", "" }       if eType == "T" then tItem[3] = "The Tower Challenge ("       	tItem[5] = ")" end

if outType == "S" then tItem[8] = "|" tItem[9] = tData[2] elseif outType == "C" then tItem[8] = "|" tItem[9] = tData[4] elseif outType == "W" then tItem[4] = tData[4] or tData[2] tItem[6] = " Event Storyline " if eType == "T" then tItem[8] = "|" tItem[9] = tData[2] end end

table.insert(outText, table.concat(tItem))

sDot = " · " end return table.concat(outText) end

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

local tArgs = util.getArgs(frame)

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

sName = sName:lower:gsub("^%s*(.-)%s*$", "%1") or '' local tempName, tempType = sName:match("^(.+)%%([nNtTcC])$")

if tempName then sName = tempName eType = tempType end if eType == "" then eType = "N" end if outType == "" then outType = "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

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

--local curName = tArgs[1] or mw.title.getCurrentTitle.text local curName = mw.title.getCurrentTitle.text

local eType = "N" local eName = "" local eYear = ""

if curName:match("^The Tower Challenge %(.+%) Event %d%d%d%d$") then eName, eYear = curName:match("^The Tower Challenge %((.+)%) Event (%d+)$") eType = "T" elseif curName:match("^.+ Event %d%d%d%d$") then eName, eYear = curName:match("^(.+) Event (%d+)$") eType = "N" end

local curDate = ""

if eType == "N" then if lteData["N"] then for k, v in pairs(lteData["N"]) do	           if eYear == string.sub(v[3],1,4) and eName == v[2] then curDate = v[3] break end end end if curDate == "" then if lteData["C"] then for k, v in pairs(lteData["C"]) do		           if eYear == string.sub(v[3],1,4) and eName == v[2] then curDate = v[3] eType = "C" break end end end end else if lteData[eType] then for k, v in pairs(lteData[eType]) do	           if eYear == string.sub(v[3],1,4) and eName == v[2] then curDate = v[3] break end end end end

local prevDate = nil local prevEvent = "" local prevType = "" local nextDate = nil local nextEvent = "" local nextType = ""

if curDate ~= "" then for _, pnType in ipairs({"N", "C", "T"}) do	       for k, v in pairs(lteData[pnType]) do	            if v[3] < curDate and v[3] > (prevDate or "") then prevDate = v[3] prevEvent = v	               prevType = pnType end if v[3] > curDate and v[3] < (nextDate or "9") then nextDate = v[3] nextEvent = v	               nextType = pnType end end end end

local prevName = "Main Storyline Walkthrough" local nextName = ""

if prevDate then if prevType == "T" then prevName = "The Tower Challenge ("                       .. prevEvent[2]                        .. ") Event " .. string.sub(prevEvent[3],1,4) .. "|Tower Challenge ("                       .. prevEvent[2]                        .. ")" else prevName = prevEvent[2] .. " Event " .. string.sub(prevEvent[3],1,4) end end if nextDate then if nextType == "T" then nextName = "The Tower Challenge ("                       .. nextEvent[2]                        .. ") Event " .. string.sub(nextEvent[3],1,4) .. "|Tower Challenge ("                       .. nextEvent[2]                        .. ")" else nextName = nextEvent[2] .. " Event " .. string.sub(nextEvent[3],1,4) end nextName = "" .. nextName .. " »" end return "{| class=\"article-table\" style=\"width: 100%;\"" .. "\n| nowrap width=\"50%\"|« "           .. prevName            .. "\n| nowrap align=\"right\"|" .. nextName .. "\n|}" end

-- function get Last X events function p.getLastLTE(frame) local tArgs = util.getArgs(frame)

local count = tArgs[1] count = tonumber(count) or 5 local allEvents = {} local today = date:fmt("%Y/%m/%d %H:%M:%S")

for k, t in pairs(lteData) do       for _, v in pairs(t) do            if (today > (v[3] .. dayStart)) then table.insert(allEvents, {k, v[2], v[3]}) end end end

table.sort(allEvents, function(a,b) return a[3] > b[3] end)

local outText = ""

for i, v in ipairs(allEvents) do       local linkText  = "" local dateText = util.strDate(v[3], nil, nil, true)

if v[1] == "T" then linkText = "* "                       .. mw.text.truncate(v[2] .. "'s Tower Challenge", 43 - mw.ustring.len(dateText), nil, true)                        .. " " .. dateText .. " \n" else linkText = "* "                       .. mw.text.truncate(v[2], 43 - mw.ustring.len(dateText), nil, true)                        .. " " .. dateText .. " \n" end

outText = outText .. linkText if i >= count then break end end return outText end

return p

-- --