Module:Navboxes

Revision as of 02:29, 12 June 2021 by Falterfire (talk | contribs)

Documentation for this module may be created at Module:Navboxes/doc

-- New module to stop navbox generators cluttering other modules

local p = {}

local SkillData = mw.loadData('Module:Skills/data')
local MagicData = mw.loadData('Module:Magic/data')
local ItemData = mw.loadData('Module:Items/data')

local Shared = require('Module:Shared')
local Icons = require('Module:Icons')
local Items = require('Module:Items')

function p.getFarmingNavbox(frame)
  local allotmentSeedsTable = {}
  local allotmentProduceTable = {}
  local herbSeedsTable = {}
  local herbProduceTable = {}
  local treeSeedsTable = {}
  local treeProduceTable = {}

  for i, item in Shared.skpairs(ItemData.Items) do
    if item.tier == 'Allotment' then
      table.insert(allotmentSeedsTable, Icons.Icon({item.name, type='item'}))
    elseif item.type == 'Harvest' then
      table.insert(allotmentProduceTable, Icons.Icon({item.name, type='item'}))
    elseif item.tier == 'Herb' then
      table.insert(herbSeedsTable, Icons.Icon({item.name, type='item'}))  
    elseif item.type == 'Herb' then
      table.insert(herbProduceTable, Icons.Icon({item.name, type='item'}))
    elseif item.tier == 'Tree' then
      table.insert(treeSeedsTable, Icons.Icon({item.name, type='item'}))
    elseif i == 2 or i == 3 or i == 5 or i == 7 or i == 8 then
      table.insert(treeProduceTable, Icons.Icon({item.name, type='item'}))  
    end
  end
    
  local result = '{| class="wikitable mw-collapsible" style="margin:auto; clear:both; width: 100%"'
  result = result..'\r\n!colspan="2" style="padding-left:64px;"|'..Icons.Icon({'Farming', type='skill'})
  result = result..'\r\n|-\r\n!colspan="2"|Allotments'
  result = result..'\r\n|-\r\n!scope="row"|Seeds'
  result = result..'\r\n|style="text-align:center;|'..table.concat(allotmentSeedsTable, ' • ')
  result = result..'\r\n|-\r\n!scope="row"|Produce'
  result = result..'\r\n|style="text-align:center;|'..table.concat(allotmentProduceTable, ' • ')
  result = result..'\r\n|-\r\n!colspan="2"|Herbs'
  result = result..'\r\n|-\r\n!scope="row"|Seeds'
  result = result..'\r\n|style="text-align:center;|'..table.concat(herbSeedsTable, ' • ')
  result = result..'\r\n|-\r\n!scope="row"|Produce'
  result = result..'\r\n|style="text-align:center;|'..table.concat(herbProduceTable, ' • ')
  result = result..'\r\n|-\r\n!colspan="2"|Trees'
  result = result..'\r\n|-\r\n!scope="row"|Seeds'
  result = result..'\r\n|style="text-align:center;|'..table.concat(treeSeedsTable, ' • ')
  result = result..'\r\n|-\r\n!scope="row"|Produce'
  result = result..'\r\n|style="text-align:center;|'..table.concat(treeProduceTable, ' • ')
  result = result..'\r\n|}'

  return result
end

function p.getFoodNavbox(frame)
  local cookedFish = {}
  local harvestedFood = {}
  local special = {}
  for i, item in Shared.skpairs(ItemData.Items) do
    if i >= 22 and i < 34 then
    table.insert(cookedFish, Icons.Icon({item.name, type='item'}))
    elseif i >= 152 and i < 160 then
    table.insert(harvestedFood, Icons.Icon({item.name, type='item'}))
    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)
  local result = '{| class="wikitable" style="margin:auto; clear:both; width: 100%"'
  result = result..'\r\n!colspan=2|'..Icons.Icon({'Herblore', 'Potions', type='skill'})

  local CombatPots = {}
  local SkillPots = {}
  for i, potData in Shared.skpairs(SkillData.Herblore.ItemData) do
    if potData.category == 0 then
      table.insert(CombatPots, Icons.Icon({potData.name, type='item', img=(potData.name..' I')}))
    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

  result = result..'\r\n|-\r\n!Combat Potions\r\n|class="center" style="vertical-align:middle;"'
  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

function p.getPrayerNavbox(frame)
  local prayers = {}
  for i, prayer in Shared.skpairs(SkillData.Prayer) do
    table.insert(prayers, Icons.Icon({prayer.name, type="prayer"}))
  end
  local result = '{| class="wikitable" style="margin:auto; clear:both; width: 100%"'
  result = result..'\r\n!'..Icons.Icon({'Prayer', 'Prayers', type='skill'})
  result = result..'\r\n|-\r\n|style="text-align:center;"|'..table.concat(prayers, ' • ')
  result = result..'\r\n|}'
  return result
