Module:Icons

local p = {} local util = require( 'Module:Util' ) --	Icon data is now stored on the sub page /data to seperate functional code	for the dataset users will often need to update. This reduces the risk of	breaking the code by entering data in the wrong place and makes it easier to	manage the code itself by not having to pass through the large dataset at 	the top.

require( 'Module:Icons/data' )

local iconSize = { --       All sizes are controlled on the height to ensure a string of icons maintain         a consistent line height ["small"]          = "x10px", ["medium"]         = "x14px", ["normal"]         = "x14px", ["big"]            = "x20px", }

-- 28/Oct/2021 Added class control table to array as to handle light/dark 	themes. This was originally put into the frontend template, when class	handling should be back end. Adding the ['class'] = 'light' or 	['class'] = 'dark' parameter to a icon's dataset on /data will enable it to	access a class if needed.

-- 08/Nov/2021 Remove the class definition as to be able to just pass straight through local class = {	['light'] = 'lighticon',	['dark'] = 'darkicon',	['general'] = 'generalicon' }

function p.Icons(frame) --All icons are now lower case to reduce script errors from 	incorrectly entering the icon code in a different case to the list local iconList = mw.text.split(string.lower(frame.args[1]), ",") local parserError = "" local iconSetting if util.exists(frame.args[2]) == true then iconSetting = tostring(frame.args[2]) if util.exists(iconSize[iconSetting]) == true then iconSetting = iconSize[iconSetting] end else iconSetting = iconSize["medium"] end local iconLinks if util.exists(frame.args[3]) == true then iconLinks = mw.text.split(frame.args[3], ",") end local tipOverride if util.exists(frame.args[4]) == true then tipOverride = mw.text.split(frame.args[4], ",") end local iconClass = '' if util.exists(frame.args[5]) == true then iconClass = "|class="..tostring(frame.args[5]); end

local result = ""

for k, v in ipairs(iconList) do       newIcon = iconData[util.trim(v)] if util.exists(newIcon) then currentIcon = newIcon.icon if util.exists(tipOverride, k) == true then currentTip = tipOverride[k] else if util.exists(iconLinks, k) == true then currentTip = iconLinks[k] else currentTip = newIcon.tip end end else currentIcon = "Icon question.png" currentTip = "Unrecognized icon name" result = result .. ""       end --Create wikitext icon dataLine = '[[File:' .. currentIcon .. '|' .. iconSetting       if util.exists(iconLinks, k) ==true then            dataLine = dataLine .. '|link=' .. iconLinks[k]        else            dataLine = dataLine .. '|link='        end        if currentTip ~= nil then            dataLine = dataLine .. '|' .. currentTip        end

dataLine = dataLine .. iconClass .. ']]'

createTip = mw.html.create('span') createTip:addClass( 'va-icon' ) :attr('title', currentTip) :wikitext(dataLine) result = result .. tostring(createTip) if k < table.getn(iconList) then result = result .. " "       end end return result .. parserError end

function p.platforms(frame) --All icons are now lower case to reduce script errors from 	incorrectly entering the icon code in a different case to the list local icons = mw.text.split(string.lower(frame.args[1]), ",") local result = "" for k, v in ipairs(icons) do       currentIcon = iconData[util.trim(v)] if util.exists(currentIcon, 'platform') == true then createSM = mw.html.create('span') createSM:css('display', 'none') :wikitext('Has platform::' .. currentIcon.tip .. '') :allDone createPlatform = mw.html.create('span') createPlatform:addClass('va-icon') :attr('title', currentIcon.tip) :wikitext(            			.. currentIcon.icon             			.. ) :allDone -- Uncommenting tostring(createSM) below will enable            	Semantic Mediawiki data tracking result = result .. tostring(createSM) .. tostring(createPlatform) if k < table.getn(icons) then result = result .. " "           end end end if result == '' then result = '[Platforms needed]' end return result end

function p.documentation keys = {} for k in pairs(iconData) do       table.insert(keys, k)    end table.sort(keys) result = '{| class="va-table va-table-full"\n|-\n !prefix!!Icon!!prefix!!Icon!!prefix!!Icon\n|-\n' set = 1 for k,v in ipairs(keys) do		i = iconData[v] result = result .. "||'''" .. v .. "'''"       if util.exists(i) == true and i.class ~= nil then newFile = mw.html.create(span) --:addClass(class[i.class]) :wikitext('') else newFile = mw.html.create(span) :wikitext('') end result = result .. '||' .. tostring(newFile) if set == 3 then result = result .. '\n|-\n' end if set < 3 then set = set + 1 else set = 1 end end result = result .. '\n|}' return result end

function p.Test(frame) --Please empty when done debugging so other users know it is free to use end

return p