local Y=nil local p={}local r=require(script:WaitForChild("\077\097\115\116\101\114\067\111\110\116\114\111\108"))local b=require(script.MasterControl:WaitForChild("\075\101\121\098\111\097\114\100\077\111\118\101\109\101\110\116"))function getTouchModule()local Y=nil if not IsUserChoice then if DevMovementMode==Enum.DevTouchMovementMode.Scriptable then Y=nil end else if UserMovementMode==Enum.TouchMovementMode.ClickToMove then Y=nil end end return Y end function setJumpModule(Y) end function setClickToMove()if DevMovementMode==Enum.DevTouchMovementMode.ClickToMove or DevMovementMode==Enum.DevComputerMovementMode.ClickToMove or UserMovementMode==Enum.ComputerMovementMode.ClickToMove or UserMovementMode==Enum.TouchMovementMode.ClickToMove then if lastInputType==Enum.UserInputType.Touch then Y=ControlState.Current end elseif Y then Y:Disable()Y=nil end end p.Touch={}p.Touch.Current=nil p.Touch.LocalPlayerChangedCon=nil p.Touch.GameSettingsChangedCon=nil function p.Touch.RefreshControlStyle(Y)p.Touch.Current:Disable()setJumpModule(false)p.Touch:Enable()end function p.Touch.DisconnectEvents(Y)if p.Touch.LocalPlayerChangedCon then p.Touch.LocalPlayerChangedCon:disconnect()p.Touch.LocalPlayerChangedCon=nil end if p.Touch.GameSettingsChangedCon then p.Touch.GameSettingsChangedCon:disconnect()p.Touch.GameSettingsChangedCon=nil end end function p.Touch.Enable(Y)DevMovementMode=LocalPlayer.DevTouchMovementMode IsUserChoice=DevMovementMode==Enum.DevTouchMovementMode.UserChoice if IsUserChoice then UserMovementMode=GameSettings.TouchMovementMode end local r=getTouchModule()if r then setClickToMove()setJumpModule(isJumpEnabled)r:Enable()p.Touch.Current=r p.Touch:DisconnectEvents()p.Touch.LocalPlayerChangedCon=LocalPlayer.Changed:connect(function(Y)if Y=="\068\101\118\084\111\117\099\104\077\111\118\101\109\101\110\116\077\111\100\101"then p.Touch:RefreshControlStyle()end end)p.Touch.GameSettingsChangedCon=GameSettings.Changed:connect(function(Y)if Y=="\084\111\117\099\104\077\111\118\101\109\101\110\116\077\111\100\101"then p.Touch:RefreshControlStyle()end end)end end function p.Touch.Disable(Y)p.Touch:DisconnectEvents()local r=getTouchModule()end local function h()local Y=nil if not IsUserChoice then if DevMovementMode==Enum.DevComputerMovementMode.KeyboardMouse then Y=b elseif DevMovementMode==Enum.DevComputerMovementMode.ClickToMove then Y=b end else if UserMovementMode==Enum.ComputerMovementMode.KeyboardMouse or UserMovementMode==Enum.ComputerMovementMode.Default then Y=b elseif UserMovementMode==Enum.ComputerMovementMode.ClickToMove then Y=b end end return Y end p.Keyboard={}function p.Keyboard.Enable(Y)DevMovementMode=LocalPlayer.DevComputerMovementMode IsUserChoice=DevMovementMode==Enum.DevComputerMovementMode.UserChoice if IsUserChoice then UserMovementMode=GameSettings.ComputerMovementMode end local p=h()if p then if p then p:Enable()end end end function p.Keyboard.Disable(Y)local p=h()if p then p:Disable()end end if IsTouchDevice then BindableEvent_OnFailStateChanged=script.Parent:WaitForChild("\079\110\067\108\105\099\107\084\111\077\111\118\101\070\097\105\108\083\116\097\116\101\067\104\097\110\103\101")end
--
local ClickToMoveTouchControls = nil
local ControlModules = {}

local MasterControl = require(script:WaitForChild('MasterControl'))



local keyboardModule = require(script.MasterControl:WaitForChild('KeyboardMovement'))

function getTouchModule()
	local module = nil
	if not IsUserChoice then
		if DevMovementMode == Enum.DevTouchMovementMode.Scriptable then
			module = nil
		end
	else
		if UserMovementMode == Enum.TouchMovementMode.ClickToMove then
			-- Managed by CameraScript
			module = nil
		end
	end
	
	return module
