local V=require(script.Parent:WaitForChild("\066\097\115\101\067\104\097\114\097\099\116\101\114\067\111\110\116\114\111\108\108\101\114"))local E=setmetatable({},V)E.__index=E function E.new(s)local t=setmetatable(V.new(),E)t.CONTROL_ACTION_PRIORITY=s t.forwardValue=0 t.backwardValue=0 t.leftValue=0 t.rightValue=0 t.activeGamepad=NONE t.gamepadConnectedConn=nil t.gamepadDisconnectedConn=nil return t end function E.Enable(E,V)if not UserInputService.GamepadEnabled then return false end if V==E.enabled then return true end E.forwardValue=0 E.backwardValue=0 E.leftValue=0 E.rightValue=0 E.moveVector=ZERO_VECTOR3 E.isJumping=false if V then E.activeGamepad=E:GetHighestPriorityGamepad()if E.activeGamepad~=NONE then E:BindContextActions()E:ConnectGamepadConnectionListeners()else return false end else E:UnbindContextActions()E:DisconnectGamepadConnectionListeners()E.activeGamepad=NONE end E.enabled=V return true end
--
local BaseCharacterController = require(script.Parent:WaitForChild("BaseCharacterController"))
local Gamepad = setmetatable({}, BaseCharacterController)
Gamepad.__index = Gamepad

function Gamepad.new(CONTROL_ACTION_PRIORITY)
	local self = setmetatable(BaseCharacterController.new(), Gamepad)

	self.CONTROL_ACTION_PRIORITY = CONTROL_ACTION_PRIORITY

	self.forwardValue  = 0
	self.backwardValue = 0
	self.leftValue = 0
	self.rightValue = 0

	self.activeGamepad = NONE	-- Enum.UserInputType.Gamepad1, 2, 3...
	self.gamepadConnectedConn = nil
	self.gamepadDisconnectedConn = nil
	return self
end

function Gamepad:Enable(enable)
	if not UserInputService.GamepadEnabled then
		return false
	end

	if enable == self.enabled then
		-- Module is already in the state being requested. True is returned here since the module will be in the state
		-- expected by the code that follows the Enable() call. This makes more sense than returning false to indicate
		-- no action was necessary. False indicates failure to be in requested/expected state.
		return true
	end

	self.forwardValue  = 0
	self.backwardValue = 0
	self.leftValue = 0
	self.rightValue = 0
	self.moveVector = ZERO_VECTOR3
	self.isJumping = false

	if enable then
		self.activeGamepad = self:GetHighestPriorityGamepad()
		if self.activeGamepad ~= NONE then
			self:BindContextActions()
			self:ConnectGamepadConnectionListeners()
		else
			-- No connected gamepads, failure to enable
			return false
		end
	else
		self:UnbindContextActions()
		self:DisconnectGamepadConnectionListeners()
		self.activeGamepad = NONE
	end

	self.enabled = enable
	return true
end
