Module:Bundle

--[=[ -- LUA script to get Bundles -- --]=]

local p = {}

---[=[ For testing remove 1 '-' from start of line local bundleData = mw.loadData('Module:Bundle/data') --[==[]=] local bundleData = { ["rh"] = { ["Parade"] = {4, ["D"] = {"2022/03/13", 18, " 19:00:00 UTC"}, ["C"] = {"Robin Hood Float", "IP-RH #5", "Maid Marian,2 #5", "Maid Marian,3 #5"}, ["H"] = "Sir Hiss$Maid Marian$Prince John", },	}, } --]==] local cData = mw.loadData( 'Module:ItemCollection/data' )

local util = require('Module:Utility') local EC = require("Module:EC").getEC local TOK = require("Module:CharacterToken").getToken local CHEST = require("Module:EnchantedChest").getChest local AVATAR = require("Module:CharacterAvatar").getAvatar local date = require("Dev:Date") local today = os.date("%Y/%m/%d %H:%M:%S")

local function oneItem(item, type) if not item then return "" end local tt = mw.text.split(item, "%s*#%s*") local iName = tt[1] or item local nCount = tt[2] or 0

local size = 0

if type == 5 then size = 30 elseif type == 4 then size = 40 elseif type == "C" then size = 50 elseif type == 2 or type == 3 then size = 60 elseif type == 1 then size = 80 end

local conv = { ["ch"] = "cp", ["cos"] = "cp", }

local iData = cData["Items"][iName]

if item:match("Chests") then if type == "N" then tItem = CHEST({iName, "L", (nCount ~= "1")}) else tItem = CHEST({iName, size}) if nCount ~= 0 then tItem = tItem .. " '''x" .. nCount .. "'''" end end elseif iData and iData[2] then if type == 4 then size = 50 elseif type == "C" then size = 65 elseif type == 3 or type == 2 or type == 1 then size = "" end local iDisp = iName:gsub("^([^%(]-)%/([^%(]-)$", "%2") if type == "N" then tItem = "" .. (iDisp or iName) .. "" else local fname = iName:lower:gsub("[':%,%.]", ""):gsub(" ", "_") if iData[2] == "pf" then fname = fname:gsub("_float$", "") else fname = fname:gsub("^([^%(]-)%/([^%(]-)$", "%1-%2") end tItem = "" if nCount ~= 0 then tItem = tItem .. " '''x" .. nCount .. "'''" end end elseif item:match("^EC") then if type == 3 then size = 50 end if type == "N" then tItem = EC({iName, "L", S=(nCount == "1")}) else tItem = EC({iName, nil, nil, "I", size}) if nCount ~= 0 then tItem = tItem .. " '''x" .. nCount .. "'''" end end else if type == "N" then tItem = TOK({iName, "L"}) if nCount ~= "1" then tItem = tItem .. "s" end else tItem = TOK({iName, size}) if nCount ~= 0 then tItem = tItem .. " '''x" .. nCount .. "'''" end end end

return tItem end

