16,254
edits
Falterfire (talk | contribs) (more wording updates) |
(getModifiersText: Support for maxVisible parameter) |
||
Line 868: | Line 868: | ||
end | end | ||
function p.getModifiersText(modifiers, doColor, inline) | function p.getModifiersText(modifiers, doColor, inline, maxVisible) | ||
if inline == nil then inline = false end | if inline == nil then inline = false end | ||
if type(maxVisible) ~= 'number' then maxVisible = nil end | |||
if modifiers == nil or Shared.tableIsEmpty(modifiers) then | if modifiers == nil or Shared.tableIsEmpty(modifiers) then | ||
return '' | return '' | ||
end | end | ||
local modArray = {} | local modArray = { ["visible"] = {}, ["overflow"] = {} } | ||
local modCount = { ["visible"] = 0, ["overflow"] = 0 } | |||
local insertKey = 'visible' | |||
for bonus, value in pairs(modifiers) do | for bonus, value in pairs(modifiers) do | ||
table.insert(modArray, p._getModifierText(bonus, | -- If there is a single by skill modifier with multiple values, this will | ||
-- appear as multiple rows. Split these so the number of visible lines is | |||
-- always accurate | |||
local valueArray = nil | |||
if type(value) == 'table' then | |||
valueArray = value | |||
else | |||
valueArray = {value} | |||
end | |||
for i, subVal in ipairs(valueArray) do | |||
if type(subVal) == 'table' and subVal.skillID ~= nil then | |||
subVal = {subVal} | |||
end | |||
if maxVisible ~= nil and not inline and insertKey == 'visible' and modCount[insertKey] >= maxVisible then | |||
insertKey = 'overflow' | |||
end | |||
table.insert(modArray[insertKey], p._getModifierText(bonus, subVal, doColor)) | |||
modCount[insertKey] = modCount[insertKey] + 1 | |||
end | |||
end | end | ||
if inline then | if inline then | ||
return table.concat(modArray, | return table.concat(modArray['visible'], ' and ') | ||
else | else | ||
return table.concat(modArray, | if modCount['overflow'] == 1 then | ||
table.insert(modArray['visible'], modArray['overflow'][1]) | |||
end | |||
local overflowText = '' | |||
if modCount['overflow'] > 1 then | |||
-- Number of other modifiers has exceeded the specified maximum | |||
overflowText = table.concat({ | |||
'<br/><span class="mw-collapsible mw-collapsed" ', | |||
'data-expandtext="Show ' .. Shared.formatnum(modCount['overflow']) .. ' more modifiers" ', | |||
'data-collapsetext="Hide">', | |||
table.concat(modArray['overflow'], '<br/>'), | |||
'</span>' | |||
}) | |||
end | |||
return table.concat(modArray['visible'], '<br/>') .. overflowText | |||
end | end | ||
end | end |