local N={}N.ClassName="\080\114\111\112\101\114\116\121\084\119\101\101\110\101\114\083\116\097\099\107"N.__index=N function N.new(C)local F=setmetatable({},N)F._base=C or error("\078\111 \098\097\115\101\080\114\111\112\101\114\116\121\084\119\101\101\110\101\114")F._tweens={}return F end function N.SetSpeed(C,N)C._base:SetSpeed(N)end function N.TweenProperty(h,N,C,F)assert(N)h._tweens[C]={Key=C;Priority=N;Value=F;AddTime=tick()}h:_updateBaseTweener()end function N.RemoveTween(C,N)if C._tweens[N]then C._tweens[N]=nil C:_updateBaseTweener()end end function N.HasTweens(N)return next(N._tweens)~=nil end function N.Update(N)return N._base:Update()end function N._updateBaseTweener(N)local C local F=0 for N,h in pairs(N._tweens)do if not C then C=h elseif h.Priority>C.Priority then C=h elseif h.Priority==C.Priority and h.AddTime>C.AddTime then C=h end F=F+1 end if F>10 then warn("\091\080\114\111\112\101\114\116\121\084\119\101\101\110\101\114\083\116\097\099\107\093 - \080\114\111\112\101\114\116\121\084\119\101\101\110\101\114\083\116\097\099\107 \105\115 \111\102 \115\105\122\101 "..(tostring(F).."\033"))end if C then N._base:Tween(C.Value)end end return N
--- Stack of tween properties
-- @classmod PropertyTweenerStack

local PropertyTweenerStack = {}
PropertyTweenerStack.ClassName = "PropertyTweenerStack"
PropertyTweenerStack.__index = PropertyTweenerStack

function PropertyTweenerStack.new(basePropertyTweener)
	local self = setmetatable({}, PropertyTweenerStack)

	self._base = basePropertyTweener or error("No basePropertyTweener")
	self._tweens = {}

	return self
end

function PropertyTweenerStack:SetSpeed(speed)
	self._base:SetSpeed(speed)
end

function PropertyTweenerStack:TweenProperty(priority, key, value)
	assert(priority)

	self._tweens[key] = {
		Key = key;
		Priority = priority;
		Value = value;
		AddTime = tick();
	}
	self:_updateBaseTweener()
end

function PropertyTweenerStack:RemoveTween(key)
	if self._tweens[key] then
		self._tweens[key] = nil
		self:_updateBaseTweener()
	end
end

function PropertyTweenerStack:HasTweens()
	return next(self._tweens) ~= nil
end

---
-- @return boolean true if updating, false otherwise
function PropertyTweenerStack:Update()
	return self._base:Update()
end

function PropertyTweenerStack:_updateBaseTweener()
	local topTween
	local count = 0
	for _, tween in pairs(self._tweens) do
		if not topTween then
			topTween = tween
		elseif tween.Priority > topTween.Priority then
			topTween = tween
		elseif tween.Priority == topTween.Priority and tween.AddTime > topTween.AddTime then
			topTween = tween
		end
		count = count + 1
	end

	-- Notify perfomrance issues
	if count > 10 then
		warn("[PropertyTweenerStack] - PropertyTweenerStack is of size " .. tostring(count) .. "!")
	end

	if topTween then
		self._base:Tween(topTween.Value)
	end
end

return PropertyTweenerStack