Module:Magic: Difference between revisions

From Melvor Idle
(Slight rework to how getting spells is handled)
(Fixed some mistakes with new getting spells)
Line 8: Line 8:
function processSpell(section, index)
function processSpell(section, index)
   local result = Shared.clone(MagicData[section][index])
   local result = Shared.clone(MagicData[section][index])
   result.id = index + 1
   result.id = index - 1
   result.type = section
   result.type = section
   return result
   return result
Line 51: Line 51:
    
    
   if MagicData[section] ~= nil then
   if MagicData[section] ~= nil then
     return processSpell(section, id - 1)
     return processSpell(section, id + 1)
   else
   else
     return nil
     return nil

Revision as of 18:37, 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