Anonymous

Module:Navboxes: Difference between revisions

From Melvor Idle
getPrayerNavbox/getSpellNavbox: Order prayers/spells by level, in line with in-game appearance
(getRuneNavbox: Order results by level & improve resilience against future rune additions; getSkillcapeNavbox: Include missing max cape & consistency with shop table; getFishingNavbox: Implement to replace manually maintained table)
(getPrayerNavbox/getSpellNavbox: Order prayers/spells by level, in line with in-game appearance)
Line 188: Line 188:


function p.getPrayerNavbox(frame)
function p.getPrayerNavbox(frame)
   local prayers = {}
   local prayerList = {}
   for i, prayer in Shared.skpairs(SkillData.Prayer) do
   for i, prayer in Shared.skpairs(SkillData.Prayer) do
    table.insert(prayers, Icons.Icon({prayer.name, type="prayer"}))
  table.insert(prayerList, { ["name"] = prayer.name, ["order"] = prayer.prayerLevel })
   end
   end
   local result = '{| class="wikitable" style="margin:auto; clear:both; width: 100%"'
  table.sort(prayerList, function(a, b)
   result = result..'\r\n!'..Icons.Icon({'Prayer', 'Prayers', type='skill'})
                        if a.order == b.order then
   result = result..'\r\n|-\r\n|style="text-align:center;"|'..table.concat(prayers, ' • ')
                        return a.name < b.name
   result = result..'\r\n|}'
                        else
   return result
                        return a.order < b.order
                        end
                      end)
 
   local prayerListText = {}
  for i, prayer in ipairs(prayerList) do
  table.insert(prayerListText, Icons.Icon({ prayer.name, type='prayer' }))
  end
 
  local resultPart = {}
  table.insert(resultPart, '{| class="wikitable" style="margin:auto; clear:both; width: 100%"')
   table.insert(resultPart, '\r\n!'..Icons.Icon({'Prayer', 'Prayers', type='skill'}))
   table.insert(resultPart, '\r\n|-\r\n|style="text-align:center;"| ' .. table.concat(prayerListText, ' • '))
   table.insert(resultPart, '\r\n|}')
   return table.concat(resultPart)
end
end


Line 257: Line 271:


function p.getSpellNavbox(frame)
function p.getSpellNavbox(frame)
   local spells = {}
   local spellTable = { ["standard"] = {}, ["curse"] = {}, ["aurora"] = {}, ["ancient"] = {}, ["alt"] = {} }
   local curses = {}
   local catData = {
  local auroras = {}
  { ["name"] = 'standard', ["header"] = '[[Magic#Standard_Magic|Standard Spells]]', ["imgType"] = 'spell' },
  local ancients = {}
  { ["name"] = 'curse', ["header"] = '[[Magic#Curses|Curses]]', ["imgType"] = 'curse' },
   local altmagic = {}
  { ["name"] = 'aurora', ["header"] = '[[Magic#Auroras|Auroras]]', ["imgType"] = 'aurora' },
  { ["name"] = 'ancient', ["header"] = '[[Magic#Ancient_Magicks|Ancient Magicks]]', ["imgType"] = 'spell' },
  { ["name"] = 'alt', ["header"] = '[[Alternative_Magic|Alt Magic]]', ["imgType"] = 'spell' },
   }


   for i, spell in Shared.skpairs(MagicData.Spells) do
   for i, spell in ipairs(MagicData.Spells) do
    table.insert(spells, Icons.Icon({spell.name, type='spell'}))
  table.insert(spellTable['standard'], { ["name"] = spell.name, ["order"] = spell.level })
  end
  for i, spell in ipairs(MagicData.Curses) do
  table.insert(spellTable['curse'], { ["name"] = spell.name, ["order"] = spell.level })
   end
   end
   for i, spell in Shared.skpairs(MagicData.Curses) do
   for i, spell in ipairs(MagicData.Auroras) do
    table.insert(curses, Icons.Icon({spell.name, type='curse'}))
  table.insert(spellTable['aurora'], { ["name"] = spell.name, ["order"] = spell.level })
   end
   end
   for i, spell in Shared.skpairs(MagicData.Auroras) do
   for i, spell in ipairs(MagicData.Ancient) do
    table.insert(auroras, Icons.Icon({spell.name, type='aurora'}))
  table.insert(spellTable['ancient'], { ["name"] = spell.name, ["order"] = spell.level })
   end
   end
   for i, spell in Shared.skpairs(MagicData.Ancient) do
   for i, spell in ipairs(MagicData.AltMagic) do
    table.insert(ancients, Icons.Icon({spell.name, type='spell'}))
  table.insert(spellTable['alt'], { ["name"] = spell.name, ["order"] = spell.level })
   end
   end
   for i, spell in Shared.skpairs(MagicData.AltMagic) do
    
    table.insert(altmagic, Icons.Icon({spell.name, type='spell'}))
  local getSpellList = function(spellTable, imgType)
      local listPart = {}
      for i, obj in ipairs(spellTable) do
        table.insert(listPart, Icons.Icon({obj.name, type=imgType}))
      end
      return table.concat(listPart, ' ')
    end
 
  local resultPart = {}
  table.insert(resultPart, '{| class="wikitable" style="margin:auto; clear:both; width: 100%"')
  table.insert(resultPart, '\r\n!colspan=2|[[File:Magic_(skill).svg|25px|link=Spells]] [[Spells]]')
  for i, catDefn in ipairs(catData) do
  table.sort(spellTable[catDefn.name], function(a, b)
                                if a.order == b.order then
                                return a.name < b.name
                                else
                                return a.order < b.order
                                end
                              end)
  table.insert(resultPart, '\r\n|-\r\n!scope="row"| ' .. catDefn.header)
  table.insert(resultPart, '\r\n|style="text-align:center;| ' .. getSpellList(spellTable[catDefn.name], catDefn.imgType))
   end
   end
  table.insert(resultPart, '\r\n|}')


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