Anonymous

Module:Pets: Difference between revisions

From Melvor Idle
1,096 bytes removed ,  15 January 2023
getPetNavbox: Migrate to Module:Navboxes
(Implement getExpansionIcon & add to a number of outputs; More robust guaranteed pet chance logic)
(getPetNavbox: Migrate to Module:Navboxes)
 
(2 intermediate revisions by the same user not shown)
Line 45: Line 45:
local pet = p.getPet(petName)
local pet = p.getPet(petName)
if pet == nil then
if pet == nil then
return "ERROR: No pet named " .. petName .. " exists in the data module[[Category:Pages with script errors]]"
return Shared.printError('No pet named "' .. petName .. '" exists in the data module')
end
end
Line 68: Line 68:
['Festive Cool Rock'] = { text = '[[Holiday Event 2021]]', useIcon = false },
['Festive Cool Rock'] = { text = '[[Holiday Event 2021]]', useIcon = false },
['Jerry the Giraffe'] = { text = '[[Golbin Raid|Golbin Raid Shop]]', useIcon = false },
['Jerry the Giraffe'] = { text = '[[Golbin Raid|Golbin Raid Shop]]', useIcon = false },
['Preston the Platypus'] = { text = '[[Golbin Raid|Golbin Raid Shop]]', useIcon = false }
['Preston the Platypus'] = { text = '[[Golbin Raid|Golbin Raid Shop]]', useIcon = false },
['Ty'] = { text = 'Mastery', useIcon = true },
['Golden Golbin'] = { text = Icons.Icon({'Golbin', type='monster'}) .. ' kills', useIcon = false},
['Saki'] = { text = 'Mastery', useIcon = true }
}
}
local petSourceText = nil
local petSourceText = nil
Line 186: Line 189:
local pet = p.getPet(name)
local pet = p.getPet(name)
if pet == nil then
if pet == nil then
return 'ERROR: Could not find pet with name ' .. (name or 'Unknown') .. '[[Category:Pages with script errros]]'
return Shared.printError('No pet named "' .. (name or 'Unknown') .. '" exists in the data module')
end
end
local effect = (args.effect ~= nil and args.effect ~= '') and args.effect or p._getPetEffect(pet)
local effect = (args.effect ~= nil and args.effect ~= '') and args.effect or p._getPetEffect(pet)
Line 210: Line 213:


result = '{|class="wikitable sortable lighttable stickyHeader"'
result = '{|class="wikitable sortable lighttable stickyHeader"'
result = result..'\r\n|- class="headerRow-0"\r\n! Name !! Image !! Acquired From !! Effect'
result = result..'\r\n|- class="headerRow-0"\r\n! colspan="2"| Pet !! Acquired From !! Effect'


for i, thisPet in ipairs(GameData.rawData.pets) do
for i, thisPet in ipairs(GameData.rawData.pets) do
result = result..'\r\n|-\r\n|'..Icons.Icon({thisPet.name, type='pet', noicon=true})
result = result..'\r\n|-\r\n|class="table-img" data-sort-value="' .. thisPet.name .. '"| ' .. Icons.Icon({thisPet.name, size='60', type='pet', notext=true})
result = result..'||style="text-align: center;"|' .. Icons.getExpansionIcon(thisPet.id) .. Icons.Icon({thisPet.name, size='60', type='pet', notext=true})
result = result..'||' .. Icons.getExpansionIcon(thisPet.id) ..Icons.Icon({thisPet.name, type='pet', noicon=true})
result = result..'||'..p._getPetSourceText(thisPet)
result = result..'||'..p._getPetSourceText(thisPet)
result = result..'||'..p._getPetEffect(thisPet)
result = result..'||'..p._getPetEffect(thisPet)
Line 233: Line 236:
end
end
if dung == nil then
if dung == nil then
return 'ERROR: Invalid dungeon name '..dungeonName..'[[Category:Pages with script errors]]'
return Shared.printError('No dungeon named "' .. dungeonName .. '" exists in the data module')
end
end


Line 245: 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