Module:CharacterAvatar

-- -- LUA script replacement for wikitext template -- -- -- -- 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] or "x50px"

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 avatarData[eventName] and avatarData[eventName][charlow] then avatarFile = avatarFile .. "-" .. avatarData[eventName][charlow] end

avatarFile = avatarFile .. ".png|" .. size .. "|"   	.. character .. "|link=" .. character .. "]]"

return avatarFile end

return p