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 availableData = { ["Items"] = { ["Yesss$Niceland$Tiana (Comfy)"] = {"2021/08/15", 5, nil, " 18:00:00 UTC"}, ["Destiny$Bailey"] = {"2021/06/03", 15, true, " 18:00:00 UTC"}, },	["Chests"] = { ["Frozen"] = {"2021/08/05", 15}, ["Hercules"] = {"2021/07/15", 16}, ["Magical Chests"] = {"2021/07/16", 15}, ["Sapphire Chests"] = {"2021/08/05", 15}, } } --]===]

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 sName, data in pairs(availableData) do	if sName == "Items" then for k, v in pairs(data) do			if v[3] and v[1] and today >= v[1] then table.insert(tIndex, {k, v[1]}) end end end end

table.sort(tIndex, function(a,b) return a[2] > b[2] end) local outText = ""

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"

local space = ""

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

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

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

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

local headerlast = '{| class="article-table" width="100%"\n! style="font-weight: normal;"|\n' local headerupcoming = '{| class="article-table" width="100%" style="border: 3px solid #F94444;"\n! style="font-weight: normal;"|\n' local foot1 = ' For '

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

local outText = "==Upcoming Events ==\n" .. headerupcoming .. upcomingME({"5"}) .. foot1 .. "a complete timeline of the events in Disney Magic Kingdoms, click [[Event Timeline"                   .. foot2

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

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

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

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

outText = outText .. "==Latest Characters==\n" .. headerlast .. lastCharacter(5) .. foot1 .. "more 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

local function countdown(enddate, text1, text2) return "" .. text1 .. "" .. enddate .. " "       	.. text2 .. " " end

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

local more = "" local tItem = {}

for sName, data in pairs(availableData) do   	if sName == "Items" then for k, v in pairs(data) do		      	for cName in mw.text.gsplit(k, "%s*%$%s*") do    			       	table.insert(tItem, {cName, v[1], v[2], (v[4] or util.dayStart)}) end end else for k, v in pairs(data) do			if k:match("^.+ Chests$") then local item = CHEST.getDATA({k}) for cName in mw.text.gsplit(item, "%s*%$%s*") do   			       	       	table.insert(tItem, {cName, v[1], v[2], (v[4] or util.dayStart)}) end else local item = CHEST.getDATA({"Legendary Chests", k}) for cName in mw.text.gsplit(item, "%s*%$%s*") do   			       	       	table.insert(tItem, {cName, v[1], v[2], (v[4] or util.dayStart)}) end end end end end

for _, values in pairs(tItem) do local UnlockDate = values[2] .. util.dayStart local LockDate = date(values[2]):adddays(values[3]):fmt("%Y/%m/%d") .. values[4] if tArgs[1] == values[1] and today <= UnlockDate then return "" .. countdown(UnlockDate,			" ''(Available in ", ")''"		)	elseif tArgs[1] == values[1] and values[3] == 0 then return "" elseif tArgs[1] == values[1] and today <= LockDate then return "" .. countdown(LockDate,			" ''(Available for ", ")''"		)	elseif tArgs[1] == values[1] then return "" end end

if tArgs["C"] then if cData["Items"][tArgs[1]] and cData["Items"][tArgs[1]][4] and cData["Items"][tArgs[1]][4] == true then return "" else return "" end else return "" end end

return p