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 = loader.lazy.require('String', 'Table', 'RarityTier', 'UI/Core', 'Pet/Utils', 'UIText') local p = {}

function p.petUI local petsByRarity = {} local sortedPets = {} -- TODO: Account for petName such as subzero wisp for k in pairs(petData) do		pet = petData[k]

maxRarity = pet["rarities"][#pet["rarities"]] if not petsByRarity[maxRarity] then petsByRarity[maxRarity] = {} end petsByRarity[maxRarity][k] = pet if not sortedPets[maxRarity] then sortedPets[maxRarity] = {k} else table.insert(sortedPets[maxRarity], k)		end end --mw.logObject(petsByRarity) --mw.logObject(sortedPets) -- TODO: sortedPets should move from sortedPets[maxRarity] to sortedPets[maxRarity][maxLevel], so as to account for special cases like the Golden Dragon pet. 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 mw.log(rarityCode) if sortedPets[rarityCode] then table.sort(sortedPets[rarityCode]) for b = 1, #sortedPets[rarityCode] do				petName = sortedPets[rarityCode][b] local pet = petsByRarity[rarityCode][petName] base, maxLevel = petUtils.getBaseMax(petName) local petSlot = p.petUISlot(pet, petName, rarity, maxLevel) table.insert(petSlots, petSlot) petScore = petScore + rarityScore end end end --Next steps: Add the pet slots to the UI	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(pet, petName, rarity, maxLevel) local petInfoTable = petUtils.petTemplateCreator(petName, maxLevel, rarity, petName) --mw.logObject(petInfoTable) -- Use the function above, as it is incredibly useful! local petImage = pet['variables'][rarity].petimage or (petName .. ' Pet') local petTitle = '&7[Lvl ' .. maxLevel .. '] &' .. UIText.getRarityColor(rarity, false) .. (pet['variables'][rarity].petname or petName) local petLink = (pet['variables'][rarity].petname or petName) .. ' Pet' petStatsText = petInfoTable[5] petAbilityText = petInfoTable[6] local petText = '&8' .. pet['petType'] .. '//'	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) ui:setSlot(6, 3, {		'Diamond',		title = '&aPet Score Rewards',		text = '&7Pet Score is calculated based/&7on how many &aunique &7pets you/&7have and the &ararity &7of these/&7pets.//&610 Score&7: &8+&b1 Magic Find/&625 Score&7: &8+&b2 Magic Find/&650 Score&7: &8+&b3 Magic Find/&675 Score&7: &8+&b4 Magic Find/&6100 Score&7: &8+&b5 Magic Find/&6130 Score&7: &8+&b6 Magic Find/&6175 Score&7: &8+&b7 Magic Find/&6225 Score&7: &8+&b8 Magic Find/&6275 Score&7: &8+&b9 Magic Find &5«/&6325 Score&7: &8+&b10 Magic Find//&9Your Pet Score: &f' .. petScore, 		--TODO: This should be calculated, and not static		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