Module:ModifierTables: Difference between revisions

_getModifierTable: Correct issues with incorrect other modifier count & incorrect number of visible modifiers; change sort order
(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 Shared.skpairs(modValue) do
             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))
              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})
          local key = ((maxOtherMods == nil or otherModCount < maxOtherMods) and 'visible') or 'overflow'
          for j, subValue in ipairs(modValue) do
          table.insert(modTextArray[key], Constants._getModifierText(modName, modValue))
            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'])
  mw.logObject(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
   if modifierCount == 1 then
   table.sort(tableArray, function(a, b)
    table.sort(tableArray, function(a, b)
                          if modifierCount == 1 and a.val ~= b.val then
                            if a.val ~= b.val then
                            return a.val > b.val
                              return a.val > b.val
                          elseif a.type ~= b.type then
                            elseif a.name ~= b.name then
                             return a.type < b.type
                              return a.name < b.name
                           else
                             else
                            return a.name < b.name
                              return a.type < b.type
                          end
                            end
                        end)
                           end)
  else
    table.sort(tableArray, function(a, b) 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|-'