Anonymous

Module:Icons: Difference between revisions

From Melvor Idle
Icon: Modify link logic to prevent linking to File pages when nolink is specified
m (Fix error)
(Icon: Modify link logic to prevent linking to File pages when nolink is specified)
(4 intermediate revisions by the same user not shown)
Line 5: Line 5:


-- Locally index some functions for performance
-- Locally index some functions for performance
local sgsub, sformat, fixPagename, formatnum, tostring, type = string.gsub, string.format, Shared.fixPagename, Shared.formatnum, tostring, type
local sgsub, fixPagename, formatnum, tostring, type = string.gsub, Shared.fixPagename, Shared.formatnum, tostring, type


local p = {}
local p = {}
Line 274: 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 397: Line 398:
local ovrTxt = txtOverrides[link]
local ovrTxt = txtOverrides[link]
local ovrLink = linkOverrides[link]
local ovrLink = linkOverrides[link]
local ovrTypeExt = typeExtOverrides[iconType]
if ovrTypeExt ~= nil then
ovrTypeExt = ovrTypeExt[img]
end
local ovrExt = extOverrides[img]
local ovrType = typeOverrides[iconType]
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 412: Line 407:
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
local ovrExt = extOverrides[img]
local ovrType = typeOverrides[iconType]
if not hasText and ovrTxt ~= nil then
if not hasText and ovrTxt ~= nil then
text = ovrTxt
text = ovrTxt
hasText = true
end
end
if ovrLink ~= nil then
if ovrLink ~= nil then
if not hasText then text = link end
if not hasText then
text = link
hasText = true
end
link = ovrLink
link = ovrLink
end
end
Line 431: Line 438:
-- There are a couple specific double overrides to be included that don't fit in the above lists
-- There are a couple specific double overrides to be included that don't fit in the above lists
if ambiguousOverrides[link] then
if ambiguousOverrides[link] then
if not hasText then text = link end
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
Line 442: Line 452:
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 = (nolink and notext and '' or '|link=' .. link)
local txtLink = '|link=' .. (nolink and notext and '' or link)
resultText = '[[File:' .. txtImg .. '|' .. txtSize .. 'x' .. txtSize .. 'px' .. txtLink .. ']]'
resultText = '[[File:' .. txtImg .. '|' .. txtSize .. 'x' .. txtSize .. 'px' .. txtLink .. ']]'
end
end