Module:Icons

local p = {}

--	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.

local class = { ['light'] = 'lighticon', ['dark'] = 'darkicon', ['general'] = 'generalicon' }

-- Added this function in as a common method to check if a variable is 	populated. Old code was making this check multiple times in different forms.	The child parameter is to check if a row exists when object is a table. function exists(object, child) if object ~= nil and object ~= '' then if child ~= nil then if object[child] ~= nil and object[child] ~= '' then return true else return false end else return true end else return false end end

function trim(object) --Use of while instead of if incase multiple whitespaces are present. while string.sub(object, 1, 1) == ' ' do 		object = string.sub(object, 2) end while string.sub(object, string.len(object)) == ' ' do		object = string.sub(object, 1, string.len(object) - 1) end return object end

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 exists(frame.args[2]) == true then iconSetting = tostring(frame.args[2]) if exists(iconSize[iconSetting]) == true then iconSetting = iconSize[iconSetting] end else iconSetting = iconSize["medium"] end local iconLinks if exists(frame.args[3]) == true then iconLinks = mw.text.split(frame.args[3], ",") end local tipOverride if exists(frame.args[4]) == true then tipOverride = mw.text.split(frame.args[4], ",") end

local result = ""

for k, v in ipairs(iconList) do       newIcon = iconData[trim(v)] if exists(newIcon) then currentIcon = newIcon.icon if exists(tipOverride, k) == true then currentTip = tipOverride[k] else if 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 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 .. ']]'       --light/dark theme handling if exists(newIcon.class) == true then iconClass = 'va-icon ' .. class[newIcon.class] else iconClass = 'va-icon' end createTip = mw.html.create('span') createTip:addClass( iconClass ) :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[trim(v)] if 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 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)        table.sort(keys) 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 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