Module:CharacterToken

-- -- LUA script replacement for wikitext template -- -- t-.png -- -- -- Parameters: -- 1: Token = (character,token type,count) --           count is optional -- 2: Size in pixels --     optional, defaults to 25 -- 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 token = tArgs[1] or "" local size = tArgs[2] if not size or size == "" then size = "25" end

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

local tokenFileAll = "" local space = ""

for tok in mw.text.gsplit(token, "%s*!%s*") do

local tokenFile local tokenLink local cName, tokenType, count = mw.ustring.match(tok,                            "^([^,]-)%s*,%s*(%d+)%s*,*%s*([\/%d]*)$")

if not cName then cName, count = mw.ustring.match(tok, "^([^,]-)%s*,%s*,*%s*([\/%d]*)$") if not cName then cName = tok end end

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

if tokenData[cName] and tokenData[cName][tokenType] then if tokenData[cName]["F"] then tokenFile = "[[File:t-" .. tokenData[cName]["F"]           else                tokenFile = "[[File:t-" .. cName            end            tokenFile = mw.ustring.gsub(tokenFile, " ", "_")            tokenLink = "|" .. tokenData[cName][tokenType]                .. " Token|link="                .. tokenData[cName][tokenType]                .. " Token]]"        else            tokenFile = "work_in_progress"            tokenLink = ""            tokenType = "0"        end        if tokenType ~= "0" then            tokenFile = tokenFile .. "-" .. tokenType        end        tokenFileAll = tokenFileAll .. space            .. tokenFile .. ".png|x"            .. size            .. "px"            .. tokenLink

if count and count ~= "" then tokenFileAll = tokenFileAll .. "'''" .. count .. "'''"       end

space = " " end return tokenFileAll end

return p