Module:Magic: Difference between revisions

From Melvor Idle
(Added some other ways to pull Alt Magic spells)
(Slight rework to how getting spells is handled)
Line 5: Line 5:
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
function processSpell(section, index)
  local result = Shared.clone(MagicData[section][index])
  result.id = index + 1
  result.type = section
  return result
end


function p.getSpell(name, type)
function p.getSpell(name, type)
   local section = type
   local section = type
   if type == nil or type == 'Spell' then
   if type == nil or type == 'Spell' or type == 'Standard' then
     section = 'Spells'
     section = 'Spells'
   elseif type == 'Curse' then
   elseif type == 'Curse' then
Line 22: Line 29:
     for i, spell in pairs(MagicData[section]) do
     for i, spell in pairs(MagicData[section]) do
       if spell.name == name then
       if spell.name == name then
         result = Shared.clone(spell)
         result = processSpell(section, i)
        result.id = i - 1
       end
       end
     end
     end
Line 32: Line 38:
end
end


function p.getSpellByID(id, type)
function p.getSpellByID(type, id)
   local section = type
   local section = type
   if type == nil or type == 'Spell' then
   if type == nil or type == 'Spell' or type == 'Standard' then
     section = 'Spells'
     section = 'Spells'
   elseif type == 'Curse' then
   elseif type == 'Curse' then
Line 40: Line 46:
   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
    
    
   if MagicData[section] ~= nil then
   if MagicData[section] ~= nil then
     return MagicData[section][id + 1]
     return processSpell(section, id - 1)
   else
   else
     return nil
     return nil

Revision as of 18:35, 6 October 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 processSpell(section, index)
  local result = Shared.clone(MagicData[section][index])
  result.id = index + 1
  result.type = section
  return result
end

function p.getSpell(name, type)
  local section = type
  if type == nil or type == 'Spell' or type == 'Standard' 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 = processSpell(section, i)
      end
    end
    return result
  else
    return nil
  end
end

function p.getSpellByID(type, id)
  local section = type
  if type == nil or type == 'Spell' or type == 'Standard' 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
    return processSpell(section, id - 1)
  else
    return nil
  end
end

return p