No edit summary |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 96: | Line 96: | ||
.. "px" |
.. "px" |
||
.. tokenLink |
.. tokenLink |
||
+ | |||
− | + | if count and count ~= "" then |
|
+ | tokenFileAll = tokenFileAll .. "'''" .. count .. "'''" |
||
+ | end |
||
space = " " |
space = " " |
Revision as of 00:02, 27 May 2020
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: 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 = "[[File:work_in_progress"
tokenLink = "|" .. cName
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
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