Module:Pet/UI

local loader = require('Module:Loader') local petData = require('Module:Pet/Data') local rarityData = require('Module:RarityTier/Data')

local string, table, rarityTier, Interface, petUtils, UIText, rarityAliases = loader.lazy.require('String', 'Table', 'RarityTier', 'UI/Core', 'Pet/Utils', 'UIText', 'RarityTier/Aliases') local p = {}

function p.petUI local sortedPets = {} local petAliases = {} for k in pairs(petData) do		pet = petData[k] maxRarity = pet["rarities"][#pet["rarities"]] -- This code is solely for sorting purposes, to deal with cases such as Wisp Pet rarity = rarityAliases[string.lower(maxRarity)] local petname = pet['variables'][rarity]['petname'] if petname then petAliases[petname] = k		end base, maxLevel = petUtils.getBaseMax(k) if not sortedPets[maxRarity] then sortedPets[maxRarity] = {} end if not sortedPets[maxRarity][maxLevel] then sortedPets[maxRarity][maxLevel] = {petname or k}		else table.insert(sortedPets[maxRarity][maxLevel], petname or k)		end end local petSlots = {} local petScore = 0 -- This list is ordered from common upwards, so we need to reverse it, or iterate in reverse order, to get the desired order. orderedRarities = rarityTier._orderedTiers for a = #orderedRarities, 1, -1 do		rarity = orderedRarities[a] rarityCode = string.upper(rarityData[rarity]['short']) rarityScore = rarityData[rarity]['order'] + 1 local petsTable = sortedPets[rarityCode] if petsTable then for maxLevel, petsByLevel in table.sortedPairs(petsTable, function(a, b) return a > b end) do				table.sort(petsByLevel) for b = 1, #petsByLevel do					petName = petsByLevel[b] if petAliases[petName] then petName = petAliases[petName] end local petSlot = p.petUISlot(petName, rarity, maxLevel) table.insert(petSlots, petSlot) petScore = petScore + rarityScore end end end end local menu = ' ' local chunk = {} for a = 1, #petSlots do		table.insert(chunk, petSlots[a]) if a % 28 == 0 then menu = menu .. p.petTemplateUI(a/28, math.ceil(#petSlots/28), chunk, petScore) chunk = {} elseif a == #petSlots then menu = menu .. p.petTemplateUI(math.ceil(a/28), math.ceil(#petSlots/28), chunk, petScore) chunk = {} end end menu = menu .. ' '	return menu end

function p.petUISlot(petName, rarity, maxLevel) local petInfoTable = petUtils.petTemplateCreator(petName, maxLevel, rarity, petName) local petImage = petInfoTable['image'] or (petName .. ' Pet') local petTitle = '&7[Lvl ' .. maxLevel .. '] &' .. UIText.getRarityColor(rarity, false) .. (petInfoTable[2] or petName) local petLink = (petInfoTable[2] or petName) .. ' Pet' petStatsText = petInfoTable[5] petAbilityText = petInfoTable[6] local petText = '&8' .. petInfoTable[3] .. '//'	petText = petText .. petStatsText .. petAbilityText petText = petText .. '&b&lMAX LEVEL//&eClick to summon.' local petSlot = { petImage, title = petTitle, text = petText, link = petLink, class = 'none', }	return petSlot end

function p.petTemplateUI(page, maxPage, pets, petScore) local args = { ['topText'] = '(' .. page .. '/' .. maxPage .. ') Pets', ['id'] = 'pets-' .. page, ['goback'] = '&7To SkyBlock Menu', ['return_id'] = 'default', ['hide'] = ((page == 1) and 'false' or 'true'), ['fill'] = 'border', }	local ui = Interface(args) if page ~= 1 then ui:setSlot(6, 1, {			'Arrow',			title = '&aPrevious Page',			text = '&ePage ' .. (page - 1),			link = 'none',			class = 'goto-pets-' .. (page - 1),		}, false) end ui:setSlot(6, 2, {			'Autopet Rules 2-Pack',			title = '&cAutopet',			text = '&7Define custom &crules &7to/&7automatically equip your/&7pets.//&7Rules used: &c0\\/14',			link = 'none',			class = 'none',		}, false) petScores = {10, 25, 50, 75, 100, 130, 175, 225, 275, 325} petScoreText = '&7Pet Score is calculated based/&7on how many &aunique &7pets you/&7have and the &ararity &7of these/&7pets./' indicator = false for i = 1, #petScores do		if (petScore < petScores[i]) and not indicator then petScoreText = petScoreText .. ' &5«'			indicator = true end petScoreText = petScoreText .. '/&6' .. petScores[i] .. ' Score&7: &8+&b' .. i .. ' Magic Find' end if not indicator then petScoreText = petScoreText .. ' &5«'	end petScoreText = petScoreText .. '/&9Your Pet Score: &f' .. petScore ui:setSlot(6, 3, {		'Diamond',		title = '&aPet Score Rewards',		text = petScoreText,		link = 'none',		class = 'none',	}, false)

ui:setSlot(6, 6, {		'Gray Dye', 		title = '&aConvert Pet to an Item', 		text = '&7Enable this setting and click/&7any pet to convert it to an/&7item.//&cDisabled',		link = 'none',		class = 'none',	}, false)

ui:setSlot(6, 7, {		'Stone Button',		title = '&aHide Pets', 		text = '&7Hide all pets which are little/&7heads from being visible in the/&7world.//&7Pet effects remain active.//&7Currently: &aPets shown!/&7Selected pet: &cNone',		link = 'none',		class = 'none',	}, false) if page ~= maxPage then ui:setSlot(6, 9, {			'Arrow',			title = '&aNext Page',			text = '&ePage ' .. (page + 1),			link = 'none',			class = 'goto-pets-' .. (page + 1),		}, false) end for a = 1, #pets do		ui:setSlot(math.ceil(a/7) + 1, ((a-1) % 7) + 2, pets[a], false) end return tostring(ui) end

return p