Module:Icons: Difference between revisions

From Melvor Idle
(man fuck those stupid identically named spiders, amirite?)
(Added GP function)
Line 3: Line 3:


local p = {}
local p = {}
local Shared= require("Module:Shared")


function p.Icon(frame)
function p.Icon(frame)
Line 36: Line 38:
   result = result..']]'
   result = result..']]'


   if qty ~= nil and qty ~= '' then result = result..' '..qty end
   if qty ~= nil and qty ~= '' then result = result..' '..Shared.formatnum(qty) end


   if not notext then  
   if not notext then  
Line 59: Line 61:
   end
   end


  return result
end
function p.GP(amt, maxamt)
  local result = p.Icon({'Coins', notext=true})
  result = result..' '..Shared.formatnum(amt)
  if maxamt ~= nil then result = result..' - '..Shared.formatnum(maxamt) end
   return result
   return result
end
end


return p
return p

Revision as of 18:02, 20 September 2020

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 = {}

local Shared= require("Module:Shared")

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 nolink = args.nolink ~= nil and args.nolink ~= ''
  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 link == 'Melee' then
    img = 'Combat'
  elseif link == 'Spider (lv. 51)' then
    img = 'Spider'
  elseif link == 'Spider (lv. 52)' then
    img = 'Spider2'
  elseif link == 'Spider' then
    link = 'Spider (lv. 51)'
  elseif link == 'Spider2' then
    link = 'Spider (lv. 52)'
  end

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

  if qty ~= nil and qty ~= '' then result = result..' '..Shared.formatnum(qty) end

  if not notext then 
    if nolink then
      if text ~= nil and text ~= '' then
        result = result..' '..text
      else
        result = result..' '..link
      end
    else
      result = result..' [['..link
      if text ~= nil and text ~= '' then
        result = result..'|'..text
      end
      result = result..']]'
    end
  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

function p.GP(amt, maxamt)
  local result = p.Icon({'Coins', notext=true})
  result = result..' '..Shared.formatnum(amt)
  if maxamt ~= nil then result = result..' - '..Shared.formatnum(maxamt) end
  return result
end

return p