12,787
edits
(getModifierTable: support 'maxOtherMods' argument) |
(_getModifierTable: Correct issues with incorrect other modifier count & incorrect number of visible modifiers; change sort order) |
||
Line 206: | Line 206: | ||
if Shared.contains(modifierNames, modName) then | if Shared.contains(modifierNames, modName) then | ||
if type(modValue) == 'table' then | if type(modValue) == 'table' then | ||
for j, subVal in | for j, subVal in ipairs(modValue) do | ||
if subVal[1] == skill or skill == nil or skill == '' then | if subVal[1] == skill or skill == nil or skill == '' then | ||
table.insert(mainModText, Constants._getModifierText(modName, subVal)) | table.insert(mainModText, Constants._getModifierText(modName, subVal)) | ||
else | else | ||
otherModCount = otherModCount + 1 | otherModCount = otherModCount + 1 | ||
local key = ((maxOtherMods == nil or otherModCount < maxOtherMods) and 'visible') or 'overflow' | local key = ((maxOtherMods == nil or otherModCount <= maxOtherMods) and 'visible') or 'overflow' | ||
table.insert(modTextArray[key], Constants._getModifierText(modName, subVal)) | |||
end | end | ||
end | end | ||
Line 219: | Line 219: | ||
end | end | ||
else | else | ||
otherModCount = otherModCount + 1 | modValue = (type(modValue) == 'table' and modValue or {modValue}) | ||
for j, subValue in ipairs(modValue) do | |||
otherModCount = otherModCount + 1 | |||
local key = ((maxOtherMods == nil or otherModCount <= maxOtherMods) and 'visible') or 'overflow' | |||
table.insert(modTextArray[key], Constants._getModifierText(modName, subValue)) | |||
end | |||
end | end | ||
end | end | ||
Line 227: | Line 230: | ||
local otherModText = {table.concat(modTextArray['visible'], '<br/>')} | local otherModText = {table.concat(modTextArray['visible'], '<br/>')} | ||
local overflowModCount = Shared.tableCount(modTextArray['overflow']) | local overflowModCount = Shared.tableCount(modTextArray['overflow']) | ||
if overflowModCount > 0 then | if overflowModCount > 0 then | ||
-- Number of other modifiers for the object exceed the specified maximum | -- Number of other modifiers for the object exceed the specified maximum | ||
Line 373: | Line 375: | ||
--Sort by value if only one modifier was passed in | --Sort by value if only one modifier was passed in | ||
--Otherwise sort alphabetically by name | --Otherwise sort alphabetically by type, then name | ||
table.sort(tableArray, function(a, b) | |||
if modifierCount == 1 and a.val ~= b.val then | |||
return a.val > b.val | |||
elseif a.type ~= b.type then | |||
return a.type < b.type | |||
else | |||
return a.name < b.name | |||
end | |||
end) | |||
for i, row in Shared.skpairs(tableArray) do | for i, row in Shared.skpairs(tableArray) do | ||
result = result..'\r\n|-' | result = result..'\r\n|-' |