local function t(t,o)local e=(o-t)%TAU local N=PI-math.abs(math.abs(e)-PI)if(e+TAU)%TAU<PI then return N else return-N end end function init(t)local o=t.SubN local e=t.Frame.RadialDial local N=Enum.UserInputType.MouseMovement t._Maid:Mark(t._ClickedBind)t._Maid:Mark(t._HoverBind)t._Maid:Mark(UIS.LastInputTypeChanged:Connect(function(t)if MOUSE_GROUP[t]or GAMEPAD_GROUP[t]then N=t end end))local r=0 t._Maid:Mark(UIS.InputBegan:Connect(function(o)if not t.Enabled then return end if GAMEPAD_GROUP[o.UserInputType]then if not GAMEPAD_CLICK[o.KeyCode]then return else t._ClickedBind:Fire(t:PickIndex(r))end end local e=t:GetTheta(o.UserInputType)if e then t._ClickedBind:Fire(t:PickIndex(e))end end))t._Maid:Mark(RUNSERVICE.RenderStepped:Connect(function(o)if not t.Enabled then return end local K=t:GetTheta(N)if K and t:IsVisible()then r=K local o=math.rad(t.Frame.Rotation)local N=math.deg((((K-t.Rotation)+o)+EX_OFFSET)+2*TAU)%360 local m=N/(360/t.SubN)+.5 e.Rotation=math.deg(t:GetRotation(m))local s=t:PickIndex(K)if s~=t._LastHoverIndex then t._HoverBind:Fire(t._LastHoverIndex,s)t._LastHoverIndex=s end end end))end

	
local function shortestDist(start, stop)
	local modDiff = (stop - start) % TAU
	local sDist = PI - math.abs(math.abs(modDiff) - PI)
	if ((modDiff + TAU) % TAU < PI) then
		return sDist
	else
		return -sDist
	end
end

function init(self)
	local subN = self.SubN
	local dial = self.Frame.RadialDial
	
	local inputType = Enum.UserInputType.MouseMovement
	
	self._Maid:Mark(self._ClickedBind)
	self._Maid:Mark(self._HoverBind)
	
	self._Maid:Mark(UIS.LastInputTypeChanged:Connect(function(iType)
		if (MOUSE_GROUP[iType] or GAMEPAD_GROUP[iType]) then
			inputType = iType
		end
	end))
	
	local lTheta = 0
	
	self._Maid:Mark(UIS.InputBegan:Connect(function(input)
		if (not self.Enabled) then
			return
		end
		
		
		if (GAMEPAD_GROUP[input.UserInputType]) then
			if (not GAMEPAD_CLICK[input.KeyCode]) then
				return
			else
				self._ClickedBind:Fire(self:PickIndex(lTheta))
			end
		end
		
		local theta = self:GetTheta(input.UserInputType)
		if (theta) then
			self._ClickedBind:Fire(self:PickIndex(theta))
		end
	end))

	self._Maid:Mark(RUNSERVICE.RenderStepped:Connect(function(dt)
		if (not self.Enabled) then
			return
		end
		
		local theta = self:GetTheta(inputType)
		if (theta and self:IsVisible()) then
			lTheta = theta
			
			local frameRot = math.rad(self.Frame.Rotation)
			local toDeg = math.deg(theta - self.Rotation + frameRot + EX_OFFSET + 2*TAU) % 360
			local closest = toDeg / (360 / self.SubN) + 0.5
			
			dial.Rotation = math.deg(self:GetRotation(closest))
			
			local index = self:PickIndex(theta)
			if (index ~= self._LastHoverIndex) then
				self._HoverBind:Fire(self._LastHoverIndex, index)
				self._LastHoverIndex = index
			end
		end
	end))
end
