Module:Available

--[=[ -- LUA script to get Items Availability Info -- --]=]

local p = {}

---[==[ local availableData = mw.loadData( 'Module:Available/data' ) --[===[]==] local availableData = { ["Hocus Pocus Event 2022"] = { ["Winifred Sanderson"] = {"2022/10/29", 6, " 18:00:00 UTC", true, A="Event Shop"}, },	["Striking Gold Mini Event"] = {true, ["Hocus Pocus Gold Trophy"] = {"2022/11/01", 3, A="Striking Gold #125", R="L1"}, },	["Chests"] = { ["Legendary Chests"] = { ["The Incredibles"] = {"2022/08/18", 15, " 18:00:00 UTC"}, },		["Red Ribbon Chests"] = { ["Christmas 2022"] = {"2022/12/25", 1, nil, true}, },	} } --]===]

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 ~= "Legendary" then for k, v in pairs(data) do				if type(v) == "table" and v[4] 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 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 headerlast = '{| class="article-table" width="100%"\n! style="font-weight: normal;"|\n' local headerupcoming = '{| class="article-table" width="100%" style="border: 3px solid yellowgreen;"\n! style="font-weight: normal;"|\n' local foot1 = ' For '

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

local outText = '==Upcoming Mini 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 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:Characters"                   .. 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.availabilitySale(frame) local tArgs = util.getArgs(frame) local today = os.date("%Y/%m/%d %H:%M:%S") if not tArgs["P"] then tArgs["P"] = mw.title.getCurrentTitle.text end local LockDate = ""

for k, data in pairs(availableData["Sales"]) do LockDate = date(data[1]):adddays(data[2]):fmt("%Y/%m/%d") .. (data[3] or util.dayStart) if today <= LockDate then for cName in mw.text.gsplit(k, "%s*%$%s*") do				if tArgs["P"] == cName then if tArgs[1] == "I" then local ecNumb = tonumber((string.gsub(tArgs[2] or "1", "[,]", ""))) local sNumb = tonumber((string.gsub(tArgs[3] or "1", "[,]", ""))) sNumb = string.format("%.2f", (sNumb/ecNumb)) return tArgs[3] .. "  " .. tArgs[2] .. " (" .. math.ceil(100-(sNumb*100)) .. "%) " else return tArgs[3] end break end end end end

return tArgs[2] or "" end

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

local tOut = "" local space = "" local onlybundle = true local tItem = CHEST(tArgs[1])

for sName, data in pairs(availableData) do		if sName ~= "Legendary" then for k, v in pairs(data) do				if type(v) == "table" then for cName in mw.text.gsplit(k, "%s*%$%s*") do						if tArgs[1] == cName then table.insert(tItem, {cName, v[1], v[2], (v[3] or util.dayStart), (v["L"] 		or sName), (v["A"] or ""), (v["D"] or v["A"] or v["L"] or sName), (sName=="Sales" and true or nil)}) end end end end end end

for sName, data in pairs(bData) do		for k, tab in pairs(data) do			for _, cName in pairs(tab["C"]) do				if tArgs[1] == cName then table.insert(tItem, {cName, tab["D"][1], tab["D"][2], (tab["D"][3] or util.dayStart), "Bundles List", k, k, true}) end end end end

for sName, data in pairs(meData) do		if sName:match("^ttc ") then for k, tab in pairs(data) do				if tab["C"] then for _, cName in pairs(mw.text.split(tab["C"], "%s*%$%s*")) do						if tArgs[1] == cName then table.insert(tItem, {cName, tab[1], tab[2], util.dayStart, data["Name"], "Characters Required", "Challenging the Tower"}) end end end end end end

table.sort(tItem, function(a,b) return (date(a[2]):adddays(a[3]):fmt("%Y/%m/%d")) < (date(b[2]):adddays(b[3]):fmt("%Y/%m/%d")) end)

for _, v in pairs(tItem) do		local hFile = "Home-limited_time" if v[5]:match(" Chests") then hFile = "Ec-" .. v[5]:gsub(" ", "_"):gsub("_Chests", ""):lower elseif v[7] == "Challenging the Tower" then hFile = "update-20-event_challenge" elseif v[5] == "Bundles List" then hFile = "Home-shop" elseif v[5]:match(" Mini Event$") then hFile = v[5]:match("^(.+) Mini Event$"):lower hFile = meData[hFile]["NPC"] hFile = "Npc-" .. hFile:gsub(" ", "_"):lower elseif v[5]:match("^The Tower Challenge %(.+%) Event %d%d%d%d") then hFile = "update-20-event_shop" elseif v[5]:match("^Season ") then hFile = "season_pass" elseif v[5]:match(" Calendar$") then hFile = "home-calendar" if v[6] == "" then v[6] = v[2] end elseif v[5] == "Discovery Rewards" then hFile = "discovery" elseif v[5]:match(" Sales$") then hFile = "home-sale" end hFile = " "

local Header = hFile .. "" .. v[7] .. ":  " local UnlockDate = v[2] .. util.dayStart local LockDate = date(v[2]):adddays(v[3]):fmt("%Y/%m/%d") .. v[4]

if not v[6] then onlybundle = nil end if v[5] == "Shop" then onlybundle = nil end if today <= UnlockDate then tOut = tOut .. space .. Header .. ": " .. util.countdown(UnlockDate, " in ", " on ") space = " " elseif v[3] == 0 then tOut = tOut .. space .. Header .. ": Currently Available " space = " " elseif today <= LockDate then tOut = tOut .. space .. Header .. ": " .. util.countdown(LockDate, " for ", " until ") space = " " end end

if tArgs[2] and cData["Items"][tArgs[1]] and not cData["Items"][tArgs[1]][4] and onlybundle == true then tOut = tOut .. space .. "Shop:  : Currently Available" end

if tOut ~= "" then return tOut else return "Shop:  : Not Currently Available" end end

return p