17,101
edits
m (Added a missing potion override) |
(Icon: Optimize, reduces runtime by ~30%) |
||
Line 3: | Line 3: | ||
local Shared = require("Module:Shared") | local Shared = require("Module:Shared") | ||
-- Locally index some functions for performance | |||
local sgsub, sformat, fixPagename, formatnum, tostring, type = string.gsub, string.format, Shared.fixPagename, Shared.formatnum, tostring, type | |||
local p = {} | local p = {} | ||
Line 360: | Line 363: | ||
} | } | ||
--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 376: | Line 385: | ||
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 ovrTypeExt = typeExtOverrides[iconType] | ||
elseif type( | if ovrTypeExt ~= nil then | ||
ovrTypeExt = ovrTypeExt[img] | |||
end | |||
local ovrExt = extOverrides[img] | |||
local ovrType = typeOverrides[iconType] | |||
local hasText = (text ~= nil and text ~= '') | |||
if ovrImg ~= nil and img == link then | |||
if type(ovrImg) == 'string' then | |||
img = ovrImg | |||
elseif type(ovrImg) == 'table' then | |||
img = ovr[1] | img = ovr[1] | ||
if ovr[2] ~= nil then iconType = ovr[2] end | if ovr[2] ~= nil then iconType = ovr[2] end | ||
end | end | ||
end | end | ||
if | if not hasText and ovrTxt ~= nil then | ||
text = | text = ovrTxt | ||
end | end | ||
if | if ovrLink ~= nil then | ||
if | if not hasText then text = link end | ||
link = | 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 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 = (nolink and notext and '' or '|link=' .. 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 515: | Line 522: | ||
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 | ||