Module:Icons: Difference between revisions

From Melvor Idle
(Added override to grab proper image for the stupid spiders.)
(Added extension overrides for the pets)
(27 intermediate revisions by the same user not shown)
Line 3: Line 3:


local p = {}
local p = {}
--Extension overrides for items that have non-svg images
local extOverrides = {
  ["Crown of Rhaelyx"] = "png",
  ["Jewel of Rhaelyx"] = "png",
  ["Circlet of Rhaelyx"] = "png",
  ["Charge Stone of Rhaelyx"] = "png",
  ["Mysterious Stone"] = "png",
  ["Cloudburst Staff"] = "png",
  ["Earth Layered Shield"] = "png",
  ["Lemon"] = "jpg",
  ["Lemons"] = "jpg",
  ["Lemonade"] = "jpg",
  ["Miolite Sprig"] = "png",
  ["Miolite Trio"] = "png",
  ["Miolite Warden"] = "png",
  ["Miolite Monarch"] = "png",
  ["Wicked Greater Dragon"] = "png",
  ["Hunting Greater Dragon"] = "png",
  ["Chaotic Greater Dragon"] = "png",
  ["Beavis"] = "png",
  ["Pudding Duckie"] = "png",
  ["Pyro"] = "png",
  ["Snek"] = "png",
  ["Larry, the Lonely Lizard"] = "png",
  ["Caaarrrlll"] = "png",
  ["Gronk"] = "png",
  ["Finn, the Cat"] = "png",
  ["Marahute"] = "png",
  ["Monk-ey"] = "png",
  ["Asura"] = "png"
}
--When calling for an icon of type Key, instead use type Value
local typeOverrides = {
  ['combat'] = 'combatArea',
  ['slayer'] = 'combatArea',
}
--When calling for an icon for Key, replace with image Value
local imgOverrides = {
  ['Alt Magic'] = 'Magic',
  ['Alt. Magic'] = 'Magic',
  ['Alternative Magic'] = 'Magic',
  ['Melee'] = 'Combat',
  ['Spider (lv. 51)'] = 'Spider',
  ['Spider (lv. 52)'] = 'Spider2'
}
--When calling for an icon for Key, the link goes to Value
local linkOverrides = {
  ['Alt Magic'] = 'Alternative Magic',
  ['Alt. Magic'] = 'Alternative Magic',
  ['Spider'] = 'Spider (lv. 51)',
  ['Spider2'] = 'Spider (lv. 52)'
}
--If no other text override was specified for the given link, use these
local txtOverrides = {
  ['Spider'] = 'Spider (lv. 51)',
  ['Spider2'] = 'Spider (lv. 52)'
}
local Shared= require("Module:Shared")


function p.Icon(frame)
function p.Icon(frame)
Line 11: Line 71:
   local ext = args.ext ~= nil and args.ext or 'svg'
   local ext = args.ext ~= nil and args.ext or 'svg'
   local notext = args.notext ~= nil and args.notext ~= ''
   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 menu = args.menu ~= nil and args.menu ~= ''
   local imgSize = args.size ~= nil and args.size or 25
   local imgSize = args.size ~= nil and args.size or 25
   local qty = args.qty
   local qty = args.qty
  local img = args.img ~= nil and args.img or link
  link = string.gsub(link, "%%27", "'")
  link = string.gsub(link, "'", "'")
  link = string.gsub(link, "'", "'")
  img = string.gsub(img, "%%27", "'")
  img = string.gsub(img, "'", "'")
  img = string.gsub(img, "'", "'")


   local img = link
   img = string.gsub(img, '#', '')
  link = string.gsub(link, '#', '')
   --MANUAL OVERRIDES
   --MANUAL OVERRIDES
   if link == 'Melee' then
   if imgOverrides[link] ~= nil and img == link then
     img = 'Combat'
     img = imgOverrides[link]
   elseif link == 'Spider (lv. 51)' then
  end
     img = 'Spider'
  if text == nil and txtOverrides[link] ~= nil then
   elseif link == 'Spider (lv. 52)' then
    text = txtOverrides[link]
     img = 'Spider2'
  end
   if linkOverrides[link] ~= nil then
    if text == nil then text = link end
    link = linkOverrides[link]
  end
  if extOverrides[img] ~= nil then  
     ext = extOverrides[img]
  end
  if typeOverrides[type] ~= nil then
    type = typeOverrides[type]
  end
  --There are a couple specific double overrides I want to include that don't fit in the above lists
   if link == 'Golbin' then
     if text == nil then text = 'Golbin' end
    link = 'Golbin ('..type..')'
   end
   end


  --Creating the image...
   local result = '[[File:'..img
   local result = '[[File:'..img
  --Add in type if one is set
   if type ~= nil and type ~= '' then result = result..'_('..type..')' end
   if type ~= nil and type ~= '' then result = result..'_('..type..')' end
   result = result..'.'..ext..'|'..tostring(imgSize)..'px|link='..link..']]'
  --Add in extension and image size
   if qty ~= nil and qty ~= '' then result = result..' '..qty end
   result = result..'.'..ext..'|'..tostring(imgSize)..'x'..tostring(imgSize)..'px'
  --Include a link unless no link -and- no text was requested
  if not (nolink and notext) then result = result..'|link='..link end
  result = result..']]'
 
  --Add Quantity to the front if requested
   if qty ~= nil and qty ~= '' then result = Shared.formatnum(qty)..' '..result end
 
   if not notext then  
   if not notext then  
     result = result..' [['..link
     if nolink then
    if text ~= nil and text ~= '' then
      if text ~= nil and text ~= '' then
      result = result..'|'..text
        result = result..' '..text
      else
        result = result..' '..link
      end
    else
      result = result..' [['..link
      if text ~= nil and text ~= '' and text ~= link then
        result = result..'|'..text
      end
      result = result..']]'
     end
     end
    result = result..']]'
   end
   end
  result = '<span style="display:inline-block">'..result..'</span>'


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


  return result
