13,018
edits
(Use tabs instead of spaces for indentation) |
(Icon: Modify link logic to prevent linking to File pages when nolink is specified) |
||
(11 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 232: | Line 235: | ||
["Festive Chio"] = 'png', | ["Festive Chio"] = 'png', | ||
["Festive Cool Rock"] = 'png', | ["Festive Cool Rock"] = 'png', | ||
["Mastery Tokens"] = 'gif' | ["Mastery Tokens"] = 'gif', | ||
["Enchanted Topaz Bolts"] = 'png', | |||
["Enchanted Sapphire Bolts"] = 'png', | |||
["Enchanted Ruby Bolts"] = 'png', | |||
["Enchanted Emerald Bolts"] = 'png', | |||
["Enchanted Diamond Bolts"] = 'png', | |||
["Enchanted Jadestone Bolts"] = 'png', | |||
["Poison Ring"] = 'png', | |||
["Burning Ring"] = 'png', | |||
["Frostburn Ring"] = 'png', | |||
["Ultima Godsword"] = 'png', | |||
["Mystery Wand"] = 'png', | |||
["Poison Arrows"] = 'png', | |||
["Fire Arrows"] = 'png', | |||
["Frostburn Arrows"] = 'png', | |||
["Burning Wand"] = 'png', | |||
["Frostburn Wand"] = 'png', | |||
["Ring of Balance"] = 'png', | |||
["Flying Cape"] = 'png', | |||
["Amulet of Healing"] = 'png', | |||
["Sword of Some Reliability"] = 'png', | |||
["One Layer Shield"] = 'png', | |||
["Warding Shield"] = 'png', | |||
["Tilted Crossbow"] = 'png', | |||
["Ultimate Speed Boots"] = 'png', | |||
["Almighty Ring"] = 'png', | |||
["Punching Bag Platebody"] = 'png', | |||
["Precision Gloves"] = 'png', | |||
["Heavy Gloves"] = 'png', | |||
["Ultimate Slapping Gloves"] = 'png', | |||
["Amulet of Burning Leech"] = 'png', | |||
["Amulet of Poison Leech"] = 'png', | |||
["Magic Critical Amulet"] = 'png', | |||
["Melee Critical Amulet"] = 'png', | |||
["Bloodthirst Amulet"] = 'png', | |||
["Dragon Head Helmet"] = 'png', | |||
["Stonewall Shield"] = 'png', | |||
["Impossible Longbow"] = 'png', | |||
["Throwing Dragon Sword"] = 'png', | |||
["Golbin Crate"] = 'png', | |||
["Bone"] = 'png' | |||
} | } | ||
Line 265: | Line 308: | ||
['Bane, Instrument of Fear'] = 'Bane', | ['Bane, Instrument of Fear'] = 'Bane', | ||
['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 | |||
['Melee Accuracy Potion'] = {'Melee Accuracy Potion I', 'item'}, | |||
['Melee Evasion Potion'] = {'Melee Evasion Potion I', 'item'}, | |||
['Ranged Assistance Potion'] = {'Ranged Assistance Potion I', 'item'}, | |||
['Hinder Potion'] = {'Hinder Potion I', 'item'}, | |||
['Magic Assistance Potion'] = {'Magic Assistance Potion I', 'item'}, | |||
['Regeneration Potion'] = {'Regeneration Potion I', 'item'}, | |||
['Famished Potion'] = {'Famished Potion I', 'item'}, | |||
['Ranged Strength Potion'] = {'Ranged Strength Potion I', 'item'}, | |||
['Lucky Herb Potion'] = {'Lucky Herb Potion I', 'item'}, | |||
['Divine Potion'] = {'Divine Potion I', 'item'}, | |||
['Melee Strength Potion'] = {'Melee Strength Potion I', 'item'}, | |||
['Magic Damage Potion'] = {'Magic Damage Potion I', 'item'}, | |||
['Lethal Toxins Potion'] = {'Lethal Toxins Potion I', 'item'}, | |||
['Diamond Luck Potion'] = {'Diamond Luck Potion I', 'item'}, | |||
['Damage Reduction Potion'] = {'Damage Reduction Potion I', 'item'}, | |||
['Bird Nest Potion'] = {'Bird Nest Potion I', 'item'}, | |||
['Controlled Heat Potion'] = {'Controlled Heat Potion I', 'item'}, | |||
['Generous Cook Potion'] = {'Generous Cook Potion I', 'item'}, | |||
['Fishermans Potion'] = {'Fishermans Potion I', 'item'}, | |||
['Skilled Fletching Potion'] = {'Skilled Fletching Potion I', 'item'}, | |||
['Gentle Hands Potion'] = {'Gentle Hands Potion I', 'item'}, | |||
['Secret Stardust Potion'] = {'Secret Stardust Potion I', 'item'}, | |||
['Crafting Potion'] = {'Crafting Potion I', 'item'}, | |||
['Perfect Swing Potion'] = {'Perfect Swing Potion I', 'item'}, | |||
['Necromancer Potion'] = {'Necromancer Potion I', 'item'}, | |||
['Performance Enhancing Potion'] = {'Performance Enhancing Potion I', 'item'}, | |||
['Elemental Potion'] = {'Elemental Potion I', 'item'}, | |||
['Herblore Potion'] = {'Herblore 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 289: | 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 305: | 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 444: | 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 | ||