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 = options : One or more Output Options Some Options are mutually exclusive D = Event Name with start date A = Display Alternate Text (parameter 4) I = Include Icon 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 Table 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, sOption, altText) local eventName  = "Unknown Event" local eventNumber = "" local eventDate  = nil local eventDays  = nil

local linkText = "Work In Progress" local outText = ""

sNumber = tonumber(sNumber)

if meData[sName] then eventName = meData[sName]["Name"] or "Data Error" imageNPC = meData[sName]["Icon"] or "" nameNPC  = meData[sName]["NPC"] or "" linkText = eventName .. " Mini Event"

if meData[sName][sNumber] then eventDate = meData[sName][sNumber][1] eventDays = meData[sName][sNumber][2] or 1 linkText = linkText .. "#"                       .. eventName .. " #"                       .. tostring(sNumber) end end

if string.match(sOption, "[ETL]") then -- Fixed Formats if string.match(sOption, "E") then -- Event Page Format

elseif string.match(sOption, "T") then -- Token Page Format

elseif string.match(sOption, "L") then -- Latest Info Main Page Format

end else -- Normal Mode outText = "[[" .. linkText

if sNumber and eventDate then outText = outText .. "|"           if string.match(sOption, "9") then outText = outText .. eventName if not string.match(sOption, "S") then outText = outText .. " Mini Event" end

outText = outText .. " #" .. tostring(sNumber)

if altText ~= "" then outText = outText .. altText end elseif string.match(sOption, "A") and altText ~= "" then outText = outText .. altText elseif string.match(sOption, "S") then outText = outText .. eventName end else if string.match(sOption, "A") and altText ~= "" then outText = outText .. "|" .. altText elseif string.match(sOption, "S") then outText = outText .. "|" .. eventName end end

outText = outText .. "]]"   end

--[===[   if outType:match("^[ADTN]$") 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

-- Event Table if outType == "T" then outText = eventName .. " Mini Event|" .. eventName outNPC = "" return "\n|-\n| align=\"center\" width=\"1\"|" .. outNPC .. "\n|"           .. outText ..             "\n|" .. aDate(eventDate) .. "-"           .. bDate(endDate) end

-- NPC Template if outType == "N" then outNPC = "" return "" .. nameNPC .. " (" .. outNPC .. ")" 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 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 sOption = tArgs[3] or "" local altText = tArgs[4] or ""

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

sOption = sOption:upper

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

return p

-- --