Anonymous

Module:Navboxes: Difference between revisions

From Melvor Idle
getPotionNavbox: Ensure potions sorted by Herblore level requirement & remove 'Potion' name prefix for cleaner appearance
(getPrayerNavbox/getSpellNavbox: Order prayers/spells by level, in line with in-game appearance)
(getPotionNavbox: Ensure potions sorted by Herblore level requirement & remove 'Potion' name prefix for cleaner appearance)
Line 162: Line 162:


function p.getPotionNavbox(frame)
function p.getPotionNavbox(frame)
   local result = '{| class="wikitable" style="margin:auto; clear:both; width: 100%"'
   local catList = {
  result = result..'\r\n!colspan=2|'..Icons.Icon({'Herblore', 'Potions', type='skill'})
    { ["categoryID"] = 0, ["name"] = 'Combat' },
    { ["categoryID"] = 1, ["name"] = 'Skill' }
  }
  table.sort(catList, function(a, b) return a.name < b.name end)


   local CombatPots = {}
   -- Compile list of potions to be included
   local SkillPots = {}
   local potList = {}
   for i, potData in Shared.skpairs(SkillData.Herblore.ItemData) do
   for i, potData in ipairs(SkillData.Herblore.ItemData) do
     if potData.category == 0 then
     if potList[potData.category] == nil then
       table.insert(CombatPots, Icons.Icon({potData.name, type='item', img=(potData.name..' I')}))
       potList[potData.category] = {}
    else
      if potData.name == 'Bird Nests Potion' then
        table.insert(SkillPots, Icons.Icon({"Bird Nest Potion", type='item', img="Bird Nest Potion I"}))
      else
        table.insert(SkillPots, Icons.Icon({potData.name, type='item', img=(potData.name..' I')}))
      end
     end
     end
    local potFirstItem = Items.getItemByID(potData.itemID[1])
    local potName = string.gsub(potFirstItem.name, ' Potion [IV]+$', '')
    table.insert(potList[potData.category], { ["name"] = potName, ["order"] = potData.level, ["img"] = potFirstItem.name })
   end
   end


   result = result..'\r\n|-\r\n!Combat Potions\r\n|class="center" style="vertical-align:middle;"'
   local resultPart = {}
   result = result..'|'..table.concat(CombatPots, ' ')
  -- Generate table header
   result = result..'\r\n|-\r\n!Skill Potions\r\n|class="center" style="vertical-align:middle;"'
  table.insert(resultPart, '{| class="wikitable" style="margin:auto; clear:both; width: 100%"')
  result = result..'|'..table.concat(SkillPots, ' • ')
   table.insert(resultPart, '\r\n!colspan=2|' .. Icons.Icon({ 'Herblore', 'Potions', type='skill' }))
   result = result..'\r\n|}'
  -- Generate section for each category of potions
   return result
   for i, catData in ipairs(catList) do
    -- Compile list of potions
    local potListText = {}
    table.sort(potList[catData.categoryID], function(a, b) return (a.order == b.order and a.name < b.name) or a.order < b.order end)
    for j, potData in ipairs(potList[catData.categoryID]) do
      table.insert(potListText, Icons.Icon({ potData.img, potData.name, type='item' }))
    end
    table.insert(resultPart, '\r\n|-\r\n! ' .. catData.name .. ' Potions')
    table.insert(resultPart, '\r\n|class="center" style="vertical-align:middle;"| ' .. table.concat(potListText, ' • '))
  end
   table.insert(resultPart, '\r\n|}')
 
   return table.concat(resultPart)
end
end