Module:CharacterToken

-- -- LUA script replacement for wikitext template -- -- t-.png -- -- -- Parameters: -- 1: Character Name -- 2: Token Type -- -- The list of available tokens is kept in the module data -- -- Unknown Token is returned if Token Type is not in data. --

local p = {}

local tokenData = mw.loadData( 'Module:CharacterToken/data' )

function p.getToken(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 tokenType = tArgs[2] local size = tArgs[3] or "25"

character = mw.ustring.gsub(mw.ustring.lower(character), "^%s*(.-)%s*$", "%1") or ''

if not tokenType or tokenType == "" then tokenType = "0" end

local tokenFile = "[[File:t-" .. character   local tokenLink

if tokenData[character] and tokenData[character][tokenType] then if tokenData[character]["F"] then tokenFile = "[[File:t-" .. tokenData[character]["F"]       end

tokenLink = "|" .. tokenData[character][tokenType] .. " Token|link=" .. tokenData[character][tokenType] .. " Token]]" else tokenLink = "|Unknown Token|link=Work In Progress]]" end

if tokenType ~= "0" then tokenFile = tokenFile .. "-" .. tokenType end tokenFile = tokenFile .. ".png|x" .. size .. "px" .. tokenLink

return tokenFile end

return p