FANDOM


------
-- LUA script replacement for wikitext template
--
-- [[File:c-{{lc:{{{1}}}}}{{#if:{{{2|}}}
-- |{{#ifexist: File:c-{{lc:{{{1}}}-{{{2}}}.png}}
-- |-{{lc:{{{2}}}}}|}}|}}.png|x50px|{{{1}}}|link={{{1}}}]]
--
-- Parameters:
-- 1: Character Name
-- 2: Event / IP version
--
-- The list of available versions is kept in the module data
-- to avoid the expensive function "ifexist"
--
-- Plain version is returned if Event version is not in data.
------
 
local p = {}
 
local avatarData = mw.loadData( 'Module:CharacterAvatar/data' )
 
function p.getAvatar(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 eventName  = mw.ustring.lower(tArgs[2] or "")
    local size = tArgs[3]
 
    if not size or size == "" then
        size = "50"
    end
 
    character = character:gsub("^%s*(.-)%s*$", "%1") or ''
    eventName = eventName:gsub("^%s*(.-)%s*$", "%1") or ''
 
    local avatarFile = ""
    local space = ""
 
    for cName in mw.text.gsplit(character, "%s*!%s*") do
 
        if cName ~= "" then
            local charlow = cName:lower()
 
            avatarFile = avatarFile .. space
                        .. "[[File:c-"
                        .. charlow
 
            if avatarData[eventName] and avatarData[eventName][charlow] then
                avatarFile = avatarFile .. "-"
            	            .. (avatarData[eventName]["F"] or eventName)
            end
 
            avatarFile = avatarFile .. ".png|x"
                .. size
                .. "px|"
                .. cName
                .. "|link="
                .. cName
                .. "]]"
        else
            avatarFile = avatarFile .. space
                        .. "[[File:work_in_progress.png|x"
                        .. size
                        .. "px|Unkown|link=Work In Progress]]"
        end
        space = " "
    end
 
    return avatarFile
end
 
return p
 
-- </nowiki>
-- [[Category:Lua Modules]]
Community content is available under CC-BY-SA unless otherwise noted.