end

function p.getRuneNavbox(frame)
  local standardRunes = {}
  local combinationRunes = {}
  for i, item in pairs(ItemData.Items) do
    if (i >= 390 and i < 400) or (i >= 821 and i < 825) then
    table.insert(standardRunes, Icons.Icon({item.name, type='item'}))
    elseif i >= 825 and i < 831 then
    table.insert(combinationRunes, Icons.Icon({item.name, type='item'}))
    end
  end
  local result = '{| class="wikitable" style="margin:auto; clear:both; width: 100%"'
  result = result..'\r\n!colspan="2"|[[File:Air_Rune_(item).svg|25px|link=Runes]] [[Runes]]'
  result = result..'\r\n|-\r\n!scope="row"|Standard Runes'
  result = result..'\r\n|style="text-align:center;"|'..table.concat(standardRunes, ' • ')
  result = result..'\r\n|-\r\n!scope="row"|Combination Runes'
  result = result..'\r\n|style="text-align:center;"|'..table.concat(combinationRunes, ' • ')
  result = result..'\r\n|}'
  return result
end

function p.getSkillcapeNavbox(frame)
  local capeList = {}
  for i, item in pairs(ItemData.Items) do
    if Shared.contains(item.name, 'Skillcape') or item.name == 'Cape of Completion' then
    table.insert(capeList, Icons.Icon({item.name, type='item'}))
    end
  end
  table.sort(capeList, function(a,b)
    return a < b
  end)
  local result = '{| class="wikitable" style="margin:auto; clear:both; width: 100%"'
  result = result..'\r\n![[File:Cape_of_Completion_(item).svg|25px|link=Skillcapes]] [[Skillcapes]]'
  result = result..'\r\n|-\r\n|style="text-align:center;"|'..table.concat(capeList, ' • ')
  result = result..'\r\n|}'
  return result
end

function p.getSpellNavbox(frame)
  local spells = {}
  local curses = {}
  local auroras = {}
  local ancients = {}
  local altmagic = {}

  for i, spell in Shared.skpairs(MagicData.Spells) do
    table.insert(spells, Icons.Icon({spell.name, type='spell'}))
  end
  for i, spell in Shared.skpairs(MagicData.Curses) do
    table.insert(curses, Icons.Icon({spell.name, type='curse'}))
  end
  for i, spell in Shared.skpairs(MagicData.Auroras) do
    table.insert(auroras, Icons.Icon({spell.name, type='aurora'}))
  end
  for i, spell in Shared.skpairs(MagicData.Ancient) do
    table.insert(ancients, Icons.Icon({spell.name, type='spell'}))
  end
  for i, spell in Shared.skpairs(MagicData.AltMagic) do
    table.insert(altmagic, Icons.Icon({spell.name, type='spell'}))
  end

  local result = '{| class="wikitable" style="margin:auto; clear:both; width: 100%"'
  result = result..'\r\n!colspan=2|[[File:Magic_(skill).svg|25px|link=Spells]] [[Spells]]'
  result = result..'\r\n|-\r\n!scope="row"|Standard Spells'
  result = result..'\r\n|style="text-align:center;|'..table.concat(spells, ' • ')
  result = result..'\r\n|-\r\n!scope="row"|Curses'
  result = result..'\r\n|style="text-align:center;|'..table.concat(curses, ' • ')
  result = result..'\r\n|-\r\n!scope="row"|Auroras'
  result = result..'\r\n|style="text-align:center;|'..table.concat(auroras, ' • ')
  result = result..'\r\n|-\r\n!scope="row"|Ancient Magicks'
  result = result..'\r\n|style="text-align:center;|'..table.concat(ancients, ' • ')
  result = result..'\r\n|-\r\n!scope="row"|Alt Magic'
  result = result..'\r\n|style="text-align:center;|'..table.concat(altmagic, ' • ')
  result = result..'\r\n|}'

  return result
end

function p.getFamiliarNavbox(frame)
  local familiars = Items.getItems(function(item) return item.type == 'Familiar' end)
  table.sort(familiars, function(a, b) return a.summoningLevel < b.summoningLevel end)

  local result = '{| class="wikitable" style="margin:auto; clear:both; width: 100%"'
  result = result..'\r\n!colspan=2|[[File:Summoning_(skill).svg|25px|link=Summoning]] [[Summoning|Summoning Familiars]]'
  local iconArray = {}
  for i, fam in Shared.skpairs(familiars) do
    table.insert(iconArray, Icons.Icon({fam.name, type='item'}))
  end
  result = result..'\r\n|-\r\n|style="text-align:center;"|'..table.concat(iconArray, ' • ')
  result = result..'\r\n|}'
  return result
end

return p