Module:ModifierTables: Difference between revisions

getModifierTable: support 'maxOtherMods' argument
mNo edit summary
(getModifierTable: support 'maxOtherMods' argument)
Line 175: Line 175:
end
end


function p._getModifierTable(modifiers, skill, columnName, getOpposites, displayOtherMods)
function p._getModifierTable(modifiers, skill, columnName, getOpposites, displayOtherMods, maxOtherMods)
   local modifierNames = {}
   local modifierNames = {}
   if type(modifiers) == 'string' then
   if type(modifiers) == 'string' then
Line 200: Line 200:
   local getModText =  
   local getModText =  
     function(modifiers)
     function(modifiers)
       local modTextArray = {}
       local modTextArray = { ["visible"] = {}, ["overflow"] = {} }
      local otherModCount = 0
       local mainModText = {}
       local mainModText = {}
       for modName, modValue in Shared.skpairs(modifiers) do
       for modName, modValue in Shared.skpairs(modifiers) do
Line 209: Line 210:
                 table.insert(mainModText, Constants._getModifierText(modName, subVal))
                 table.insert(mainModText, Constants._getModifierText(modName, subVal))
               else
               else
                 table.insert(modTextArray, Constants._getModifierText(modName, subVal))
              otherModCount = otherModCount + 1
              local key = ((maxOtherMods == nil or otherModCount < maxOtherMods) and 'visible') or 'overflow'
                 table.insert(modTextArray[key], Constants._getModifierText(modName, subVal))
               end
               end
             end
             end
Line 216: Line 219:
           end
           end
         else
         else
           table.insert(modTextArray, 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, modValue))
         end
         end
       end
       end


      return table.concat(mainModText, '<br/>'), table.concat(modTextArray, '<br/>')
  local otherModText = {table.concat(modTextArray['visible'], '<br/>')}
  local overflowModCount = Shared.tableCount(modTextArray['overflow'])
  mw.logObject(modTextArray['overflow'])
  if overflowModCount > 0 then
  -- Number of other modifiers for the object exceed the specified maximum
  table.insert(otherModText, '<br/><span style="float:left;margin-left:0;margin-right:1em" class="mw-collapsible mw-collapsed" ')
  table.insert(otherModText, 'data-expandtext="Show ' .. Shared.formatnum(overflowModCount) .. ' more modifiers", data-collapsetext="Hide">')
  table.insert(otherModText, table.concat(modTextArray['overflow'], '<br/>') .. '</span>')
  end
      return table.concat(mainModText, '<br/>'), table.concat(otherModText)
     end
     end


Line 230: Line 244:
     row.name = item.name
     row.name = item.name
     row.icon = Icons.Icon({item.name, type='item'})
     row.icon = Icons.Icon({item.name, type='item'})
     row.type = 'Item'--For equipment, show the slot they go in
     row.type = 'Item'
     --For equipment, show the slot they go in
     --For equipment, show the slot they go in
if item.validSlots ~= nil then
if item.validSlots ~= nil then
Line 378: Line 392:
     result = result..'||'..row.type..'||data-sort-value="'..row.val..'"|'..row.modifierText
     result = result..'||'..row.type..'||data-sort-value="'..row.val..'"|'..row.modifierText
     if hasOtherModifiers and displayOtherMods then
     if hasOtherModifiers and displayOtherMods then
    local _, nummodifier = string.gsub(row.otherModifiers, '<br>', '<br>')
      result = result..'||'..row.otherModifiers
    local nummodifiers = string.len(row.otherModifiers)
    mw.log(row.otherModifiers)
    if nummodifiers < 5 then
    result = result..'||'..nummodifiers..' modifiers: '..row.otherModifiers
    else
    result = result..'|| many modifiers'
    end
     end
     end
   end
   end
Line 399: Line 406:
   local getOpposites = frame.args ~= nil and frame.args[3] or frame[3]
   local getOpposites = frame.args ~= nil and frame.args[3] or frame[3]
   local displayOtherMods = frame.args ~= nil and frame.args.displayOtherMods or frame.displayOtherMods
   local displayOtherMods = frame.args ~= nil and frame.args.displayOtherMods or frame.displayOtherMods
  local maxOtherMods = frame.args ~= nil and tonumber(frame.args.maxOtherMods)


   if Shared.contains(modifier, ',') then
   if Shared.contains(modifier, ',') then
Line 416: Line 424:
   end
   end
    
    
   return p._getModifierTable(modifier, skill, columnName, getOpposites, displayOtherMods)
   return p._getModifierTable(modifier, skill, columnName, getOpposites, displayOtherMods, maxOtherMods)
end
end


return p
return p