end

function setJumpModule(isEnabled)

end

function setClickToMove()
	if DevMovementMode == Enum.DevTouchMovementMode.ClickToMove or DevMovementMode == Enum.DevComputerMovementMode.ClickToMove or
		UserMovementMode == Enum.ComputerMovementMode.ClickToMove or UserMovementMode == Enum.TouchMovementMode.ClickToMove then
		--
		if lastInputType == Enum.UserInputType.Touch then
			ClickToMoveTouchControls = ControlState.Current
		end
	elseif ClickToMoveTouchControls then
		ClickToMoveTouchControls:Disable()
		ClickToMoveTouchControls = nil
	end
end

ControlModules.Touch = {}
ControlModules.Touch.Current = nil
ControlModules.Touch.LocalPlayerChangedCon = nil
ControlModules.Touch.GameSettingsChangedCon = nil

function ControlModules.Touch:RefreshControlStyle()
	ControlModules.Touch.Current:Disable()
	setJumpModule(false)
	ControlModules.Touch:Enable()
end
function ControlModules.Touch:DisconnectEvents()
	if ControlModules.Touch.LocalPlayerChangedCon then
		ControlModules.Touch.LocalPlayerChangedCon:disconnect()
		ControlModules.Touch.LocalPlayerChangedCon = nil
	end
	if ControlModules.Touch.GameSettingsChangedCon then
		ControlModules.Touch.GameSettingsChangedCon:disconnect()
		ControlModules.Touch.GameSettingsChangedCon = nil
	end
end
function ControlModules.Touch:Enable()
	DevMovementMode = LocalPlayer.DevTouchMovementMode
	IsUserChoice = DevMovementMode == Enum.DevTouchMovementMode.UserChoice
	if IsUserChoice then
		UserMovementMode = GameSettings.TouchMovementMode
	end
		
	local newModuleToEnable = getTouchModule()
	if newModuleToEnable then
		setClickToMove()
		setJumpModule(isJumpEnabled)
		
		newModuleToEnable:Enable()
		ControlModules.Touch.Current = newModuleToEnable

		ControlModules.Touch:DisconnectEvents()
		ControlModules.Touch.LocalPlayerChangedCon = LocalPlayer.Changed:connect(function(property)
			if property == 'DevTouchMovementMode' then
				ControlModules.Touch:RefreshControlStyle()
			end
		end)		
		
		ControlModules.Touch.GameSettingsChangedCon = GameSettings.Changed:connect(function(property)
			if property == 'TouchMovementMode' then
				ControlModules.Touch:RefreshControlStyle()
			end
		end)

	end
end
function ControlModules.Touch:Disable()
	ControlModules.Touch:DisconnectEvents()
	
	local newModuleToDisable = getTouchModule()
	

end

local function getKeyboardModule()
	-- NOTE: Click to move still uses keyboard. Leaving cases in case this ever changes.
	local whichModule = nil
	if not IsUserChoice then
		if DevMovementMode == Enum.DevComputerMovementMode.KeyboardMouse then
			whichModule = keyboardModule
		elseif DevMovementMode == Enum.DevComputerMovementMode.ClickToMove then
			-- Managed by CameraScript
			whichModule = keyboardModule
		end 
	else
		if UserMovementMode == Enum.ComputerMovementMode.KeyboardMouse or UserMovementMode == Enum.ComputerMovementMode.Default then
			whichModule = keyboardModule
		elseif UserMovementMode == Enum.ComputerMovementMode.ClickToMove then
			-- Managed by CameraScript
			whichModule = keyboardModule
		end
	end

	return whichModule
end

ControlModules.Keyboard = {}
function ControlModules.Keyboard:Enable()
	DevMovementMode = LocalPlayer.DevComputerMovementMode
	IsUserChoice = DevMovementMode == Enum.DevComputerMovementMode.UserChoice
	if IsUserChoice then
		UserMovementMode = GameSettings.ComputerMovementMode
	end
		
	local newModuleToEnable = getKeyboardModule()
	if newModuleToEnable then	
		if newModuleToEnable then
			newModuleToEnable:Enable()
		end
	end
end
function ControlModules.Keyboard:Disable()
	local newModuleToDisable = getKeyboardModule()
	if newModuleToDisable then
		newModuleToDisable:Disable()
	end
end

if IsTouchDevice then
	BindableEvent_OnFailStateChanged = script.Parent:WaitForChild('OnClickToMoveFailStateChange')
end
