Module:Navboxes: Difference between revisions

From Melvor Idle
mNo edit summary
m (Added alt magic)
Line 31: Line 31:
   local auroras = {}
   local auroras = {}
   local ancients = {}
   local ancients = {}
  local altmagic = {}


   for i, spell in Shared.skpairs(MagicData.Spells) do
   for i, spell in Shared.skpairs(MagicData.Spells) do
Line 43: Line 44:
   for i, spell in Shared.skpairs(MagicData.Ancient) do
   for i, spell in Shared.skpairs(MagicData.Ancient) do
     table.insert(ancients, Icons.Icon({spell.name, type='spell'}))
     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
   end


Line 55: Line 59:
   result = result..'\r\n|-\r\n!scope="row"|Ancient Magicks'
   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|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|}'
   result = result..'\r\n|}'



Revision as of 12:07, 8 June 2021

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

-- New module to stop navbox generators cluttering other modules

local p = {}

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

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

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

return p