Anonymous

Module:Icons: Difference between revisions

From Melvor Idle
1,236 bytes added ,  27 November 2022
Amend/fix overrides for Summoning marks
(Add overrides for new v1.1 potions)
(Amend/fix overrides for Summoning marks)
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
--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 Shared = require("Module:Shared")
local Shared = require("Module:Shared")
local GameData = require("Module:GameData")


-- Locally index some functions for performance
-- Locally index some functions for performance
Line 24: Line 22:
["rock"] = "svg", -- Some exceptions included by name below
["rock"] = "svg", -- Some exceptions included by name below
["thieving"] = "svg",
["thieving"] = "svg",
["mark"] = "svg", -- Some exceptions included by name below
["constellation"] = "svg",
["constellation"] = "svg",
["building"] = "svg",
["building"] = "svg",
Line 66: Line 63:
["Event Clue 3"] = "svg",
["Event Clue 3"] = "svg",
["Event Clue 4"] = "svg",
["Event Clue 4"] = "svg",
["Golbin Thief"] = "svg",
["Occultist"] = "svg",
["Wolf"] = "svg",
["Ent"] = "svg",
["Mole"] = "svg",
["Octopus"] = "svg",
["Minotaur"] = "svg",
["Centaur"] = "svg",
["Witch"] = "svg",
["Pig"] = "svg",
["Crow"] = "svg",
["Leprechaun"] = "svg",
["Cyclops"] = "svg",
["Yak"] = "svg",
["Unicorn"] = "svg",
["Dragon"] = "svg",
["Monkey"] = "svg",
["Salamander"] = "svg",
["Bear"] = "svg",
["Devil"] = "svg",
-- Pets
-- Pets
["Cris"] = "svg",
["Cris"] = "svg",
Line 171: Line 148:
local typeExtOverrides = {
local typeExtOverrides = {
-- Example: ["item"] = { ["Chicken"] = "png" }
-- Example: ["item"] = { ["Chicken"] = "png" }
["item"] = {
-- These familiars also exist as type mark, where the image is of PNG format
["Golbin Thief"] = "svg",
["Occultist"] = "svg",
["Wolf"] = "svg",
["Ent"] = "svg",
["Mole"] = "svg",
["Octopus"] = "svg",
["Minotaur"] = "svg",
["Centaur"] = "svg",
["Witch"] = "svg",
["Pig"] = "svg",
["Crow"] = "svg",
["Leprechaun"] = "svg",
["Cyclops"] = "svg",
["Yak"] = "svg",
["Unicorn"] = "svg",
["Dragon"] = "svg",
["Monkey"] = "svg",
["Salamander"] = "svg",
["Bear"] = "svg",
["Devil"] = "svg"
}
}
}


