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] if not size or size == "" then size = "25" end

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

if not tokenType or tokenType == "" then -- this is to check if character and token type -- are passed as one parameter local ch, tt = mw.ustring.match(character, "^(.-)[%s,](%d+)$") if tt then character = ch           tokenType = tt        else tokenType = "0" end end

local tokenFile local tokenLink

if tokenData[character] and tokenData[character][tokenType] then if tokenData[character]["F"] then tokenFile = "[[File:t-" .. tokenData[character]["F"]       else            tokenFile = "[[File:t-" .. character        end        tokenFile = mw.ustring.gsub(tokenFile, " ", "_")        tokenLink = "|" .. tokenData[character][tokenType]            .. " Token|link="            .. tokenData[character][tokenType]            .. " Token]]"    else        tokenFile = "work_in_progress"        tokenLink = ""        tokenType = "0"    end

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

return tokenFile end

return p