Module:ItemCollection

-- --

--[[

-- LUA script to get Collection Icon for Character or Collection Name

-- Parameters: -- 1: Character Name (or Collection short Name) --     Separate multiple characters with a dollar sign "$" -- 2: Icon Size in pixels --     If = "T", then includes Text name/link and size = 25 --     if = "A", then links to section/anchor on current page --]]

local p = {}

local collectionData = mw.loadData( 'Module:CharacterCollection/data' )

function oneCollection(collNo, size, outType) local fileLink = ""

if collectionData["Collections"][collNo] then local collName = collectionData["Collections"][collNo][1] local file = mw.ustring.gsub(collName, "[\,\.']", "") file = mw.ustring.gsub(file, " ", "_") file = mw.ustring.lower(file) if outType == 1 then fileLink = ""               .. collName                .. " ("        end        fileLink = fileLink            .. "[[File:cc-"            .. file            .. "-l.png|x"            .. size            .. "px|"            .. collName            .. "|link="

if outType == 2 then fileLink = fileLink .. "#"       else fileLink = fileLink .. "Category:" end fileLink = fileLink .. collName .. "]]"       if outType == 1 then fileLink = fileLink .. ")"       end    end    return fileLink end

function p.getCollection(frame)

local tArgs

if frame == mw.getCurrentFrame then fParent = frame:getParent tArgs = fParent.args

if (fParent.args[1]) then tArgs = fParent.args else tArgs = frame.args end else tArgs = frame end

local character = tArgs[1] or "" local size = tArgs[2]

local outType = 0

if not size or size == "" then size = "50" elseif not tonumber(size) then if size == "A" then outType = 2 size = "40" else outType = 1 size = "25" end end

local collectionFile = "" local space = "" local collections = {}

character = mw.ustring.gsub(character, "^%s*(.-)%s*$", "%1") or '' character = mw.ustring.lower(character)

if character == "all" then for k, v in pairs(collectionData["Collections"]) do           if not v[2] then table.insert(collections, k)           end end

table.sort(collections)

for _, collNo in ipairs(collections) do           collectionFile = collectionFile .. space .. oneCollection(collNo, size, outType)

if outType == 1 then space = ", " else space = " " end end else for cName in mw.text.gsplit(character, "%s*%$%s*") do           cName = mw.text.decode(cName) if collectionData[cName] then local collNo = collectionData[cName] if not collections[collNo] then collectionFile = collectionFile .. space .. oneCollection(collNo, size, outType) if outType == 1 then space = ", " else space = " " end collections[collNo] = 1 end end end end return collectionFile end

return p