-- Decompiled with the Synapse X Luau decompiler.

local l__LocalPlayer__1 = game.Players.LocalPlayer;
local l__Pets__2 = l__LocalPlayer__1:WaitForChild("Pets");
local l__ReplicatedStorage__1 = game.ReplicatedStorage;
function getLevel(p1)
	local v3 = 0;
	local l__Value__4 = l__ReplicatedStorage__1.Pets.Settings.MaxPetLevel.Value;
	local v5 = 0 - 1;
	while true do
		if 100 * v5 + v3 <= p1 then
			if v5 ~= l__ReplicatedStorage__1.Pets.Settings.MaxPetLevel.Value then

			else
				return v5;
			end;
			if p1 < 100 * v5 + v3 + (100 + 25 * v5) then
				return v5;
			end;
		end;
		v3 = v3 + v5 * 25;
		if 0 <= 1 then
			if v5 < l__Value__4 then

			else
				break;
			end;
		elseif l__Value__4 < v5 then

		else
			break;
		end;
		v5 = v5 + 1;	
	end;
end;
function GetFolderFromPetID(p2)
	for v9, v10 in pairs(l__LocalPlayer__1.Pets:GetChildren()) do
		if v10.PetID.Value == p2 then
			return v10;
		end;	
	end;
	return nil;
