Module:Pets: Difference between revisions

From Melvor Idle
(Initial Module:Pets commit)
 
m (TODOs)
Line 1: Line 1:
--This module contains all sorts of functions for getting data on pets
--This module contains all sorts of functions for getting data on pets
--[[ TODOs
    Add getPetBySkill function
        acquiredBy field will work for all skills but Slayer
        May need to do skill look up by ID
            Ty has skill ID of 0, which is Woodcutting, for some reason
        Or maybe just take the first word
    Use the getPetBySkill function to build pet info table
        Similar to {{SkillCapeInfo}}
--]]


local p = {}
local p = {}

Revision as of 05:20, 13 January 2021

Data for this page is stored in Module:GameData/data


--This module contains all sorts of functions for getting data on pets

--[[ TODOs
    Add getPetBySkill function
        acquiredBy field will work for all skills but Slayer
        May need to do skill look up by ID
            Ty has skill ID of 0, which is Woodcutting, for some reason
        Or maybe just take the first word
    Use the getPetBySkill function to build pet info table
        Similar to {{SkillCapeInfo}}
--]]

local p = {}

local PetData = mw.loadData('Module:Pets/data')

local Shared = require( "Module:Shared" )
local Icons = require('Module:Icons')


function p.getPetByID(ID)
  local result = Shared.clone(PetData.Pets[ID + 1])
  if result ~= nil then
    result.id = ID
  end
  return result
end

function p.getPet(name)
  local result = nil
  name = string.gsub(name, "%%27", "'")
  name = string.gsub(name, "'", "'")
  name = string.gsub(name, "'", "'")
  for i, pet in pairs(PetData.Pets) do
    local PetName = string.gsub(pet.name, '#', '')
    if(name == PetName) then
      result = Shared.clone(pet)
      --Make sure every pet has an id, and account for Lua being 1-index
      result.id = i - 1
      break
    end
  end
  return result
end

function p.getPetTable(frame)
  local petName = frame.args ~= nil and frame.args[1] or frame
  local pet = p.getPet(petName)
  local result = '{| class="wikitable"\r\n'
  result = result..'!Pet!!Name!!Effect'
  result = result..'\r\n|-\r\n|'..Icons.Icon({pet.name, type='pet', size='60', notext=true})
  --result = result..'\r\n|-\r\n|[[File:'..pet.name..'_(pet).png|60px]]'
  result = result..'||[['..pet.name..']]||'..pet.description
  result = result..'\r\n|}'
  return result
end