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 Character names can be of the form CharacterName%DisplayName

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 Character names can be of the form CharacterName%DisplayName

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' VL.vardefine("img" .. i .. "-2", tostring(file)) else file = 'cc-' .. mw.ustring.lower(file) .. '-' .. i .. '.png' VL.vardefine("img" .. i, tostring(file)) 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, cName in ipairs(ch) do			table.insert(characters, cName) nCh = k		end

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

for No, cData in pairs(characters) do			local premium = "" local cName, dispName = mw.ustring.match(cData, "^(.+)%%(.+)$") if cName then dispName = cName .. "|" .. dispName else cName = cData dispName = cName end

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 .. 				.. dispName				..  .. 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 VL.vardefine("ch" .. i .. "-2", table.concat(tCh)) else VL.vardefine("ch" .. i, table.concat(tCh)) 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