Module:Magic: Difference between revisions

From Melvor Idle
(Created page for referencing on other pages)
 
(Added some other ways to pull Alt Magic spells)
Line 14: Line 14:
   elseif type == 'Aurora' then
   elseif type == 'Aurora' then
     section = 'Auroras'
     section = 'Auroras'
  elseif type == 'Alt Magic' or type == 'Alternative Magic' then
    section='AltMagic'
   end
   end
    
    

Revision as of 19:17, 30 September 2020

Data pulled from Module:GameData/data


local p = {}

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

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

function p.getSpell(name, type)
  local section = type
  if type == nil or type == 'Spell' then
    section = 'Spells'
  elseif type == 'Curse' then
    section = 'Curses'
  elseif type == 'Aurora' then
    section = 'Auroras'
  elseif type == 'Alt Magic' or type == 'Alternative Magic' then
    section='AltMagic'
  end
  
  if MagicData[section] ~= nil then
    local result = nil
    for i, spell in pairs(MagicData[section]) do
      if spell.name == name then
        result = Shared.clone(spell)
        result.id = i - 1
      end
    end
    return result
  else
    return nil
  end
end

function p.getSpellByID(id, type)
  local section = type
  if type == nil or type == 'Spell' then
    section = 'Spells'
  elseif type == 'Curse' then
    section = 'Curses'
  elseif type == 'Aurora' then
    section = 'Auroras'
  end
  
  if MagicData[section] ~= nil then
    return MagicData[section][id + 1]
  else
    return nil
  end
end

return p