Module:LTETables

-- Lua script to get Limited Time Event Tables --

local p = {}

local util = require("Module:Utility") local EC = require("Module:EC").getEC local CHEST = require("Module:EnchantedChest").getChest local TOK = require("Module:CharacterToken").getToken

local tArgs = {}

-- Item Type local tItemByType = { ["ch"] = {}, ["tok"] = {}, ["cos"] = {}, ["ba"] = {}, ["bc"] = {}, ["d"]  = {}, ["pf"] = {}, ["ec"] = {}, ["bs"] = {}, }

local function items(inStr) local tIn = mw.text.split(inStr, "%s*%$%s*") local tOut = {} for idx = 1, #tIn do		local tName, tDips = mw.ustring.match(tIn[idx], "^([^,]-)%s*#%s*(.-)$") if not tName then tName = tIn[idx] end if not tDips then tDips = tName end table.insert(tOut, {tName, tDips}) end return tOut end

local function processArgs(frame) tArgs = util.getArgs(frame)

for arg, value in pairs(tArgs) do		local cat, n = tostring(arg):match('^(%a+)([1-9]%d*)$') local num = tonumber(n) if num and tItemByType[cat] then tItemByType[cat][num] = items(value) end end end

local function iTable(iName, iType) local tHead = {'|-|', iName, '=\n', '{| class="article-table dmk-event" style="width: 100%;"\n'}

local tDate = {} local tImag = {} local tLink = {} local tRequ = {} local tCost = {}

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

tItems = tItemByType[iType]

local num = "" for arg, value in pairs(tItems) do num = arg end

local nRequ = 0 for chNo, chData in ipairs(tItems) do		for rNo, rData in ipairs(tItems[chNo]) do			if rNo == 1 then table.insert(tDate, '! style="width: ')				table.insert(tDate, string.format("%.2f", (100 / num)))				table.insert(tDate, '%;"|') table.insert(tDate, rData[1]) table.insert(tDate, '\n') end

if rNo == 2 then local cData = mw.loadData("Module:ItemCollection/data") local iData = cData.Items[rData[1]] or "" table.insert(tImag, '|') if rData[1]:match(" Chests") then table.insert(tImag, CHEST({rData[1], 75})) elseif iData and iData ~= "" then local fname = rData[1]:lower:gsub("[':%,%.]", ""):gsub(" ", "_") if iData[2] == "pf" then fname = fname:gsub("_float$", "") else fname = fname:gsub("^([^%(]-)_*%(([^%d]+%d*)%)$", "%1-%2")					end					table.insert(tImag, table.concat({""}))				else					table.insert(tImag, TOK({rData[1], 75}))				end				table.insert(tImag, '\n')				table.insert(tLink, '|')				if rData[1]:match(" Chests") then					table.insert(tLink, CHEST({rData[1], "L"}))				elseif iData and iData ~= "" then					table.insert(tLink, )					table.insert(tLink, rData[2])					end					table.insert(tLink, )				else					table.insert(tLink, TOK({rData[1], "L"}))				end				table.insert(tLink, '\n')			end

if rNo == 3 then if rData[1] == "" then table.insert(tRequ, '|\n') nRequ = nRequ + 1 else table.insert(tRequ, '| ')					table.insert(tRequ, rData[2])					table.insert(tRequ, ' \n') nRequ = nRequ + 5 end end

if rNo == 4 then table.insert(tCost, '|') if rData[1]:match("^EC") then table.insert(tCost, EC({rData[1]})) table.insert(tCost, rData[2]) else table.insert(tCost, rData[1]) if rData[2] ~= rData[1] then table.insert(tCost, rData[2]) end end table.insert(tCost, '\n') end

if rNo == 5 then tRequ[nRequ] = ']] ')				table.insert(tRequ, rData[2])				table.insert(tRequ, ' \n') nRequ = nRequ + 4 end

if rNo == 6 then tRequ[nRequ] = ']] ')				table.insert(tRequ, rData[2])				table.insert(tRequ, ' \n') nRequ = nRequ + 4 end end end

table.insert(tHead, '! colspan="')	table.insert(tHead, num)	table.insert(tHead, '"|Event ') table.insert(tHead, iName) table.insert(tHead, '\n')

table.insert(tHead, '|-\n') table.insert(tHead, table.concat(tDate)) table.insert(tHead, '|-\n') table.insert(tHead, table.concat(tImag)) table.insert(tHead, '|-\n') table.insert(tHead, table.concat(tLink))

local noquest = string.rep("|\n", num) if table.concat(tRequ) ~= noquest then table.insert(tHead, '|-\n') table.insert(tHead, table.concat(tRequ)) end

table.insert(tHead, '|-\n') table.insert(tHead, table.concat(tCost)) table.insert(tHead, '|}\n')

return table.concat(tHead) end

function p.getTables(frame) processArgs(frame)

local allTables = {}

local allTypes = { {"ch", "Character"}, {"tok", "Token"}, {"cos", "Costume"}, {"ba", "Attraction"}, {"bc", "Concession"}, {"d", "Decoration"}, {"pf", "Parade Float"}, {"ec", "Enchanted Chest"}, {"bs", "Bonus Shop", "Bonus Shop"}, }

for _, tt in ipairs(allTypes) do		local tOne = tItemByType[tt[1]] if tOne[1] then local name = tt[2] if tOne[2] then name = tt[3] or (tt[2] .. "s") end table.insert(allTables, iTable(name, tt[1])) end end

return table.concat(allTables) end

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

local tOut = '{| class="article-table" style="width: 100%; text-align: center; line-height: 1.0;"\n! style="width: 20%;"|Collections\n! colspan="7"|Characters\n'

for k, v in pairs(tArgs) do		if tonumber(k) then tOut = tOut .. '|-\n|' if k == 5 then --				tOut = tOut .. '\n' tOut = tOut .. "Featured Character\n" else tOut = tOut .. require('Module:ItemCollection').getCollection({v}) .. '\n' end if not tArgs["C"] then local i = 1 local tCh = {'|\n', '|\n', '|\n', '|\n', '|\n', '|\n', '|\n'} for character in mw.text.gsplit(v, "%s*$%s*") do					tCh[i] = '| style="width: 5%;"| ' .. character .. ' \n' i = i + 1 end tOut = tOut .. table.concat(tCh) end end end

return tOut .. '|}' end

return p