Module:Icons: Difference between revisions
From Melvor Idle
Falterfire (talk | contribs) (Added MasteryReq function) |
Falterfire (talk | contribs) (fixed issue) |
||
Line 88: | Line 88: | ||
function p._SkillReq(skill, level, showText) | function p._SkillReq(skill, level, showText) | ||
local result = | local result = p.Icon({skill, type='skill', notext='true'}) | ||
if showText then | if showText then | ||
result = result..' [['..skill..']]' | result = result..' [['..skill..']]' |
Revision as of 19:06, 1 October 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 = {}
--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",
["Aeris Godsword"] = "png",
["Ragnar Godsword"] = "png",
["Terran Godsword"] = "png",
["Glacia Godsword"] = "png",
["Cloudburst Staff"] = "png",
["Earth Layered Shield"] = "png",
}
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
--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)'
elseif link == 'Alt. Magic' or link == 'Alternative Magic' or link == 'Alt Magic' then
text = link
img = 'Magic'
link = 'Alternative Magic'
type = 'skill'
end
if extOverrides[img] ~= nil then ext = extOverrides[img] end
local result = '[[File:'..img
if type ~= nil and type ~= '' then result = result..'_('..type..')' end
result = result..'.'..ext..'|'..tostring(imgSize)..'x'..tostring(imgSize)..'px'
if not (nolink and notext) then result = result..'|link='..link end
result = result..']]'
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 ~= '' 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..' '..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..' '..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