--[[
	Adds a Spring to be updated every render step.
]]

function SpringScheduler.add(spring: Spring)
	local damping: number
	local speed: number

	if spring._dampingIsState then
		local state: PubTypes.StateObject<number> = spring._damping
		damping = state:get(false)
	else
		damping = spring._damping
	end

	if spring._speedIsState then
		local state: PubTypes.StateObject<number> = spring._speed
		speed = state:get(false)
	else
		speed = spring._speed
	end

	if typeof(damping) ~= "number" then
		logError("mistypedSpringDamping", nil, typeof(damping))
	elseif damping < 0 then
		logError("invalidSpringDamping", nil, damping)
	end

	if typeof(speed) ~= "number" then
		logError("mistypedSpringSpeed", nil, typeof(speed))
	elseif speed < 0 then
		logError("invalidSpringSpeed", nil, speed)
	end

	spring._lastDamping = damping
	spring._lastSpeed = speed

	local dampingBucket = springBuckets[damping]

	if dampingBucket == nil then
		dampingBucket = {}
		springBuckets[damping] = dampingBucket
	end

	local speedBucket = dampingBucket[speed]

	if speedBucket == nil then
		speedBucket = {}
		dampingBucket[speed] = speedBucket
	end

	speedBucket[spring] = true
end
