Module:CharacterAvatar

--[=[ Lua script replacement for wikitext template



Parameters: 1: Character Name Separate multiple characters with dollar sign "$" 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' ) local collectionData = mw.loadData( 'Module:ItemCollection/data' ) local util = require('Module:Utility')

function p.getAvatar(frame) local tArgs = util.getArgs(frame)

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("", "") or '' eventName = eventName:gsub("^%s*(.-)%s*$", "%1") or ''

local avatarFile = {}

local t1Char = { "",			"", "", "",			"", "",			".png", ""	}

for cName in mw.text.gsplit(character, "%s*%$%s*") do       if cName ~= "" then local charlow = cName:lower if collectionData["Items"][cName] and collectionData["Items"][cName][2] == "mb" then t1Char[ 3] = "npc-" else t1Char[ 3] = "c-" end t1Char[ 4] = charlow:gsub("[%.']", "") :gsub("^([^%(]-)%/([^%(]-)$", "%1-%2") :gsub(" ", "_") t1Char[10] = cName t1Char[12] = cName

if avatarData[eventName] and avatarData[eventName][charlow] then t1Char[5] = "-" t1Char[6] = avatarData[eventName]["F"] or eventName elseif eventName == "side" then t1Char[5] = "-" t1Char[6] = "side" else t1Char[1] = "" t1Char[5] = "" t1Char[6] = "" t1Char[14] = " " end else t1Char[ 1] = "" t1Char[ 3] = "" t1Char[ 4] = "work_in_progress" t1Char[ 5] = "" t1Char[ 6] = "" t1Char[10] = "Unknown" t1Char[12] = "Work In Progress" t1Char[14] = "" end

table.insert(avatarFile, table.concat(t1Char)) --t1Char[1] = " " end

return table.concat(avatarFile, " ") end

return p