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 ~= "Chests" 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

local function countdown(enddate, text1, text2, text3) return "" .. text1 .. "" .. enddate .. " "       	.. text3 .. "  " .. text2 .. date(enddate):fmt("%A, %B %d") .. text3 .. " " 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 end end end break end

return tArgs[2] or "" end

function p.unavailability(UnlockDate, DispText) local today = os.date("%Y/%m/%d %H:%M:%S") local date = require('Dev:Date') local tOut = DispText or ""

if UnlockDate and UnlockDate:match("^%d%d%d%d%/%d%d%/%d%d$") and today <= (UnlockDate .. util.dayStart) then tOut = " " .. countdown(UnlockDate .. util.dayStart,				" ''(Available in ", " (Available on ",				")" )	end

return tOut 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 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 tOut = "" local space = "" local onlybundle = true local tItem = {}

for sName, data in pairs(availableData) do		if sName == "Chests" then for k, tab in pairs(data) do				for n, v in pairs(tab) do				      	local item = CHEST.getDATA({k, n}) for cName in mw.text.gsplit(item, "%s*%$%s*") do   		       	       	       		table.insert(tItem, {cName, v[1], v[2], (v[3] or util.dayStart), k, n, k}) end end end else for k, v in pairs(data) do				if type(v) == "table" then for cName in mw.text.gsplit(k, "%s*%$%s*") do						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

for sName, data in pairs(bData) do		for k, tab in pairs(data) do			for _, cName in pairs(tab["C"]) do				table.insert(tItem, {cName, tab["D"][1], tab["D"][2], (tab["D"][3] or util.dayStart), "Bundles List", k, k, true}) 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 _, values in pairs(tItem) do local Header = "" .. values[7] .. ": " 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 not values[6] then onlybundle = nil end if tArgs[1] == values[1] and values[5] == "Shop" then onlybundle = nil end if tArgs[1] == values[1] and today <= UnlockDate then tOut = tOut .. space .. Header .. "" .. countdown(UnlockDate,				" ''(Available in ", " (Available on ",				")" )			space = " "		elseif tArgs[1] == values[1] and values[3] == 0 then			tOut = tOut .. space .. Header .. " (Currently Available) "			space = " "		elseif tArgs[1] == values[1] and today <= LockDate then			tOut = tOut .. space .. Header .. "" .. countdown(LockDate, " (Available for ",				" (Available until ", ")''"			)			space = " " end end

if tArgs["C"] 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

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

local today = os.date("%Y/%m/%d %H:%M:%S") local pagename = tArgs[1] or mw.title.getCurrentTitle.text

local tOut = "" local space = "" local tItem = {}

for k, tab in pairs(availableData["Chests"]) do		if pagename == k then for n, v in pairs(tab) do 				table.insert(tItem, {n, v[1], v[2], (v[3] or util.dayStart)}) end elseif pagename == "All" then for n, v in pairs(tab) do				if k == "Legendary Chests" then table.insert(tItem, {n, v[1], v[2], (v[3] or util.dayStart), k, (n .. " Chests")}) elseif v[2] ~= 0 then table.insert(tItem, {n, v[1], v[2], (v[3] or util.dayStart), k}) 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 _, values in pairs(tItem) do local Header = "" .. (values[6] or values[5] or values[1]) .. ": " local UnlockDate = values[2] .. util.dayStart local LockDate = date(values[2]):adddays(values[3]):fmt("%Y/%m/%d") .. values[4]

if today <= UnlockDate then tOut = tOut .. space .. Header .. "" .. countdown(UnlockDate,				" ''(Available in ", " (Available on ",				")" )			space = " "		elseif values[3] == 0 then			tOut = tOut .. space .. Header .. " (Currently Available)"			space = " "		elseif today <= LockDate then			tOut = tOut .. space .. Header .. "" .. countdown(LockDate, " (Available for ",				" (Available until ", ")''"			)			space = " " end end

if tOut ~= "" then return tOut else return "" .. pagename .. ": (Not Currently Available)" end end

return p