Animate.Rotate=require(script:WaitForChild("\082\111\116\097\116\101"))Animate.Animations={}Animate.Last={}Animate.Humanoid=nil function Animate.GetHumanoid()if not Animate.Humanoid then repeat wait()until Animate.Humanoid and Animate.Humanoid:IsDescendantOf(workspace)end return Animate.Humanoid end function Animate.GetNextNumber(t,s)local P=Animate.Animations[t]local G=P and P[s]or nil if G then local P=Animate.Last[t][s]or 1 local W=P+1<=#G and P+1 or 1 return W end return 1 end function Animate.Stop(t,s)if t then if s then local P=Animate.Animations[t][s][Animate.Last[t][s]]if P then P:Stop()end else if Animate.Animations[t]then for t,s in pairs(Animate.Animations[t])do for t,s in pairs(s)do if s then s:Stop()end end end end end end end function Animate.Play(t,s,P,G)if t and s then local W=Animate.Animations[t]if W then local f=W[s]if f then local W=Animate.Last[s]P=P or Animate.GetNextNumber(t,s)Animate.Last[t][s]=P f[P]:Play()f[P]:AdjustSpeed(G or 1.0)end end end end function Animate.Load(t,s,P,G)if t and(s and P)then local W=Animate.GetHumanoid()local f=Instance.new("\065\110\105\109\097\116\105\111\110")f.AnimationId=P local g=W:LoadAnimation(f)Animate.Animations[t]=Animate.Animations[t]or{}Animate.Animations[t][s]=Animate.Animations[t][s]or{}if not G then table.insert(Animate.Animations[t][s],g)else for G=1,#Animate.Animations[t][s],1 do local W=Animate.Animations[t][s][G]if W.Animation.AnimationId==P then Animate.Animations[t][s][G]=g end end end Animate.Last[t]={[s]=1}return g end end function Animate.Unload(t,s,P)local G=Animate.Animations[t]if not s and G then for t,s in pairs(G)do G[t]={}end else local t=G and G[s]or nil if t then if P then for s=1,#t,1 do if t[s]==P then table.remove(t,s)end end else G[s]={}end end end end function Animate.GetTrack(t,s,P)if Animate.Animations[t]and Animate.Animations[t][s]then for t,s in pairs(Animate.Animations[t][s])do if s.Animation.AnimationId==P then return s end end end end function Animate.Reload()for t,s in pairs(Animate.Animations)do for s,P in pairs(s)do for P,G in pairs(P)do Animate.Load(t,s,G.Animation.AnimationId,true)end end end end return Animate
--	Animate.Rainbow = require(script:WaitForChild("Rainbow"))
Animate.Rotate = require(script:WaitForChild("Rotate"))
Animate.Animations = {
	--[[ Tool = {
			Idle = animation_track;
			Action = {
				animation_track;
				animation_track;
				animation_track;	
			}
		}]]
	--
}

Animate.Last = {}

Animate.Humanoid = nil -- Player requires this module and sets this.

function Animate.GetHumanoid()
	if not Animate.Humanoid then
		repeat
			wait()
		until Animate.Humanoid and Animate.Humanoid:IsDescendantOf(workspace)
	end
	return Animate.Humanoid
end

function Animate.GetNextNumber(category, state)
	local category_list = Animate.Animations[category]
	local state_list = category_list and category_list[state] or nil
	if state_list then
		local state_last_number = Animate.Last[category][state] or 1
		local next_number = (state_last_number + 1 <= #state_list) and state_last_number + 1 or 1
		return next_number
	end
	return 1
end

-- stops the animation from the current category of the given state.
-- if no state is given, stop all
function Animate.Stop(category, state)
	if category then
		if state then
			local track = Animate.Animations[category][state][Animate.Last[category][state]]
			if track then
				track:Stop()
			end
		else
			if Animate.Animations[category] then
				for state, tracks in pairs(Animate.Animations[category]) do
					for _, track in pairs(tracks) do
						if track then
							track:Stop()
						end
					end
				end
			end
		end
	end
end

function Animate.Play(category, state, number, at_speed)
	if category and state then
		local category_list = Animate.Animations[category]
		if category_list then
			local state_list = category_list[state]
			if state_list then
				local state_last_number = Animate.Last[state]
				number = number or Animate.GetNextNumber(category, state)
				Animate.Last[category][state] = number
				state_list[number]:Play()
				state_list[number]:AdjustSpeed(at_speed or 1.0)
			end
		end
	end
end

-- creates a new animation track, and saves it to Animate.Animations[category][state]
function Animate.Load(category, state, id, replace_slot)
	if category and state and id then
		local humanoid = Animate.GetHumanoid()
		local animation = Instance.new("Animation")
		animation.AnimationId = id
		local track = humanoid:LoadAnimation(animation)
		Animate.Animations[category] = Animate.Animations[category] or {}
		Animate.Animations[category][state] = Animate.Animations[category][state] or {}
		if not replace_slot then
			table.insert(Animate.Animations[category][state], track)
		else
			for i = 1, #Animate.Animations[category][state] do -- loop thru and replace the animation track with the new one (called from reload)
				local t = Animate.Animations[category][state][i]
				if t.Animation.AnimationId == id then
					Animate.Animations[category][state][i] = track
				end
			end
		end
		Animate.Last[category] = {
			[state] = 1,
		}
		return track
	end
end

-- removes an id from the state list.
-- if no state supplied, all states are unloaded (set to {})
-- if no id supplied, sets the state list to {};
function Animate.Unload(category, state, id)
	local category_list = Animate.Animations[category]
	if not state and category_list then
		for state, list in pairs(category_list) do
			category_list[state] = {}
		end
	else
		local state_list = category_list and category_list[state] or nil
		if state_list then
			if id then
				for i = 1, #state_list do
					if state_list[i] == id then
						table.remove(state_list, i)
					end
				end
			else
				category_list[state] = {}
			end
		end
	end
end

function Animate.GetTrack(category, state, id)
	if Animate.Animations[category] and Animate.Animations[category][state] then
		for _, track in pairs(Animate.Animations[category][state]) do
			if track.Animation.AnimationId == id then
				return track
			end
		end
	end
end

-- reloads all the current anims
function Animate.Reload()
	for category, states in pairs(Animate.Animations) do
		for state, tracks in pairs(states) do
			for track_num, track in pairs(tracks) do
				Animate.Load(category, state, track.Animation.AnimationId, true)
			end
		end
	end
end

return Animate
