Module:LTETables

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

local p = {}

local util = require("Module:Utility") local EC = require("Module:EC").getEC

local tArgs = {}

-- Item Type local ch   = {} local cos  = {} local ba   = {} local bc   = {} local d   = {} local pf   = {}

local function items(inStr) local tIn = mw.text.split(inStr, "%s*%$%s*") local tOut = {} for idx = 1, #tIn do		local tt = mw.text.split(tIn[idx], "%s*#%s*") if not tt[2] or tt[2] == "" then tt[2] = tt[1] end table.insert(tOut, tt) 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 then if cat == "ch" then ch[num] = items(value) elseif cat == "cos" then cos[num] = items(value) elseif cat == "ba" then ba[num] = items(value) elseif cat == "bc" then bc[num] = items(value) elseif cat == "d" then d[num] = items(value) elseif cat == "pf" then pf[num] = items(value) end 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 tWelc = {} local tCost = {}

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

if iType == "ch" then tItems = ch	elseif iType == "cos" then tItems = cos elseif iType == "ba" then tItems = ba	elseif iType == "bc" then tItems = bc	elseif iType == "d" then tItems = d	elseif iType == "pf" then tItems = pf	end

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

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 table.insert(tImag, '|') local fname = rData[1]:lower:gsub("[':%,%.]", ""):gsub(" ", "_") if iType == "pf" then fname = fname:gsub("_float$", "") else fname = fname:gsub("^([^%(]-)_*%(([^%d]+%d*)%)$", "%1-%2")				end				table.insert(tImag, table.concat({""}))				table.insert(tImag, '\n')				table.insert(tLink, '|')				table.insert(tLink, rData[2])				end				table.insert(tLink, '\n')			end

if rNo == 3 then if rData[1] == "" then table.insert(tWelc, '|\n') else table.insert(tWelc, '| ')					table.insert(tWelc, rData[2])					end					table.insert(tWelc, ' \n') 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 table.insert(tWelc, ' ')				table.insert(tWelc, rData[2])				table.insert(tWelc, ' \n') 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(tWelc) ~= noquest then table.insert(tHead, '|-\n') table.insert(tHead, table.concat(tWelc)) 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 = {}

if ch[1] and ch[2] then table.insert(allTables, iTable("Characters", "ch")) elseif ch[1] then table.insert(allTables, iTable("Character", "ch")) end

if cos[1] and cos[2] then table.insert(allTables, iTable("Costumes", "cos")) elseif cos[1] then table.insert(allTables, iTable("Costume", "cos")) end

if ba[1] and ba[2] then table.insert(allTables, iTable("Attractions", "ba")) elseif ba[1] then table.insert(allTables, iTable("Attraction", "ba")) end

if bc[1] and bc[2] then table.insert(allTables, iTable("Concessions", "bc")) elseif bc[1] then table.insert(allTables, iTable("Concession", "bc")) end

if d[1] and d[2] then table.insert(allTables, iTable("Decorations", "d")) elseif d[1] then table.insert(allTables, iTable("Decoration", "d")) end

if pf[1] and pf[2] then table.insert(allTables, iTable("Parade Floats", "pf")) elseif pf[1] then table.insert(allTables, iTable("Parade Float", "pf")) end

return table.concat(allTables) end

return p