Module:InfoboxCollection

--[==[-- -- Lua script to set variables for "Template:Infobox Character Collection" --

getCollectionInfo: set the variables for the Infobox Parameters: 1 = Characters from the first section Separate multiple characters with a dollar sign "$" Two dollar sign "$$" mean we move to a second page of the collection

2 = Characters from the second section Separate multiple characters with a dollar sign "$" Two dollar sign "$$" mean we move to a second page of the collection

name = Collection Name (default PAGENAME) mainly for testing --]==]

local p = {}

local collectionData = mw.loadData( 'Module:ItemCollection/data' ) local EC = require("Module:EC").getEC local util = require('Module:Utility')

function oneSection(frame, section, second) local tArgs = util.getArgs(frame) local pageName = tArgs["name"] or mw.title.getCurrentTitle.prefixedText local VL = mw.ext.VariablesLua

local chTotal = 0 local reTotal = 0 local pages = {}

for allcharacters in mw.text.gsplit(section, "%s*$$%s*") do		table.insert(pages, allcharacters) end

for i, ch in pairs(pages) do		local tCh = {'{| style="width: 280px; text-align: center;"\n'} local characters = {} local nCh = 1

local file = mw.ustring.gsub(pageName, "Category:", "") file = mw.ustring.gsub(file, "[\,\.']", "") file = mw.ustring.gsub(file, " ", "_") if i ~= 1 then if second then file = 'cc-' .. mw.ustring.lower(file) .. '-' .. i .. '-2.png' if i == 2 then VL.vardefine("img2-2", tostring(file)) elseif i == 3 then VL.vardefine("img3-2", tostring(file)) elseif i == 4 then VL.vardefine("img4-2", tostring(file)) elseif i == 5 then VL.vardefine("img5-2", tostring(file)) elseif i == 6 then VL.vardefine("img6-2", tostring(file)) elseif i == 7 then VL.vardefine("img7-2", tostring(file)) elseif i == 8 then VL.vardefine("img8-2", tostring(file)) elseif i == 9 then VL.vardefine("img9-2", tostring(file)) end else file = 'cc-' .. mw.ustring.lower(file) .. '-' .. i .. '.png' if i == 2 then VL.vardefine("img2", tostring(file)) elseif i == 3 then VL.vardefine("img3", tostring(file)) elseif i == 4 then VL.vardefine("img4", tostring(file)) elseif i == 5 then VL.vardefine("img5", tostring(file)) elseif i == 6 then VL.vardefine("img6", tostring(file)) elseif i == 7 then VL.vardefine("img7", tostring(file)) elseif i == 8 then VL.vardefine("img8", tostring(file)) elseif i == 9 then VL.vardefine("img9", tostring(file)) end end else if second then file = 'cc-' .. mw.ustring.lower(file) .. '-1-2.png' VL.vardefine("img1-2", tostring(file)) else file = 'cc-' .. mw.ustring.lower(file) .. '.png' VL.vardefine("img1", tostring(file)) end end

ch = mw.text.split(ch, "%s*%$%s*")

for k, pages in pairs(ch) do			table.insert(characters, pages) nCh = k		end

local rewards = 0 local space = "" local width = math.floor(280/nCh)

for No, cName in pairs(characters) do			local premium = "" if collectionData["Items"][cName] and collectionData["Items"][cName][3] and collectionData["Items"][cName][3] == true then premium = "''" rewards = rewards + 8 else rewards = rewards + 4 end

local oneCh = space .. '| style="width:'				.. width				.. 'px;"|' .. premium .. 				.. cName				..  .. premium .. '\n'

table.insert(tCh, oneCh)

space = '| style="width: 2px;"|' .. "·\n" end

if tArgs["rewards" .. i] then rewards = tonumber(tArgs["rewards" .. i]) or 0 end

local gemsRew = '|-\n| colspan="'			.. nCh + (nCh - 1)			.. '"|' .. "'''Collect them all and win: " .. EC({"Gems"}) .. rewards .. "'''\n|}\n"

table.insert(tCh, gemsRew)

chTotal = chTotal + nCh reTotal = reTotal + rewards

if second then if i == 1 then VL.vardefine("ch1-2", table.concat(tCh)) elseif i == 2 then VL.vardefine("ch2-2", table.concat(tCh)) elseif i == 3 then VL.vardefine("ch3-2", table.concat(tCh)) elseif i == 4 then VL.vardefine("ch4-2", table.concat(tCh)) elseif i == 5 then VL.vardefine("ch5-2", table.concat(tCh)) elseif i == 6 then VL.vardefine("ch6-2", table.concat(tCh)) elseif i == 7 then VL.vardefine("ch7-2", table.concat(tCh)) elseif i == 8 then VL.vardefine("ch8-2", table.concat(tCh)) elseif i == 9 then VL.vardefine("ch9-2", table.concat(tCh)) end else if i == 1 then VL.vardefine("ch1", table.concat(tCh)) elseif i == 2 then VL.vardefine("ch2", table.concat(tCh)) elseif i == 3 then VL.vardefine("ch3", table.concat(tCh)) elseif i == 4 then VL.vardefine("ch4", table.concat(tCh)) elseif i == 5 then VL.vardefine("ch5", table.concat(tCh)) elseif i == 6 then VL.vardefine("ch6", table.concat(tCh)) elseif i == 7 then VL.vardefine("ch7", table.concat(tCh)) elseif i == 8 then VL.vardefine("ch8", table.concat(tCh)) elseif i == 9 then VL.vardefine("ch9", table.concat(tCh)) end end end

local tReward = "Rewards " .. EC({"Gems"}) .. reTotal local tCharacter = "Characters " .. chTotal if second then VL.vardefine("reTotal-2", tReward) VL.vardefine("chTotal-2", tCharacter) else VL.vardefine("reTotal-1", tReward) VL.vardefine("chTotal-1", tCharacter) end

return reTotal end

function p.getCollectionInfo(frame) local tArgs = util.getArgs(frame) local VL = mw.ext.VariablesLua

local Total = 0 if tArgs[2] and tArgs[1] then Total = oneSection(frame, tArgs[1]) + oneSection(frame, tArgs[2], true) elseif tArgs[1] then Total = oneSection(frame, tArgs[1]) end Total = EC({"Gems"}) .. Total

VL.vardefine("reTotal", Total)

return "" end

return p