Line 312: Line 312:
['Spider2'] = 'Brown Spider'
['Spider2'] = 'Brown Spider'
}
}
--When calling for an icon for Key + Type, the link goes to Value
local typeLinkOverrides = {
['resource'] = {
-- Township resources
['Food'] = '',
['Wood'] = '',
['Planks'] = '',
['Stone'] = '',
['Bar'] = '',
['Ore'] = '',
['Coal'] = '',
['Rune Essence'] = '',
['Herbs'] = '',
['Potions'] = '',
['Leather'] = '',
['Clothing'] = ''
},
['township'] = {
['Workers'] = '',
['Statistics'] = '',
['Town'] = ''
}
}
--If no other text override was specified for the given link, use these
--If no other text override was specified for the given link, use these
local txtOverrides = {
local txtOverrides = {
Line 354: Line 378:
local img = args.img ~= nil and args.img ~= '' and args.img or link
local img = args.img ~= nil and args.img ~= '' and args.img or link
local class = args.class ~= nil and args.class ~= '' and args.class or ''
local class = args.class ~= nil and args.class ~= '' and args.class or ''
local altText = args.alt ~= nil and args.alt or (notext and (text or link)) or ''
local nospan = args.nospan ~= nil and args.nospan


link = fixPagename(link)
link = fixPagename(link)
Line 371: Line 397:
local ovrTxt = txtOverrides[link]
local ovrTxt = txtOverrides[link]
local ovrLink = linkOverrides[link]
local ovrLink = linkOverrides[link]
local ovrTypeLink = typeLinkOverrides[iconType]
if ovrTypeLink ~= nil and ovrTypeLink[img] ~= nil then
if ovrTypeLink[img] == '' then
nolink = true
else
ovrLink = ovrTypeLink[img]
end
end
local hasText = (text ~= nil and text ~= '')
local hasText = (text ~= nil and text ~= '')
if ovrImg ~= nil and img == link then
if ovrImg ~= nil and img == link then
Line 430: Line 464:
local txtImg = (iconType ~= nil and iconType ~= '' and img .. '_(' .. iconType .. ')' or img) .. '.' .. ext
local txtImg = (iconType ~= nil and iconType ~= '' and img .. '_(' .. iconType .. ')' or img) .. '.' .. ext
-- Include a link unless no link -and- no text was requested
-- Include a link unless no link -and- no text was requested
local txtLink = '|link=' .. (nolink and notext and '' or link)
local txtLink = '|link=' .. (nolink and '' or link)
resultText = '[[File:' .. txtImg .. '|' .. txtSize .. 'x' .. txtSize .. 'px' .. txtLink .. ']]'
resultText = '[[File:' .. txtImg .. '|' .. txtSize .. 'x' .. txtSize .. 'px|alt=' .. altText .. txtLink .. ']]'
if class ~= nil and class ~= '' then
if class ~= nil and class ~= '' then
resultText = '<span class="'..class..'">'..resultText..'</span>'
resultText = '<span class="'..class..'">'..resultText..'</span>'
Line 453: Line 487:
if menu then
if menu then
return '{| class="articletable" style="display:inline-block;vertical-align:middle;"\r\n|-\r\n|' .. resultText .. '\r\n|}'
return '{| class="articletable" style="display:inline-block;vertical-align:middle;"\r\n|-\r\n|' .. resultText .. '\r\n|}'
elseif not noicon then
elseif not noicon and not nospan then
return '<span style="display:inline-block">' .. resultText .. '</span>'
return '<span style="display:inline-block">' .. resultText .. '</span>'
else
else
Line 468: Line 502:


function p._SkillReq(skill, level, showText)
function p._SkillReq(skill, level, showText)
local result = p.Icon({skill, type='skill', notext='true'})
local altText = (showText and '') or skill
if showText then
local result = p.Icon({skill, type='skill', notext=(showText and '' or true), nospan=true, alt=altText})
result = result..' [['..skill..']]'
end
if level == nil then level = 'Unknown [[Category:Pages with script errors]]' end
if level == nil then level = 'Unknown [[Category:Pages with script errors]]' end
result = result.." Level "..level
result = result.." Level "..level
Line 496: Line 528:
iconname = linkname..' I'
iconname = linkname..' I'
end
end
local altTextItem = (showText and '') or linkname
local altTextMastery = (showText and '') or '&nbsp;Mastery'


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


function p._Currency(fileName, link, amt, maxAmt)
function p._Currency(fileName, link, altText, amt, maxAmt)
local amtText = formatnum(amt)
local amtText = formatnum(amt)
if maxAmt ~= nil and maxAmt >= amt then
if maxAmt ~= nil and maxAmt >= amt then
Line 524: Line 558:
fileText = fileText .. '|link=' .. link
fileText = fileText .. '|link=' .. link
end
end
fileText = fileText .. ']]&nbsp;'
fileText = fileText .. '|alt=' .. ((altText == nil and '') or altText) .. ']]&nbsp;'
end
end


Line 531: Line 565:


function p.GP(amt, maxamt)
function p.GP(amt, maxamt)
return p._Currency('Coins.svg', 'Coins', amt, maxamt)
return p._Currency('Coins.svg', 'Coins', 'GP', amt, maxamt)
end
end


function p.SC(amt, maxamt)
function p.SC(amt, maxamt)
return p._Currency('Slayer Coins.svg', 'Currency#Slayer Coins', amt, maxamt)
return p._Currency('Slayer Coins.svg', 'Currency#Slayer Coins', 'SC', amt, maxamt)
end
end


function p.RC(amt, maxamt)
function p.RC(amt, maxamt)
return p._Currency('Raid_Coins.svg', 'Currency#Raid Coins', amt, maxamt)
return p._Currency('Raid_Coins.svg', 'Currency#Raid Coins', 'RC', amt, maxamt)
end
 
--Adding a shortcut function for this
function p.TotH()
return p.Icon({'Throne of the Herald Expansion', ext='svg', notext=true, img='TotH'})
end
 
function p.getExpansionIcon(id)
local ns, _ = GameData.getLocalID(id)
if ns == 'melvorTotH' then
return p.TotH()..' '
else
return ''
end
end
end


return p
return p