Module:Available

-- -- Lua script to display Latest Items Info on Main Page and Availability on Character/Attraction Page -- --

local p = {}

local availableData = mw.loadData( 'Module:Available/data' ) local lastLTE = require ("Module:LTEvent").getLastLTE local lastUpdate = require("Module:UpdateNumber").getLastVer local lastME = require("Module:MiniEvent").getLastME local upcomingME = require("Module:MiniEvent").getUpcomingME local util = require('Module:Utility') local date = require("Dev:Date")

local function strDate(sDate) local theDate = date(sDate)

return string.gsub(theDate:fmt("%d"), "^0", "") .. theDate:fmt(" %B %Y") end

local function lastCharacter(count) local limit = count local tIndex = {} if not limit or limit == 0 then limit = 3 end

local today = os.date("%Y/%m/%d") for idx, data in ipairs(availableData) do       if not data[5] and data[3] and today >= data[3] then table.insert(tIndex, data) end end

table.sort(tIndex, function(a,b) return a[3] > b[3] end) local outText = "" --   for i, ver in ipairs(tIndex) do --        outText = outText .. singleEvent(ver[2], ver[3], "L", "") --       if i >= count then break end --   end

local retText = "" for i, v in ipairs(tIndex) do       local today = os.date("%Y/%m/%d")

local linkText = v[1] and "" or "Work In Progress"

if v[2] then linkText = ""                       .. (v[1] or "")                        .. "" else local space = ""

for cName in mw.text.gsplit(v[1], "%s*%$%s*") do               linkText = linkText .. space .. "" .. cName .. "" space = ", " end end

retText = retText .. "* "               .. linkText .. " "               .. strDate(v[3]) .. " \n"

if i>= limit then break end end return retText end

function p.latest(frame) local tArgs = util.getArgs(frame)

local headerlast = '{|width="100%"\n' .. '|- valign="top" cellpadding="0px"' .. ' cellspacing="0px"\n' .. '|style="width:50%; padding: .0em;'                   .. ' border: 1px solid #cbcbcb;'                    .. ' color: #000;'                    .. ' background-color: #e5e5ea;"|\n' local headerupcoming = '{|width="100%"\n' .. '|- valign="top" cellpadding="0px"' .. ' cellspacing="0px"\n' .. '|style="width:50%; padding: .0em;'                   .. ' border: 3px solid #F94444;'                    .. ' color: #000;'                    .. ' background-color: #e5e5ea;"|\n' local foot1 = '' .. ' For more '

local foot2 = '|here]] \n|}\n'

local outText = "==Upcoming Events ==\n" .. headerupcoming .. upcomingME({"5"}) .. "\n|}\n"

outText = outText .. '{| class="" style="background-color:transparent;'                   .. ' color:inherit; width:100%;"\n' .. '|-\n' .. '| valign="top" style="width:50%;" |\n\n' outText = outText .. "==Latest Major Events==\n" .. headerlast .. lastLTE({"5"}) .. foot1 .. "events, click [[:Category:Events"                   .. foot2

outText = outText .. "==Latest Mini Events==\n" .. headerlast .. lastME({"5"}) .. foot1 .. "events, click [[:Category:Mini Events"                   .. foot2

outText = outText .. '\n| valign="top" style="width:50%;" |\n\n'

outText = outText .. "==Latest Updates==\n" .. headerlast .. lastUpdate({"5"}) .. foot1 .. "updates, click [[Content Updates"                   .. foot2

outText = outText .. "==Latest Characters==\n" .. headerlast .. lastCharacter(5) .. foot1 .. "characters, click [[:Category:Character Collections"                   .. foot2

outText = outText .. "|}\n"

return outText end

local function dispTime(t) local d = math.floor(t / 86400) local h = math.floor((t % 86400) / 3600) local m = math.floor((t % 3600) / 60) if d == 0 and h == 0 then return string.format("%dm", m)	elseif d == 0 then return string.format("%dh %02d", h, m)	else return string.format("%dd %dh %02d", d, h, m)	end end

function p.availability(frame) local tArgs = util.getArgs(frame) if not tArgs[1] then tArgs[1] = mw.title.getCurrentTitle.text end local today = os.date("%Y/%m/%d %H:%M:%S")

for idx, data in ipairs(availableData) do   	if data[2] == nil then for cName in mw.text.gsplit(data[1], "%s*%$%s*") do local UnlockDate = data[3] .. util.dayStart local LockDate = data[4] .. util.dayStart if tArgs[1] == cName and today <= UnlockDate then return frame:preprocess("No"								  			..' '								        	.. " ''(Available in " .. ' '							       		.. UnlockDate .. " )'' ")				elseif tArgs[1] == cName and today <= LockDate then return frame:preprocess(""								  			..' '								        	.. " ''(Available for " .. ' '							       		.. UnlockDate .. " )'' ")				elseif tArgs[1] == cName then return frame:preprocess("No") end end end end return frame:preprocess("") end

return p