Description
This module is the Lua back-end for {{Token}}, to display character token icons.
Usage
{{#invoke:CharacterToken|getToken|<parameter list>}}
For parameter details see Template:Token/doc
------
-- LUA script replacement for wikitext template
--
-- [[File:t-{{{1}}}{{#if:{{{2|}}}|-{{{2}}}|}}.png
-- |x25px|{{{3}}} Token|link={{{3}}} Token]]
--
-- 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, "^(.-),(%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 = "[[File:work_in_progress"
tokenLink = "|" .. character
if tokenType ~= "0" then
tokenLink = tokenLink .. " " .. tokenType
end
tokenLink = tokenLink .. "|link=Work In Progress]]"
tokenType = "0"
end
if tokenType ~= "0" then
tokenFile = tokenFile .. "-" .. tokenType
end
tokenFile = tokenFile .. ".png|x"
.. size
.. "px"
.. tokenLink
return tokenFile
end
return p