Module:MiniEvent

--[[ LUA script to get Limited Time Mini Event information

getME: get Limited Time Mini Event based on input parameters Parameters: 1 = name    : Mini Event name 2 = number  : Event Number 3 = output  : Output Type D = Event Name with start date A = Alternate Text (parameter 4) 4 = alt text : Alternate Text

Unknown Event is returned if Event is not in data.

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

local p = {}

local meData = mw.loadData( 'Module:MiniEvent/data' ) --local date = require('Dev:Date')

-- 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

-- Date local function strDate(numDate, ordinal) local months = {"January ", "February ", "March ", "April ", "May ", "June ", "July ", "August ", "September ", "October ", "November ", "December "} local day = math.min(math.fmod(numDate, 100), 31) local idd = math.fmod(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 " local year = math.floor(numDate / 100) local mon = math.min(math.fmod(year, 100), 12) year = math.floor(year/100) return (day .. nth .. months[mon] .. year) end

-- Event Tabble Date local function aDate(numDate, ordinal) local day = math.min(math.fmod(numDate, 100), 31) local idd = math.fmod(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) end

local function bDate(numDate, ordinal) local months = {"January ", "February ", "March ", "April ", "May ", "June ", "July ", "August ", "September ", "October ", "November ", "December "} local day = math.min(math.fmod(numDate, 100), 31) local idd = math.fmod(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 " local year = math.floor(numDate / 100) local mon = math.min(math.fmod(year, 100), 12) year = math.floor(year/100) return (day .. nth .. months[mon]) end

-- function get single event local function singleEvent(sName, sNumber, outType, altText) local eventName  = "Work In Progress" local eventNumber = "Unknown Event" local eventDate  = nil local endDate  = nil

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

if meData[sName] and meData[sName][sNumber] then eventName  = meData[sName][sNumber][1] eventNumber = meData[sName][sNumber][2] eventDate  = meData[sName][sNumber][3] endDate    = meData[sName][sNumber][4] eventNPC   = meData[sName][sNumber][5] outText = eventName .. " Mini Event" end

if outType:match("^[ADT]$") then if outType == "A" then dispText = altText elseif outType == "D" then if altText ~= "" then dispText = altText else dispText = eventName .. " #" .. eventNumber end dateText = " Mini Event on the " .. strDate(eventDate) end end if outType == "T" then dispText = "\n|-\n| align=\"center\" width=\"1\"|\n|"           .. outText ..             "\n|" .. aDate(eventDate) .. "-"           .. bDate(endDate) end if outType == "D" then outText = outText .. "#" .. eventName .. " #" .. eventNumber .. "|" .. eventName .. " #" .. eventNumber elseif outType == "T" then outText = outText .. "#" .. eventName .. " #" .. eventNumber .. "|" .. eventName elseif outType == "A" then outText = outText .. "#" .. eventName .. " #" .. eventNumber .. "|" .. altText else outText = outText .. "#" .. eventName .. " #" .. eventNumber .. "|" .. eventName .. " Mini Event" end outText = "" .. outText .. ""

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

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

local tArgs = getArgs(frame)

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

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

if not sNumber or sNumber == "" then outText = "" .. eventName .. " Mini Event" end

sNumber = sNumber:upper outType = outType:upper

return singleEvent(sName, sNumber, outType, altText) end

return p

-- --