TextIcons formats text icons closely to how they would look ingame.
Documentation
Package items
TextIcons._getIcon(text, frame)
(function)- Gets text with symbols replaced.
- Parameters:
- Returns:
- Created with Docbunto
See Also
Code
--- '''TextIcons''' formats [[Text Icons|text icons]] closely to how they would look ingame.
--
-- @module TextIcons
-- @image TooltipPic.png
-- @require [[Module:TextIcons/data]]
-- @release experimental
-- <nowiki>
local p = {}
local TextIconsData = mw.loadData [[Module:TextIcons/data]]
--- Gets text with symbols replaced.
-- @function p._getIcon
-- @param {string} text text to convert
-- @param[opt] {table} frame table contains optional parameters
-- @param[opt] {string} frame.class css class to be included
-- @param[opt] {string} frame.platform specific platform (e.g. 'PC','IOS')
-- @param[opt] {int} frame.size height of the image
-- @return {string} converted text
-- @return {number} number of converted tokens
function p.getIcon(text, frame)
local platform = frame.platform
local class = frame.class
local size = frame.size
return text:gsub('<([A-Za-z0-9_]+)>', function(key)
local index = TextIconsData[key] or
error(('getIcon(text, frame): TextIcon with text "%s" does not exist in [[Module:TextIcons/data]]'):format(key or '<nil>'))
local image = index.Image[platform] or index.Image.AUTO or index.Image.AGNOSTIC or
error(('getIcon(text, frame): TextIcon with text "%s" and platform "%s" does not exist in [[Module:TextIcons/data]]'):format(key or '<nil>', platform or '<nil>'))
if key == 'LINE_SEPARATOR' then
return '<hr />'
end
local result = '[[File:' .. image
if class or index.Invert then
result = result .. '|class=' .. class or '' .. index.Invert and 'light-invert' or ''
end
if size then
result = result .. '|x' .. size .. 'px'
end
result = result .. ']]'
return result
end)
end
return p