Anonymous

Module:Pets: Difference between revisions

From Melvor Idle
1,300 bytes removed ,  15 January 2023
getPetNavbox: Migrate to Module:Navboxes
(Use printError function)
(getPetNavbox: Migrate to Module:Navboxes)
Line 248: Line 248:
end
end
end
end
end
-- TODO Move to Module:Navboxes
function p.getPetNavbox()
local resultPart = {}
table.insert(resultPart, '{| class="wikitable" style="margin:auto; text-align:center; clear:both; width: 100%"')
table.insert(resultPart, '\r\n|-\r\n!colspan="2"|[[Pets]]')
local petList = {
["skill"] = {},
["boss"] = {},
["other"] = {}
}
local skillPetList = {}
local bossPetList = {}
local otherPetList = {}
for i, petData in ipairs(GameData.rawData.pets) do
local source = p._getPetSource(petData)
local listCat = 'other'
if type(source) == 'table' and source.type ~= nil then
if source.type == 'skill' then
listCat = 'skill'
elseif source.type == 'dungeon' or source.type == 'slayerArea' then
listCat = 'boss'
else
listCat = 'other'
end
end
table.insert(petList[listCat], petData.name)
end
local getIconList =
function(pets)
local result = {}
for i, pet in ipairs(pets) do
table.insert(result, Icons.Icon({pet, type='pet'}))
end
return table.concat(result, ' • ')
end
for cat, catData in pairs(petList) do
table.sort(catData, function(a, b) return a < b end)
table.insert(resultPart, '\r\n|-\r\n!' .. Shared.titleCase(cat) .. ' Pets\r\n|' .. getIconList(catData))
end
table.insert(resultPart, '\r\n|}')
return table.concat(resultPart)
end
end


return p
return p