FANDOM


(Created page with "------ -- LUA script to get Collection Icon for Character ---- -- Parameters: -- 1: Character Name -- 2: Icon Size -- ------ local p = {} local collectionData = mw.loadData(...")

Revision as of 18:20, May 21, 2020

------
-- LUA script to get Collection Icon for Character
----
-- Parameters:
-- 1: Character Name
-- 2: Icon Size
--
------
 
local p = {}
 
local collectionData = mw.loadData( 'Module:CharacterCollection/data' )
 
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]
 
    if not size or size == "" then
        size = "50"
    end
 
    character = mw.ustring.gsub(character, "^%s*(.-)%s*$", "%1") or ''
 
    local collectionFile = ""
    local space = ""
 
    local collections = {}
 
    for cName in mw.text.gsplit(character, "%s*!%s*") do
 
        local charlow = mw.ustring.lower(cName)
 
        if collectionData[charlow] then
        	collections[collectionData[charlow]] = 1
        end
    end
 
    for coll, _ in pairs(collections) do
        collectionFile = collectionFile .. space
            .. "[[File:cc-"
            .. mw.ustring.gsub(mw.ustring.lower(coll), " ", "_")
            .. "-l.png|x"
            .. size
            .. "px|"
            .. coll
            .. "|link=Category:"
            .. coll
            .. "]]"
 
        space = " "
    end
 
    return collectionFile
end
 
return p
Community content is available under CC-BY-SA unless otherwise noted.