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 AVATAR = require("Module:CharacterAvatar").getAvatar local date = require("Dev:Date")

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 = 30

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

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

if iData and iData[2] then if type == "N" then tItem = "" .. iName .. "" else size = 40 if not type then size = 100 end if type == "C" then size = 75 end

local fname = iName:lower:gsub("[':%,%.]", ""):gsub(" ", "_") if iData[2] == "pf" then fname = fname:gsub("_float$", "") elseif iData[2] == "ec" then fname = fname:gsub("_chests$", "") size = 75 if type == "C" then size = 50 end 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 == "N" then tItem = EC({iName, "L", S=(nCount == "1")}) elseif type == "S" then tItem = EC({iName, nil, nil, nil, 30}) if nCount ~= 0 then tItem = tItem .. " '''x" .. nCount .. "'''" end else tItem = EC({iName, nil, nil, "I", 50}) 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 if not type then size = 75 end if type == "C" then size = 50 end tItem = TOK({iName, size}) if nCount ~= 0 then tItem = tItem .. " '''x" .. nCount .. "'''" end end end

return tItem end

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

function p.getBundles local tOut = {} local allBundles = {} local today = os.date("%Y/%m/%d %H:%M:%S") 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, '{| class="card ')		if cItem[2] == "zz" then cItem[2] = "default" end		table.insert(tOut, cItem[2])		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 not data["D"] or (((data["D"][1] .. util.dayStart) < today) and data["D"][2] == 0) then table.insert(tOut, "Permanent Content") else table.insert(tOut, util.ordinal(date(data["D"][1]):fmt("%d"))) table.insert(tOut, date(data["D"][1]):fmt(" %B")) table.insert(tOut, " - ") table.insert(tOut, util.ordinal(date(data["D"][1]):adddays(data["D"][2]):fmt("%d"))) table.insert(tOut, date(data["D"][1]):adddays(data["D"][2]):fmt(" %B")) 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, tableItems(data[1], data["C"])) table.insert(tOut, '\n|-\n| style="width: 230px !important; height: 80px; background-size: cover; background-position: 0 -260px; vertical-align: baseline; padding: 0 10px;"|') table.insert(tOut, " '''") table.insert(tOut, cItem[3]) table.insert(tOut, " Bundle''' \n|}\n")

table.insert(tOut, '{| class="bundle-content"\n! colspan="6"| Content  \n|-') for _, v in ipairs(data["C"]) do			table.insert(tOut, '\n|') table.insert(tOut, oneItem(v, "C")) end if data["H"] 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(data["H"], "%s*$%s*") do				table.insert(tOut, space) table.insert(tOut, AVATAR({hChar, "50"})) table.insert(tOut, ' ')				table.insert(tOut, hChar)				table.insert(tOut, ' ') space = " " end end table.insert(tOut, '\n|-') for _, v in ipairs(data["C"]) do			table.insert(tOut, '\n| ') table.insert(tOut, oneItem(v, "N")) table.insert(tOut, ' ') end table.insert(tOut, '\n|}\n') end return table.concat(tOut) end

return p