Module:CombatAreas: Difference between revisions

Some tweaks to make handling areas in other code easier
(Added p.getMonsterAreas)
(Some tweaks to make handling areas in other code easier)
Line 7: Line 7:
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Monsters = require('Module:Monsters')
local Monsters = require('Module:Monsters')
function processArea(area, index)
  local result = Shared.clone(area)
  result.id = index - 1
  if result.name == nil then
    result.name = result.areaName
  end
  if Shared.contains(result.type, 'Dungeon') then
    result.type = 'dungeon'
  end
  return result
end


function p.getArea(name)
function p.getArea(name)
Line 14: Line 26:
   for i, area in pairs(AreaData.combatAreas) do
   for i, area in pairs(AreaData.combatAreas) do
     if area.areaName == name then
     if area.areaName == name then
       result = Shared.clone(area)
       return processArea(area, i)
      result.id = i - 1
      return result
     end
     end
   end
   end
Line 22: Line 32:
   for i, area in pairs(AreaData.slayerAreas) do
   for i, area in pairs(AreaData.slayerAreas) do
     if area.areaName == name then
     if area.areaName == name then
       result = Shared.clone(area)
       return processArea(area, i)
      result.id = i - 1
      return result
     end
     end
   end
   end
Line 30: Line 38:
   for i, area in pairs(AreaData.dungeons) do
   for i, area in pairs(AreaData.dungeons) do
     if area.name == name then
     if area.name == name then
       result = Shared.clone(area)
       return processArea(area, i)
      result.type = 'dungeon'
      result.id = i - 1
      return result
     end
     end
   end
   end
Line 45: Line 50:
   for i, area in pairs(AreaData.combatAreas) do
   for i, area in pairs(AreaData.combatAreas) do
     if Shared.contains(area.monsters, monsterID) then
     if Shared.contains(area.monsters, monsterID) then
      result = Shared.clone(area)
       table.insert(areaArray, processArea(area, i))
      result.id = i - 1
       table.insert(areaArray, result)
     end
     end
   end
   end
Line 53: Line 56:
   for i, area in pairs(AreaData.slayerAreas) do
   for i, area in pairs(AreaData.slayerAreas) do
     if Shared.contains(area.monsters, monsterID) then
     if Shared.contains(area.monsters, monsterID) then
      result = Shared.clone(area)
       table.insert(areaArray, processArea(area, i))
      result.id = i - 1
       table.insert(areaArray, result)
     end
     end
   end
   end
Line 61: Line 62:
   for i, area in pairs(AreaData.dungeons) do
   for i, area in pairs(AreaData.dungeons) do
     if Shared.contains(area.monsters, monsterID) then
     if Shared.contains(area.monsters, monsterID) then
      result = Shared.clone(area)
       table.insert(areaArray, processArea(area, i))
      result.type = 'dungeon'
      result.id = i - 1
       table.insert(areaArray, result)
     end
     end
   end
   end