Module:CombatAreas: Difference between revisions
From Melvor Idle
Falterfire (talk | contribs) (Some tweaks to make handling areas in other code easier) |
Falterfire (talk | contribs) (Moving getAreaMonsterTable out to Module:Monsters to prevent loop) |
||
Line 6: | Line 6: | ||
local Shared = require('Module:Shared') | local Shared = require('Module:Shared') | ||
local Icons = require('Module:Icons') | local Icons = require('Module:Icons') | ||
function processArea(area, index) | function processArea(area, index) | ||
Line 66: | Line 65: | ||
end | end | ||
return areaArray | return areaArray | ||
end | end | ||
return p | return p |
Revision as of 19:36, 7 October 2020
Data is pulled from Module:GameData/data
NOTE: Some tables are in Module:CombatAreas/AreaTables to prevent loop from referencing Monsters
local p = {}
local Constants = mw.loadData('Module:Constants/data')
local AreaData = mw.loadData('Module:CombatAreas/data')
local Shared = require('Module:Shared')
local Icons = require('Module:Icons')
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)
local result = nil
mw.log(name)
--There are three types of areas but the lists are pretty short so looping all of them isn't a real issue
for i, area in pairs(AreaData.combatAreas) do
if area.areaName == name then
return processArea(area, i)
end
end
for i, area in pairs(AreaData.slayerAreas) do
if area.areaName == name then
return processArea(area, i)
end
end
for i, area in pairs(AreaData.dungeons) do
if area.name == name then
return processArea(area, i)
end
end
return nil
end
function p.getMonsterAreas(monsterID)
local areaArray = {}
--There are three types of areas but the lists are pretty short so looping all of them isn't a real issue
for i, area in pairs(AreaData.combatAreas) do
if Shared.contains(area.monsters, monsterID) then
table.insert(areaArray, processArea(area, i))
end
end
for i, area in pairs(AreaData.slayerAreas) do
if Shared.contains(area.monsters, monsterID) then
table.insert(areaArray, processArea(area, i))
end
end
for i, area in pairs(AreaData.dungeons) do
if Shared.contains(area.monsters, monsterID) then
table.insert(areaArray, processArea(area, i))
end
end
return areaArray
end
return p