end
function p._SkillReq(skill, level, showText)
  local result = p.Icon({skill, type='skill', notext='true'})
  if showText then
    result = result..' [['..skill..']]'
  end
  result = result.." Level "..level
  result = '<span style="display:inline-block">'..result..'</span>'
  return result
end
function p.SkillReq(frame)
  local args = frame.args ~= nil and frame.args or frame
  local skill = args[1]
  local level = tonumber(args[2])
  local showText = args.showText ~= nil and args.showText ~= '' and args.showText ~= 'false'
  return p._SkillReq(skill, level, showText)
end
function p._MasteryReq(itemName, level, showText)
  local iconname = itemName
  local linkname = itemName
  --First, go with the lowest tier of potions if a potion is mentioned
  local s, e = string.find(itemName, 'Potion')
  if e ~= nil then
    linkname = string.sub(itemName, 1, e)
    iconname = linkname..' I'
  end
  local result = 'Level '..level..' '
  result = result..p.Icon({linkname, img=iconname, type='item', notext = true})..p.Icon({'Mastery', notext=true})
  if showText  then result = result..'[['..linkname..']] [[Mastery]]' end
  result = '<span style="display:inline-block">'..result..'</span>'
  return result
end
function p.MasteryReq(frame)
  local args = frame.args ~= nil and frame.args or frame
  local itemName = args[1]
  local level = tonumber(args[2])
  local showText = args.showText ~= nil and args.showText ~= '' and args.showText ~= 'false'
  return p._MasteryReq(itemName, level, showText)
end
function p.GP(amt, maxamt)
  local result = '[[File:Coins.svg|25px|link=Coins]]'
  result = result..'&nbsp;'..Shared.formatnum(amt)
  if maxamt ~= nil then result = result..' - '..Shared.formatnum(maxamt) end
  result = '<span style="display:inline-block">'..result..'</span>'
  return result
end
function p.SC(amt, maxamt)
  local result = '[[File:Slayer Coins.svg|25px|link=Currency#Slayer Coins]]'
  result = result..'&nbsp;'..Shared.formatnum(amt)
  if maxamt ~= nil then result = result..' - '..Shared.formatnum(maxamt) end
  result = '<span style="display:inline-block">'..result..'</span>'
   return result
   return result
end
end


return p
return p

Revision as of 21:34, 13 January 2021

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 = {}
--Extension overrides for items that have non-svg images
local extOverrides = {
  ["Crown of Rhaelyx"] = "png",
  ["Jewel of Rhaelyx"] = "png",
  ["Circlet of Rhaelyx"] = "png",
  ["Charge Stone of Rhaelyx"] = "png",
  ["Mysterious Stone"] = "png",
  ["Cloudburst Staff"] = "png",
  ["Earth Layered Shield"] = "png",
  ["Lemon"] = "jpg",
  ["Lemons"] = "jpg",
  ["Lemonade"] = "jpg",
  ["Miolite Sprig"] = "png",
  ["Miolite Trio"] = "png",
  ["Miolite Warden"] = "png",
  ["Miolite Monarch"] = "png",
  ["Wicked Greater Dragon"] = "png",
  ["Hunting Greater Dragon"] = "png",
  ["Chaotic Greater Dragon"] = "png",
  ["Beavis"] = "png",
  ["Pudding Duckie"] = "png",
  ["Pyro"] = "png",
  ["Snek"] = "png",
  ["Larry, the Lonely Lizard"] = "png",
  ["Caaarrrlll"] = "png",
  ["Gronk"] = "png",
  ["Finn, the Cat"] = "png",
  ["Marahute"] = "png",
  ["Monk-ey"] = "png",
  ["Asura"] = "png"
}

