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 = { ["Shop"] = { ["Yesss$Niceland$Tiana (Comfy)"] = {"2021/08/15", 5, " 18:00:00 UTC"}, ["Destiny$Bailey"] = {"2021/06/03", 15, " 18:00:00 UTC", true}, },	["Chests"] = { ["Legendary Chests"] = { ["Mulan"] = {"2022/01/28", 5, " 19:00:00 UTC"}, },		["Bronze Chests"] = { ["Current"] = {"2021/01/01", 0}, },		["Mulan TC 2 Event"] = { ["Mulan TC 2 Event"] = {"2022/01/27", 5}, },	} } --]===]

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

for k, v in pairs(availableData["Season"]) do	if v[4] and v[1] and today >= v[1] then table.insert(tIndex, {k, v[1]}) 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, 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["Shop"]) do		if data["O"] and data["O"]:match("^Attraction Sales") then 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 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 == "Shop" 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[3] or util.dayStart), (v["O"] or "Shop"), v["B"]}) end end elseif sName == "Season" 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[3] or util.dayStart), (v["O"] or ":Category:Seasons|Season")}) end end else 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 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 a[2] < b[2] 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 not values[6] then onlybundle = nil end if tArgs[1] == values[1] and today <= UnlockDate then tOut = tOut .. space .. "" .. values[5] .. ": " .. countdown(UnlockDate,				" ''(Available in ", " (Available on ",				")" )			space = " "		elseif tArgs[1] == values[1] and values[3] == 0 then			tOut = tOut .. space .. "" .. values[5] .. ": "			space = " "		elseif tArgs[1] == values[1] and today <= LockDate then			tOut = tOut .. space .. "" .. values[5] .. ": " .. 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: " end

if tOut ~= "" then return tOut else return "" 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 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 a[2] < b[2] 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 today <= UnlockDate then tOut = tOut .. " " .. (values[6] or values[5] or values[1]) .. ": " .. countdown(UnlockDate,			" ''(Available in ", " (Available on ",			")" )	elseif values[3] == 0 then		tOut = tOut .. ""		space = " "	elseif today <= LockDate then		tOut = tOut .. " " .. (values[6] or values[5] or values[1]) .. ": " .. countdown(LockDate, " (Available for ",			" (Available until ", ")''"		)	end end

if tOut == "" then return "" else return tOut end end

return p