Module:Icons

From Melvor Idle
Revision as of 02:52, 18 September 2020 by Falterfire (talk | contribs) (Fixed a minor formatting thing, set up override for Melee)

Documentation for this module may be created at Module:Icons/doc

--You can't generate Templates from within Lua due to the loading order, so instead copying the Icon functionality into a module so it can be pulled elsewhere.
--Should function very similarly to how Template:Icon works

local p = {}

function p.Icon(frame)
  local args = frame.args ~= nil and frame.args or frame
  local link = args[1]
  local text = args[2]
  local type = args.type
  local ext = args.ext ~= nil and args.ext or 'svg'
  local notext = args.notext ~= nil and args.notext ~= ''
  local menu = args.menu ~= nil and args.menu ~= ''
  local imgSize = args.size ~= nil and args.size or 25
  local qty = args.qty

  local img = link
  --MANUAL OVERRIDES
  if text == 'Melee' then
    img = 'Combat'
  end

  local result = '[[File:'..img
  if type ~= nil and type ~= '' then result = result..'_('..type..')' end
  result = result..'.'..ext..'|'..tostring(imgSize)..'px|link='..link..']]'
  if qty ~= nil and qty ~= '' then result = result..' '..qty end
  if not notext then 
    result = result..' [['..link
    if text ~= nil and text ~= '' then
      result = result..'|'..text
    end
    result = result..']]'
  end

  if menu then
    result = '{| class="articletable" style="display:inline-block;vertical-align:bottom;"\r\n|-\r\n|'..result
    result = result..'\r\n|}'
  end

  return result
end

return p