local function tableBundle(tNumb, cData) local tOut = {' ' end

local function tableItems(bType, bName, bNumb, bDuration, bContent, bHelp) local tOut = {}

table.insert(tOut, '{| class="card ')	if not bType or bType == "zz" then bType = "default" end	table.insert(tOut, bType)	table.insert(tOut, '" style="text-align: center; line-height: normal; border-spacing: 0px; color: white; text-shadow: 1px 2px 3px #030d9d; display: inline-table;"\n| style="width: 230px !important; height: 40px; background-size: cover; background-position: top;"|') table.insert(tOut, "''")

if type(bDuration) == "table" then if (((bDuration[1] .. util.dayStart) < today) and bDuration[2] == 0) then table.insert(tOut, "Permanent Content") else table.insert(tOut, "Available for " .. date(bDuration[1]):adddays(bDuration[2]):fmt("%Y/%m/%d") .. (bDuration[3] or util.dayStart) .. "  Available until " .. date(date(bDuration[1]):adddays(bDuration[2]):fmt("%Y/%m/%d") .. (bDuration[3] or util.dayStart)):fmt("%A, %B %d") .. " ") end else table.insert(tOut, bDuration) end

table.insert(tOut, "''") table.insert(tOut, '\n|-\n| style="width: 230px !important; height: 220px; background-size: cover; background-position: 0 -40px;"|') table.insert(tOut, tableBundle(bNumb, bContent)) table.insert(tOut, '\n|-\n| style="width: 230px !important; height: 78px; background-size: cover; background-position: 0 -260px; vertical-align: baseline; padding: 0 10px;"|') table.insert(tOut, " '''") table.insert(tOut, bName) table.insert(tOut, "''' \n|}\n")

table.insert(tOut, '{| class="bundle-content" id="')	table.insert(tOut, bName)	table.insert(tOut, '"\n! colspan="6"| Contents  \n|-')

local len = #bContent for i = len - 1, 1, -1 do		bContent[len] = table.remove(bContent, i)	end

for _, v in ipairs(bContent) do		table.insert(tOut, '\n|') table.insert(tOut, oneItem(v, "C")) end

if bHelp then table.insert(tOut, '\n| rowspan="2" style="vertical-align: top; border: 4px solid #f5b90c; border-radius: 10px; width: 0%; padding: 0;"| ') space = "" for hChar in mw.text.gsplit(bHelp, "%s*$%s*") do			table.insert(tOut, space) table.insert(tOut, AVATAR({hChar, "50"})) table.insert(tOut, ' ')			hChar = hChar:gsub("^([^,]-)%s*/%s*(.-)$", "%2")			table.insert(tOut, hChar)			table.insert(tOut, ' ') space = " " end end

table.insert(tOut, '\n|-')

for _, v in ipairs(bContent) do		table.insert(tOut, '\n| ') table.insert(tOut, oneItem(v, "N")) table.insert(tOut, ' ') end table.insert(tOut, '\n|}\n \n')

return table.concat(tOut) end

function p.getBundle(frame) local tArgs = util.getArgs(frame) local bContent = {} local bHelp = nil if not tArgs[2] then return "" end

local tt = mw.text.split(tArgs[2], "%s*$%s*")

tt[1] = tonumber(tt[1]) if tt[1] and tt[1] == 1 then table.insert(bContent, (tt[4] or "")) if tt[5] then bHelp = tt[5] .. "$" .. (tt[6] or "") .. "$" .. (tt[7] or "") end elseif tt[1] and tt[1] == 2 then table.insert(bContent, (tt[4] or "")) table.insert(bContent, (tt[5] or "")) if tt[6] then bHelp = tt[6] .. "$" .. (tt[7] or "") .. "$" .. (tt[8] or "") end elseif tt[1] and (tt[1] == 3 or tt[1] == 32) then table.insert(bContent, (tt[4] or "")) table.insert(bContent, (tt[5] or "")) table.insert(bContent, (tt[6] or "")) if tt[7] then bHelp = tt[7] .. "$" .. (tt[8] or "") .. "$" .. (tt[9] or "") end elseif tt[1] and (tt[1] == 4 or tt[1] == 42) then table.insert(bContent, (tt[4] or "")) table.insert(bContent, (tt[5] or "")) table.insert(bContent, (tt[6] or "")) table.insert(bContent, (tt[7] or "")) if tt[8] then bHelp = tt[8] .. "$" .. (tt[9] or "") .. "$" .. (tt[10] or "") end elseif tt[1] and (tt[1] == 5 or tt[1] == 52) then table.insert(bContent, (tt[4] or "")) table.insert(bContent, (tt[5] or "")) table.insert(bContent, (tt[6] or "")) table.insert(bContent, (tt[7] or "")) table.insert(bContent, (tt[8] or "")) if tt[9] then bHelp = tt[9] .. "$" .. (tt[10] or "") .. "$" .. (tt[11] or "") end end

return tableItems(tArgs[1], (tt[2] or 1), (tt[1] or "?"), (tt[3] or "?"), bContent, bHelp) end

function p.getList local tOut = {} local allBundles = {} for bType, v in pairs(bundleData) do		for bName, bData in pairs(v) do if bData["D"] and ((bData["D"][1] .. util.dayStart) < today) and ((date(bData["D"][1]):adddays(bData["D"][2]):fmt("%Y/%m/%d") .. (bData["D"][3] or util.dayStart)) > today) then if bType == "default" then bType = "zz" end table.insert(allBundles, {bData, bType, bName}) elseif bData["D"] and ((bData["D"][1] .. util.dayStart) < today) and bData["D"][2] == 0 then if bType == "default" then bType = "zz" end table.insert(allBundles, {bData, bType, bName}) end end end

table.sort(allBundles, function(a,b)			if a[1]["D"][1] == b[1]["D"][1] then				return a[3] < b[3]			else				return a[1]["D"][1] > b[1]["D"][1]			end		end)

for _, cItem in pairs(allBundles) do   		local data = cItem[1] table.insert(tOut, tableItems(cItem[2], cItem[3], data[1], data["D"], data["C"], data["H"])) end

return table.concat(tOut) end

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

local pagename = tArgs[1] if not pagename then pagename = mw.title.getCurrentTitle.text end

local tOut = "" local tItem = {} local space = "" local today = os.date("%Y/%m/%d %H:%M:%S") for sName, data in pairs(bundleData) do		for bName, 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), bName}) 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 pagename == values[1] and today >= UnlockDate and (today <= LockDate or values[3] == 0) then tOut = tOut .. space .. "" .. values[5] .. "" space = " " end end

if tOut ~= "" then tOut = tOut .. " " end

return tOut end

return p