Module:Navboxes: Difference between revisions

getFoodNavbox: Revise implementation to include all current and hopefully all future food
(getThievingNavbox: Move from Module:Skills)
(getFoodNavbox: Revise implementation to include all current and hopefully all future food)
Line 58: Line 58:


function p.getFoodNavbox(frame)
function p.getFoodNavbox(frame)
   local cookedFish = {}
   local foundIDs, cookedFood, harvestedFood, otherFood = {}, {}, {}, {}
   local harvestedFood = {}
 
   local special = {}
  -- Hide Lemon cake
   for i, item in Shared.skpairs(ItemData.Items) do
   foundIDs[1029] = true
     if i >= 22 and i < 34 then
   foundIDs[1061] = true
    table.insert(cookedFish, Icons.Icon({item.name, type='item'}))
 
    elseif i >= 152 and i < 160 then
  -- Harvested food first
    table.insert(harvestedFood, Icons.Icon({item.name, type='item'}))
   for i, item in ipairs(ItemData.Items) do
     if item.grownItemID ~= nil then
      local grownItem = Items.getItemByID(item.grownItemID)
      if grownItem ~= nil and grownItem.canEat then
        table.insert(harvestedFood, { ["name"] = grownItem.name, ["order"] = item.farmingLevel })
        foundIDs[grownItem.id] = true
      end
     end
     end
   end
   end
  table.insert(harvestedFood, Icons.Icon({'Carrot', type='item'}))
  table.insert(special, Icons.Icon({'Raw Magic Fish', type='item'}))
  table.insert(special, Icons.Icon({'Lemonade', type='item'}))
  local result = '{| class="wikitable" style="margin:0 auto 10px; clear:both; width: 100%"'
  result = result..'\r\n!colspan="2"|[[File:Crab_(item).svg|25px|link=Food]] [[Food]]'
  result = result..'\r\n|-\r\n!scope="row"|Cooked Fish'
  result = result..'\r\n|style="text-align:center;|'..table.concat(cookedFish, ' • ')
  result = result..'\r\n|-\r\n!scope="row"|Harvested Food'
  result = result..'\r\n|style="text-align:center;|'..table.concat(harvestedFood, ' • ')
  result = result..'\r\n|-\r\n!scope="row"|Special'
  result = result..'\r\n|style="text-align:center;|'..table.concat(special, ' • ')
  result = result..'\r\n|}'
  return result
end


function p.getPotionNavbox(frame)
  -- Any cooked & other food
  local result = '{| class="wikitable" style="margin:auto; clear:both; width: 100%"'
  for i, item in ipairs(ItemData.Items) do
  result = result..'\r\n!colspan=2|'..Icons.Icon({'Herblore', 'Potions', type='skill'})
    -- If an item can be eaten then it must be food
    if foundIDs[i - 1] == nil and item.canEat then
      if item.cookingCategory ~= nil then
        -- Item is cooked, such food items are split by category
        if cookedFood[item.cookingCategory + 1] == nil then
          cookedFood[item.cookingCategory + 1] = {}
        end


  local CombatPots = {}
        local perfectName = nil
  local SkillPots = {}
        if item.perfectItem ~= nil then
  for i, potData in Shared.skpairs(SkillData.Herblore.ItemData) do
          local perfectItem = Items.getItemByID(item.perfectItem)
    if potData.category == 0 then
          if perfectItem ~= nil then
      table.insert(CombatPots, Icons.Icon({potData.name, type='item', img=(potData.name..' I')}))
            perfectName = perfectItem.name
    else
            foundIDs[item.perfectItem] = true
      if potData.name == 'Bird Nests Potion' then
          end
         table.insert(SkillPots, Icons.Icon({"Bird Nest Potion", type='item', img="Bird Nest Potion I"}))
        end
         table.insert(cookedFood[item.cookingCategory + 1], { ["name"] = item.name, ["order"] = item.cookingLevel, ["perfectName"] = perfectName })
       else
       else
         table.insert(SkillPots, Icons.Icon({potData.name, type='item', img=(potData.name..' I')}))
        -- Item cannot be cooked or grown, but can be eaten
         table.insert(otherFood, { ["name"] = item.name, ["order"] = item.id })
      end
      foundIDs[i - 1] = true
    end
  end
 
  -- Sort food lists
  local sortFunc = function(a, b) return (a.order == b.order and a.name < b.name) or a.order < b.order end
  for i, items in pairs(cookedFood) do
    table.sort(cookedFood[i], sortFunc)
  end
  table.sort(harvestedFood, sortFunc)
  table.sort(otherFood, sortFunc)
 
  -- Generate food lists for final output
  local cookingCatHeader = {
    Icons.Icon({'Normal Cooking Fire', 'Cooking Fire', type='upgrade', nolink=true}),
    Icons.Icon({'Basic Furnace', 'Furnace', type='upgrade', nolink=true}),
    Icons.Icon({'Basic Pot', 'Pot', type='upgrade', nolink=true})
  }
  local getFoodList = function(foodTable)
      local listPart = {}
      for i, food in ipairs(foodTable) do
        local foodText = Icons.Icon({food.name, type='item'})
        if food.perfectName ~= nil then
          foodText = Icons.Icon({food.perfectName, type='item', notext=true}) .. ' ' .. foodText
        end
        table.insert(listPart, foodText)
       end
       end
      return table.concat(listPart, ' • ')
     end
     end
  local resultPart = {}
  table.insert(resultPart, '{| class="wikitable mw-collapsible" style="margin:0 auto 10px; clear:both; width: 100%"')
  table.insert(resultPart, '\r\n|-\r\n!style="background-color:#275C87;color:#FFFFFF;" colspan="2"| [[File:Crab_(item).svg|25px|link=Food]] [[Food]]')
  table.insert(resultPart, '\r\n|-\r\n!colspan="2"| Cooked')
  for catID, foodTable in ipairs(cookedFood) do
    table.insert(resultPart, '\r\n|-\r\n!scope="row"| ' .. cookingCatHeader[catID])
    table.insert(resultPart, '\r\n|style="text-align:center;"| ' .. getFoodList(foodTable))
   end
   end
  table.insert(resultPart, '\r\n|-\r\n!colspan="2"| Harvested')
  table.insert(resultPart, '\r\n|-\r\n|colspan="2" style="text-align:center;"| ' .. getFoodList(harvestedFood))
  table.insert(resultPart, '\r\n|-\r\n!colspan="2"| Other')
  table.insert(resultPart, '\r\n|-\r\n|colspan="2" style="text-align:center;"| ' .. getFoodList(otherFood))
  table.insert(resultPart, '\r\n|}')


   result = result..'\r\n|-\r\n!Combat Potions\r\n|class="center" style="vertical-align:middle;"'
   return table.concat(resultPart)
  result = result..'|'..table.concat(CombatPots, ' • ')
  result = result..'\r\n|-\r\n!Skill Potions\r\n|class="center" style="vertical-align:middle;"'
  result = result..'|'..table.concat(SkillPots, ' • ')
  result = result..'\r\n|}'
  return result
end
end