Anonymous

Module:Pets: Difference between revisions

From Melvor Idle
Implement _getPetSkill(); Amend getPetTable()/getPetTableBySkill() to handle multiple pets
(_getPetSource: Add override for Mark)
(Implement _getPetSkill(); Amend getPetTable()/getPetTableBySkill() to handle multiple pets)
Line 31: Line 31:
       --Make sure every pet has an id, and account for Lua being 1-index
       --Make sure every pet has an id, and account for Lua being 1-index
       result.id = i - 1
       result.id = i - 1
      result.skill = p._getPetSkill(result)
       break
       break
     end
     end
Line 58: Line 59:
       local newPet = Shared.clone(pet)
       local newPet = Shared.clone(pet)
       newPet.id = i - 1
       newPet.id = i - 1
      newPet.skill = p._getPetSkill(newPet)
       table.insert(result, newPet)
       table.insert(result, newPet)
     end
     end
Line 118: Line 120:
end
end


function p.getPetTable(frame)
function p._getPetSkill(pet)
   local petName = frame.args ~= nil and frame.args[1] or frame
   local skillOverrides = {
   local pet = p.getPet(petName)
    ['Ty'] = -1,
   local result = '{| class="wikitable"\r\n'
    ['Mark'] = 21
  result = result..'!Pet!!Name!!Effect'
  }
   result = result..'\r\n|-\r\n|'..Icons.Icon({pet.name, type='pet', size='60', notext=true})
 
  result = result..'||[['..pet.name..']]||'..p._getPetEffect(pet)
  local skillID = pet.skill
   result = result..'\r\n|}'
  if skillOverrides[pet.name] ~= nil then
  return result
    skillID = skillOverrides[pet.name]
   end
  if skillID < 0 then
    return nil
  else
    return skillID
  end
end
 
function p._getPetTable(pets)
  if pets == nil or Shared.tableCount(pets) == 0 then return nil end
 
   local resultPart = {}
  table.insert(resultPart, '{| class="wikitable"\r\n!Pet!!Name!!Effect')
 
   for i, pet in pairs(pets) do
    table.insert(resultPart, '|-')
    table.insert(resultPart, '|style="text-align: center;"|' .. Icons.Icon({pet.name, type='pet', size=60, notext=true}))
    table.insert(resultPart, '|[[' .. pet.name .. ']]')
    table.insert(resultPart, '| ' .. p._getPetEffect(pet))
  end
   table.insert(resultPart, '|}')
 
  return table.concat(resultPart, '\r\n')
 
end
end


function p.getPetTableBySkill(frame)
function p.getPetTableBySkill(frame)
  local result = nil
   local skillName = frame.args ~= nil and frame.args[1] or frame
   local skillName = frame.args ~= nil and frame.args[1] or frame
  local skillID = Skills.getSkillID(skillName)


   return p.getPetTable(p.getPetBySkill(skillName).name)
   if skillID == nil then
    return ''
  else
    local pets = p.getPets(function(pet) return p._getPetSkill(pet) == skillID end)
    if pets == nil then
      return ''
    else
      return p._getPetTable(pets)
    end
  end
end
end


Line 212: Line 247:
end
end


function p.getPetNavbox(frame)
function p.getPetNavbox()
   --•
   --•
   local result = '{| class="wikitable" style="margin:auto; text-align:center; clear:both; width: 100%"'
   local result = '{| class="wikitable" style="margin:auto; text-align:center; clear:both; width: 100%"'
Line 221: Line 256:
   local otherPetList = {}
   local otherPetList = {}
   for i, petData in Shared.skpairs(PetData.Pets) do
   for i, petData in Shared.skpairs(PetData.Pets) do
     if petData.skill ~= nil and petData.skill >= 0 and petData.name ~= "Ty" then
     if p._getPetSkill(petData) ~= nil then
       table.insert(skillPetList, Icons.Icon({petData.name, type='pet'}))
       table.insert(skillPetList, Icons.Icon({petData.name, type='pet'}))
     elseif petData.obtained ~= nil and petData.obtained.dungeonCompletion ~= nil then
     elseif petData.obtained ~= nil and petData.obtained.dungeonCompletion ~= nil then