--When calling for an icon of type Key, instead use type Value
local typeOverrides = {
  ['combat'] = 'combatArea',
  ['slayer'] = 'combatArea',
}
--When calling for an icon for Key, replace with image Value
local imgOverrides = {
  ['Alt Magic'] = 'Magic',
  ['Alt. Magic'] = 'Magic',
  ['Alternative Magic'] = 'Magic',
  ['Melee'] = 'Combat',
  ['Spider (lv. 51)'] = 'Spider',
  ['Spider (lv. 52)'] = 'Spider2'
}
--When calling for an icon for Key, the link goes to Value
local linkOverrides = {
  ['Alt Magic'] = 'Alternative Magic',
  ['Alt. Magic'] = 'Alternative Magic',
  ['Spider'] = 'Spider (lv. 51)',
  ['Spider2'] = 'Spider (lv. 52)'
}
--If no other text override was specified for the given link, use these
local txtOverrides = {
  ['Spider'] = 'Spider (lv. 51)',
  ['Spider2'] = 'Spider (lv. 52)'
}

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 = args.img ~= nil and args.img or link

  link = string.gsub(link, "%%27", "&apos;")
  link = string.gsub(link, "'", "&apos;")
  link = string.gsub(link, "&#39;", "&apos;")
  img = string.gsub(img, "%%27", "&apos;")
  img = string.gsub(img, "'", "&apos;")
  img = string.gsub(img, "&#39;", "&apos;")

  img = string.gsub(img, '#', '')
  link = string.gsub(link, '#', '')
  --MANUAL OVERRIDES
  if imgOverrides[link] ~= nil and img == link then
    img = imgOverrides[link]
  end
  if text == nil and txtOverrides[link] ~= nil then
    text = txtOverrides[link]
  end
  if linkOverrides[link] ~= nil then
    if text == nil then text = link end
    link = linkOverrides[link]
  end
  if extOverrides[img] ~= nil then 
    ext = extOverrides[img] 
  end
  if typeOverrides[type] ~= nil then
    type = typeOverrides[type]
  end
  --There are a couple specific double overrides I want to include that don't fit in the above lists
  if link == 'Golbin' then
    if text == nil then text = 'Golbin' end
    link = 'Golbin ('..type..')'
  end

  --Creating the image...
  local result = '[[File:'..img
  --Add in type if one is set
  if type ~= nil and type ~= '' then result = result..'_('..type..')' end
  --Add in extension and image size
  result = result..'.'..ext..'|'..tostring(imgSize)..'x'..tostring(imgSize)..'px' 
  --Include a link unless no link -and- no text was requested
  if not (nolink and notext) then result = result..'|link='..link end
  result = result..']]'
  
  --Add Quantity to the front if requested
  if qty ~= nil and qty ~= '' then result = Shared.formatnum(qty)..' '..result 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 ~= '' and text ~= link then
        result = result..'|'..text
      end
      result = result..']]'
    end
  end

  result = '<span style="display:inline-block">'..result..'</span>'

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

  return result
end

function p._SkillReq(skill, level, showText)
  local result = p.Icon({skill, type='skill', notext='true'})
  if showText then
    result = result..' [['..skill..']]'
  end
  result = result.." Level "..level

  result = '<span style="display:inline-block">'..result..'</span>'
  return result
end

function p.SkillReq(frame)
  local args = frame.args ~= nil and frame.args or frame
  local skill = args[1]
  local level = tonumber(args[2])
  local showText = args.showText ~= nil and args.showText ~= '' and args.showText ~= 'false'
  return p._SkillReq(skill, level, showText)
end

function p._MasteryReq(itemName, level, showText)
  local iconname = itemName
  local linkname = itemName
  --First, go with the lowest tier of potions if a potion is mentioned
  local s, e = string.find(itemName, 'Potion')
  if e ~= nil then
    linkname = string.sub(itemName, 1, e)
    iconname = linkname..' I'
  end

  local result = 'Level '..level..' '
  result = result..p.Icon({linkname, img=iconname, type='item', notext = true})..p.Icon({'Mastery', notext=true})
  if showText  then result = result..'[['..linkname..']] [[Mastery]]' end
  result = '<span style="display:inline-block">'..result..'</span>'
  return result
end

function p.MasteryReq(frame)
  local args = frame.args ~= nil and frame.args or frame
  local itemName = args[1]
  local level = tonumber(args[2])
  local showText = args.showText ~= nil and args.showText ~= '' and args.showText ~= 'false'
  return p._MasteryReq(itemName, level, showText)
end

function p.GP(amt, maxamt)
  local result = '[[File:Coins.svg|25px|link=Coins]]'
  result = result..'&nbsp;'..Shared.formatnum(amt)
  if maxamt ~= nil then result = result..' - '..Shared.formatnum(maxamt) end

  result = '<span style="display:inline-block">'..result..'</span>'
  return result
end

function p.SC(amt, maxamt)
  local result = '[[File:Slayer Coins.svg|25px|link=Currency#Slayer Coins]]'
  result = result..'&nbsp;'..Shared.formatnum(amt)
  if maxamt ~= nil then result = result..' - '..Shared.formatnum(maxamt) end

  result = '<span style="display:inline-block">'..result..'</span>'
  return result
end

return p