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 = frame:getParent()
 
    if not(tArgs.args[1]) then
        tArgs = frame
    end
 
    local character = tArgs.args[1] or ""
    local eventName  = mw.ustring.lower(tArgs.args[2] or "")
 
    character = mw.ustring.gsub(character, "^%s*(.-)%s*$", "%1") or ''
    eventName = mw.ustring.gsub(eventName, "^%s*(.-)%s*$", "%1") or ''
 
    local charlow = mw.ustring.lower(character)
    local avatarFile = "[[File:c-" .. charlow
 
    if eventName == "main" then
    	avatarFile = avatarFile .. "-" .. eventName
    else
        if avatarData[charlow] and avatarData[charlow][eventName] then
        	avatarFile = avatarFile .. "-" .. avatarData[charlow][eventName]
        end
    end
 
    avatarFile = avatarFile .. ".png|x50px|"
    	.. character
    	.. "|link="
    	.. character
    	.. "]]"
 
    return avatarFile
end
 
return p
Community content is available under CC-BY-SA unless otherwise noted.