end;
function getLayoutOrder(p3)
	local v11 = GetFolderFromPetID(p3);
	local l__Value__12 = l__ReplicatedStorage__1.Pets.Rarities:FindFirstChild(l__ReplicatedStorage__1.Pets.Models:FindFirstChild(v11.Name).Settings.Rarity.Value).Order.Value;
	local l__Value__13 = l__ReplicatedStorage__1.Pets.Settings.MaxPetLevel.Value;
	local v14 = getLevel(v11.TotalXP.Value);
	local v15 = {};
	local v16 = 0;
	for v20, v21 in pairs(l__ReplicatedStorage__1.Pets.Models:GetChildren()) do
		v15[#v15 + 1] = v21;	
	end;
	table.sort(v15, function(p4, p5)
		return p4:GetFullName() < p5:GetFullName();
	end);
	for v26, v25 in pairs(v15) do
		if v11.Equipped.Value == true then
			if v11.Name == v25.Name then
				return l__Value__13 * #v15 * (#l__ReplicatedStorage__1.Pets.Rarities:GetChildren() - l__Value__12) + v16 * l__Value__13 + (l__Value__13 - v14);
			end;
		elseif v11.Name == v25.Name then
			return #v15 * #l__ReplicatedStorage__1.Pets.Rarities:GetChildren() * l__Value__13 + l__Value__13 * #v15 * (#l__ReplicatedStorage__1.Pets.Rarities:GetChildren() - l__Value__12) + v16 * l__Value__13 + (l__Value__13 - v14);
		end;
		v16 = v16 + 1;	
	end;
end;
local l__UIelements__2 = l__LocalPlayer__1.PlayerGui:WaitForChild("UIelements");
local l__Inventory__3 = script.Parent.MainFrame.Inventory;
function newUI(p6)
	local v27 = l__UIelements__2.PetTemplate:Clone();
	local v28 = l__ReplicatedStorage__1.Pets.Models:FindFirstChild(p6.Name):FindFirstChild(p6:WaitForChild("Type").Value):Clone();
	local v29 = Instance.new("Camera", v27.PetView);
	local l__Position__30 = v28.PrimaryPart.Position;
	v27.PetID.Value = p6:WaitForChild("PetID").Value;
	v27.Name = p6.Name;
	v27.LevelLabel.Text = "Lvl. " .. getLevel(p6:WaitForChild("TotalXP").Value);
	v27.PetView.CurrentCamera = v29;
	v28.Parent = v27.PetView;
	v29.CFrame = CFrame.new(Vector3.new(l__Position__30.X + 2.25, l__Position__30.Y, l__Position__30.Z + 1), l__Position__30);
	v27.Parent = l__Inventory__3;
	l__Inventory__3.CanvasSize = UDim2.new(0, 0, 0, l__Inventory__3.UIGridLayout.AbsoluteContentSize.Y + 200);
	if p6.Equipped.Value == true then
		v27.EquipMarker.Visible = true;
	else
		v27.EquipMarker.Visible = false;
	end;
	p6:WaitForChild("TotalXP"):GetPropertyChangedSignal("Value"):Connect(function()
		v27.LevelLabel.Text = "Lvl. " .. getLevel(p6:WaitForChild("TotalXP").Value);
	end);
	for v34, v35 in pairs(l__Inventory__3:GetChildren()) do
		if not v35:IsA("UIGridLayout") then
			v35.LayoutOrder = getLayoutOrder(v35.PetID.Value);
		end;	
	end;
end;
for v36, v37 in pairs(l__Pets__2:GetChildren()) do
	newUI(v37);
end;
local l__TextLabel__4 = script.Parent.MainFrame.StorageDisplay.TextLabel;
local l__Data__5 = l__LocalPlayer__1:WaitForChild("Data");
local l__TextLabel__6 = script.Parent.MainFrame.EquippedDisplay.TextLabel;
l__Pets__2.ChildAdded:Connect(function(p7)
	local v38 = 0;
	for v39, v40 in pairs(l__Pets__2:GetChildren()) do
		if v40:WaitForChild("Equipped").Value == true then
			v38 = v38 + 1;
		end;
	end;
	l__TextLabel__4.Text = #l__Pets__2:GetChildren() .. "/" .. l__Data__5.MaxStorage.Value;
	l__TextLabel__6.Text = v38 .. "/" .. l__Data__5.MaxEquip.Value;
	newUI(p7);
end);
l__Pets__2.ChildRemoved:Connect(function(p8)
	for v41, v42 in pairs(l__Inventory__3:GetChildren()) do
		if not v42:IsA("UIGridLayout") and v42.PetID.Value == p8.PetID.Value then
			v42:Destroy();
		end;
	end;
	local v43 = 0;
	for v44, v45 in pairs(l__Pets__2:GetChildren()) do
		if v45.Equipped.Value == true then
			v43 = v43 + 1;
		end;
	end;
	l__TextLabel__4.Text = #l__Pets__2:GetChildren() .. "/" .. l__Data__5.MaxStorage.Value;
	l__TextLabel__6.Text = v43 .. "/" .. l__Data__5.MaxEquip.Value;
end);
l__Inventory__3.ChildAdded:Connect(function()
	l__Inventory__3.CanvasSize = UDim2.new(0, 0, 0, l__Inventory__3.UIGridLayout.AbsoluteContentSize.Y + 200);
end);
l__Inventory__3.ChildRemoved:Connect(function()
	l__Inventory__3.CanvasSize = UDim2.new(0, 0, 0, l__Inventory__3.UIGridLayout.AbsoluteContentSize.Y + 200);
end);
local v46 = 0;
for v47, v48 in pairs(l__Pets__2:GetChildren()) do
	if v48.Equipped.Value == true then
		v46 = v46 + 1;
	end;
end;
l__Data__5.MaxStorage:GetPropertyChangedSignal("Value"):Connect(function()
	l__TextLabel__4.Text = #l__Pets__2:GetChildren() .. "/" .. l__Data__5.MaxStorage.Value;
end);
l__Data__5.MaxEquip:GetPropertyChangedSignal("Value"):Connect(function()
	l__TextLabel__6.Text = v46 .. "/" .. l__Data__5.MaxEquip.Value;
end);
l__TextLabel__4.Text = #l__Pets__2:GetChildren() .. "/" .. l__Data__5.MaxStorage.Value;
l__TextLabel__6.Text = v46 .. "/" .. l__Data__5.MaxEquip.Value;