local l=game:GetService("\080\108\097\121\101\114\115")local b=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local A=game:GetService("\072\116\116\112\083\101\114\118\105\099\101")local L=b.AvatarEditor local K=require(L.Shared.Util.Promise)local a=require(L.Shared.Colors)local Z=l.LocalPlayer local M=nil local R=nil local m=nil local j={"\066\097\099\107\065\099\099\101\115\115\111\114\121","\070\097\099\101\065\099\099\101\115\115\111\114\121","\070\114\111\110\116\065\099\099\101\115\115\111\114\121","\072\097\105\114\065\099\099\101\115\115\111\114\121","\072\097\116\065\099\099\101\115\115\111\114\121";"\078\101\099\107\065\099\099\101\115\115\111\114\121","\083\104\111\117\108\100\101\114\115\065\099\099\101\115\115\111\114\121","\087\097\105\115\116\065\099\099\101\115\115\111\114\121","\070\097\099\101";"\072\101\097\100","\076\101\102\116\065\114\109";"\076\101\102\116\076\101\103","\082\105\103\104\116\065\114\109","\082\105\103\104\116\076\101\103";"\084\111\114\115\111","\067\108\105\109\098\065\110\105\109\097\116\105\111\110","\070\097\108\108\065\110\105\109\097\116\105\111\110","\073\100\108\101\065\110\105\109\097\116\105\111\110";"\074\117\109\112\065\110\105\109\097\116\105\111\110";"\082\117\110\065\110\105\109\097\116\105\111\110","\083\119\105\109\065\110\105\109\097\116\105\111\110";"\087\097\108\107\065\110\105\109\097\116\105\111\110","\080\097\110\116\115","\083\104\105\114\116"}local P={"\066\111\100\121\084\121\112\101\083\099\097\108\101";"\072\101\097\100\083\099\097\108\101","\072\101\105\103\104\116\083\099\097\108\101","\080\114\111\112\111\114\116\105\111\110\083\099\097\108\101","\087\105\100\116\104\083\099\097\108\101"}local s={}s.UID=A:GenerateGUID(false)local function O()local l=Z.Character local b=l and l:FindFirstChildWhichIsA("\072\117\109\097\110\111\105\100")if b then return b end end local function f()return(((K.new(function(l,b)local A=O()if not A then return K.reject("\110\111 \104\117\109\097\110\111\105\100")end local L=A:GetAppliedDescription()if L then l(L)else b("\100\101\115\099\114\105\112\116\105\111\110 \110\111\116 \102\111\117\110\100")end end)):andThen(function(l)M={}for b,A in ipairs(j)do local L=string.split(l[A],"\044")for l,b in ipairs(L)do if b==""or b=="\048"then continue end M[tonumber(b)]=true end end m={}for b,A in ipairs(P)do m[A]=l[A]end R=l.HeadColor end)):catch(warn)):finally(function()if M==nil then M={}end end)end function s.Get(l)if M==nil then(f()):await()end return M end function s.GetTone(l)if R==nil then(f()):await()end return R end function s.GetScale(l)if m==nil then(f()):await()end return m end function s.Update(l)(f()):await()l.UID=A:GenerateGUID(false)end return s


local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Http = game:GetService("HttpService")

local AvatarEditor = ReplicatedStorage.AvatarEditor
local Promise = require(AvatarEditor.Shared.Util.Promise)
local Colors = require(AvatarEditor.Shared.Colors)

local player = Players.LocalPlayer

local ids = nil
local skintone = nil
local scales = nil

local idProperties = {
	"BackAccessory",
	"FaceAccessory",
	"FrontAccessory",
	"HairAccessory",
	"HatAccessory",
	"NeckAccessory",
	"ShouldersAccessory",
	"WaistAccessory",
	"Face",
	"Head",
	"LeftArm",
	"LeftLeg",
	"RightArm",
	"RightLeg",
	"Torso",
	"ClimbAnimation",
	"FallAnimation",
	"IdleAnimation",
	"JumpAnimation",
	"RunAnimation",
	"SwimAnimation",
	"WalkAnimation",
	"Pants",
	"Shirt",
}

local scaleProperties = {
	"BodyTypeScale",
	--"DepthScale",
	"HeadScale",
	"HeightScale",
	"ProportionScale",
	"WidthScale",
}

local module = {}
module.UID = Http:GenerateGUID(false)


local function getHumanoid()
	local character = player.Character
	local humanoid = character and character:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		return humanoid
	end
end


local function getHumanoidDescription()
	return Promise.new(function(resolve, reject)
		local humanoid = getHumanoid()
		if not humanoid then
			return Promise.reject("no humanoid")
		end
		
		local description = humanoid:GetAppliedDescription()
		if description then
			resolve(description)
		else
			reject("description not found")
		end
	end)
	:andThen(function(description)
		ids = {}
		for i, v in ipairs(idProperties) do
			local values = string.split(description[v], ",")
			for j, k in ipairs(values) do
				if k == "" or k == "0" then
					continue
				end
				ids[tonumber(k)] = true
			end
		end
		scales = {}
		for i, v in ipairs(scaleProperties) do
			scales[v] = description[v]
		end
		skintone = description.HeadColor
	end)
	:catch(warn)
	:finally(function()
		if ids == nil then
			ids = {}
		end
	end)
end


function module:Get()
	if ids == nil then
		getHumanoidDescription():await()
	end
	return ids
end


function module:GetTone()
	if skintone == nil then
		getHumanoidDescription():await()
	end
	return skintone
end


function module:GetScale()
	if scales == nil then
		getHumanoidDescription():await()
	end
	return scales
end


function module:Update()
	getHumanoidDescription():await()
	self.UID = Http:GenerateGUID(false)
end

return module

