12,868
edits
(Add image overrides for ease of linking to generic potion pages) |
(Icon: Modify link logic to prevent linking to File pages when nolink is specified) |
||
(8 intermediate revisions by 2 users not shown) | |||
Line 3: | Line 3: | ||
local Shared = require("Module:Shared") | local Shared = require("Module:Shared") | ||
-- Locally index some functions for performance | |||
local sgsub, fixPagename, formatnum, tostring, type = string.gsub, Shared.fixPagename, Shared.formatnum, tostring, type | |||
local p = {} | local p = {} | ||
Line 271: | Line 274: | ||
["Impossible Longbow"] = 'png', | ["Impossible Longbow"] = 'png', | ||
["Throwing Dragon Sword"] = 'png', | ["Throwing Dragon Sword"] = 'png', | ||
["Golbin Crate"] = 'png' | ["Golbin Crate"] = 'png', | ||
["Bone"] = 'png' | |||
} | } | ||
Line 305: | Line 309: | ||
['Mastery Token Astrology'] = 'Mastery Token (Astrology)', | ['Mastery Token Astrology'] = 'Mastery Token (Astrology)', | ||
['Event Token - Holiday 2021'] = 'Christmas Present (Yellow)', | ['Event Token - Holiday 2021'] = 'Christmas Present (Yellow)', | ||
["I Can't See Helmet"] = {'Golbin', 'monster'}, | |||
-- Overrides that allow generic potion pages to be linked to easily | -- Overrides that allow generic potion pages to be linked to easily | ||
['Melee Accuracy Potion'] = {'Melee Accuracy Potion I', 'item'}, | ['Melee Accuracy Potion'] = {'Melee Accuracy Potion I', 'item'}, | ||
Line 334: | Line 339: | ||
['Elemental Potion'] = {'Elemental Potion I', 'item'}, | ['Elemental Potion'] = {'Elemental Potion I', 'item'}, | ||
['Herblore Potion'] = {'Herblore Potion I', 'item'}, | ['Herblore Potion'] = {'Herblore Potion I', 'item'}, | ||
['Generous Harvest Potion'] = {'Generous Harvest Potion I', 'item'} | ['Generous Harvest Potion'] = {'Generous Harvest Potion I', 'item'}, | ||
['Seeing Gold Potion'] = {'Seeing Gold Potion I', 'item'} | |||
} | } | ||
--When calling for an icon for Key, the link goes to Value | --When calling for an icon for Key, the link goes to Value | ||
Line 358: | Line 364: | ||
} | } | ||
--Ambiguous overrides section | --Ambiguous overrides section | ||
local ambiguousOverrides = {'Golbin', 'Chick', 'Chicken', 'Cyclops', 'Wizard'} | local ambiguousOverrides = { | ||
['Golbin'] = true, | |||
['Chick'] = true, | |||
['Chicken'] = true, | |||
['Cyclops'] = true, | |||
['Wizard'] = true | |||
} | |||
function p.Icon(frame) | function p.Icon(frame) | ||
Line 374: | Line 386: | ||
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 | ||
link = | link = fixPagename(link) | ||
img = | img = fixPagename(img) | ||
img = sgsub(img, '#', '') | |||
img = sgsub(img, '/Training', '') | |||
img = sgsub(img, '/Guide', '') | |||
link = sgsub(link, '#', '') | |||
--MANUAL OVERRIDES | --MANUAL OVERRIDES | ||
local ovrImg = imgOverrides[link] | |||
local ovrTxt = txtOverrides[link] | |||
if type( | local ovrLink = linkOverrides[link] | ||
img = | local hasText = (text ~= nil and text ~= '') | ||
elseif type( | if ovrImg ~= nil and img == link then | ||
img = | if type(ovrImg) == 'string' then | ||
if | img = ovrImg | ||
elseif type(ovrImg) == 'table' then | |||
img = ovrImg[1] | |||
if ovrImg[2] ~= nil then iconType = ovrImg[2] end | |||
end | end | ||
end | end | ||
-- Type & extension overrides must be after adjustments have been made | |||
-- for any image overrides | |||
local ovrTypeExt = typeExtOverrides[iconType] | |||
if ovrTypeExt ~= nil then | |||
ovrTypeExt = ovrTypeExt[img] | |||
end | end | ||
local ovrExt = extOverrides[img] | |||
local ovrType = typeOverrides[iconType] | |||
link = | if not hasText and ovrTxt ~= nil then | ||
text = ovrTxt | |||
hasText = true | |||
end | |||
if ovrLink ~= nil then | |||
if not hasText then | |||
text = link | |||
hasText = true | |||
end | |||
link = ovrLink | |||
end | end | ||
if | if ovrTypeExt ~= nil then | ||
ext = | ext = ovrTypeExt | ||
elseif | elseif ovrExt ~= nil then | ||
ext = | ext = ovrExt | ||
elseif iconType == 'mark' then | elseif iconType == 'mark' then | ||
ext = 'png' | ext = 'png' | ||
end | end | ||
if | if ovrType ~= nil then | ||
iconType = | iconType = ovrType | ||
end | end | ||
--There are a couple specific double overrides | -- There are a couple specific double overrides to be included that don't fit in the above lists | ||
if | if ambiguousOverrides[link] then | ||
if | if not hasText then | ||
text = link | |||
hasText = true | |||
end | |||
link = link..' ('..(iconType == 'mark' and 'item' or iconType)..')' | link = link..' ('..(iconType == 'mark' and 'item' or iconType)..')' | ||
end | end | ||
local | local resultText = '' | ||
if not noicon then | if not noicon then | ||
-- | -- Image size | ||
local txtSize = tostring(imgSize) | |||
-- | -- Extension and type if one is set | ||
local txtImg = (iconType ~= nil and iconType ~= '' and img .. '_(' .. iconType .. ')' or img) .. '.' .. ext | |||
-- Include a link unless no link -and- no text was requested | |||
local txtLink = '|link=' .. (nolink and notext and '' or link) | |||
--Include a link unless no link -and- no text was requested | resultText = '[[File:' .. txtImg .. '|' .. txtSize .. 'x' .. txtSize .. 'px' .. txtLink .. ']]' | ||
end | end | ||
if not notext then | if not notext then | ||
if nolink then | if nolink then | ||
resultText = resultText .. (noicon and '' or ' ') .. (hasText and text or link) | |||
else | else | ||
resultText = resultText .. (noicon and '' or ' ') .. '[[' .. link .. (hasText and text ~= link and '|' .. text or '') .. ']]' | |||
end | end | ||
end | end | ||
if | -- Add Quantity to the front if requested | ||
--local resultQty = (qty ~= nil and qty ~= '' and formatnum(qty) .. ' ' or '') | |||
if qty ~= nil and qty ~= '' then | |||
resultText = formatnum(qty) .. ' ' .. resultText | |||
end | end | ||
if menu then | if menu then | ||
return '{| class="articletable" style="display:inline-block;vertical-align:middle;"\r\n|-\r\n|' .. resultText .. '\r\n|}' | |||
elseif not noicon then | |||
return '<span style="display:inline-block">' .. resultText .. '</span>' | |||
else | |||
return resultText | |||
end | end | ||
end | end | ||
Line 513: | Line 532: | ||
function p._Currency(fileName, link, amt, maxAmt) | function p._Currency(fileName, link, amt, maxAmt) | ||
local amtText = | local amtText = formatnum(amt) | ||
if maxAmt ~= nil and maxAmt >= amt then | if maxAmt ~= nil and maxAmt >= amt then | ||
amtText = amtText .. ' - ' . | amtText = amtText .. ' - ' .. formatnum(maxAmt) | ||
end | end | ||