local H=nil local G={}local n=require(script:WaitForChild("\077\097\115\116\101\114\067\111\110\116\114\111\108"))local Q=require(script.MasterControl:WaitForChild("\084\104\117\109\098\115\116\105\099\107"))local O=require(script.MasterControl:WaitForChild("\084\104\117\109\098\112\097\100"))local Y=require(script.MasterControl:WaitForChild("\068\080\097\100"))local u=G.Thumbstick local e=require(script.MasterControl:WaitForChild("\084\111\117\099\104\074\117\109\112"))local t=require(script.MasterControl:WaitForChild("\075\101\121\098\111\097\114\100\077\111\118\101\109\101\110\116"))G.Gamepad=require(script.MasterControl:WaitForChild("\071\097\109\101\112\097\100"))function getTouchModule()local H=nil if not IsUserChoice then if DevMovementMode==Enum.DevTouchMovementMode.Thumbstick then H=Q isJumpEnabled=true elseif DevMovementMode==Enum.DevTouchMovementMode.Thumbpad then H=O isJumpEnabled=true elseif DevMovementMode==Enum.DevTouchMovementMode.DPad then H=Y isJumpEnabled=false elseif DevMovementMode==Enum.DevTouchMovementMode.ClickToMove then H=nil elseif DevMovementMode==Enum.DevTouchMovementMode.Scriptable then H=nil end else if UserMovementMode==Enum.TouchMovementMode.Default or UserMovementMode==Enum.TouchMovementMode.Thumbstick then H=Q isJumpEnabled=true elseif UserMovementMode==Enum.TouchMovementMode.Thumbpad then H=O isJumpEnabled=true elseif UserMovementMode==Enum.TouchMovementMode.DPad then H=Y isJumpEnabled=false elseif UserMovementMode==Enum.TouchMovementMode.ClickToMove then H=nil end end return H end function setJumpModule(H)if not H then e:Disable()elseif ControlState.Current==G.Touch then e:Enable()end 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 H=ControlState.Current end elseif H then H:Disable()H=nil end end G.Touch={}G.Touch.Current=nil G.Touch.LocalPlayerChangedCon=nil G.Touch.GameSettingsChangedCon=nil function G.Touch.RefreshControlStyle(H)if G.Touch.Current then G.Touch.Current:Disable()end setJumpModule(false)e:Disable()G.Touch:Enable()end function G.Touch.DisconnectEvents(H)if G.Touch.LocalPlayerChangedCon then G.Touch.LocalPlayerChangedCon:disconnect()G.Touch.LocalPlayerChangedCon=nil end if G.Touch.GameSettingsChangedCon then G.Touch.GameSettingsChangedCon:disconnect()G.Touch.GameSettingsChangedCon=nil end end function G.Touch.Enable(H)DevMovementMode=LocalPlayer.DevTouchMovementMode IsUserChoice=DevMovementMode==Enum.DevTouchMovementMode.UserChoice if IsUserChoice then UserMovementMode=GameSettings.TouchMovementMode end local n=getTouchModule()if n then setClickToMove()setJumpModule(isJumpEnabled)n:Enable()G.Touch.Current=n if isJumpEnabled then e:Enable()end end G.Touch:DisconnectEvents()G.Touch.LocalPlayerChangedCon=LocalPlayer.Changed:connect(function(H)if H=="\068\101\118\084\111\117\099\104\077\111\118\101\109\101\110\116\077\111\100\101"then G.Touch:RefreshControlStyle()end end)G.Touch.GameSettingsChangedCon=GameSettings.Changed:connect(function(H)if H=="\084\111\117\099\104\077\111\118\101\109\101\110\116\077\111\100\101"then G.Touch:RefreshControlStyle()end end)end function G.Touch.Disable(H)G.Touch:DisconnectEvents()local n=getTouchModule()if n==Q or n==Y or n==O then n:Disable()setJumpModule(false)e:Disable()end end local function i()local H=nil if not IsUserChoice then if DevMovementMode==Enum.DevComputerMovementMode.KeyboardMouse then H=t elseif DevMovementMode==Enum.DevComputerMovementMode.ClickToMove then H=t end else if UserMovementMode==Enum.ComputerMovementMode.KeyboardMouse or UserMovementMode==Enum.ComputerMovementMode.Default then H=t elseif UserMovementMode==Enum.ComputerMovementMode.ClickToMove then H=t end end return H end G.Keyboard={}function G.Keyboard.RefreshControlStyle(H)G.Keyboard:Disable()G.Keyboard:Enable()end function G.Keyboard.Enable(H)DevMovementMode=LocalPlayer.DevComputerMovementMode IsUserChoice=DevMovementMode==Enum.DevComputerMovementMode.UserChoice if IsUserChoice then UserMovementMode=GameSettings.ComputerMovementMode end local n=i()if n then n:Enable()end G.Keyboard:DisconnectEvents()G.Keyboard.LocalPlayerChangedCon=LocalPlayer.Changed:connect(function(H)if H=="\068\101\118\067\111\109\112\117\116\101\114\077\111\118\101\109\101\110\116\077\111\100\101"then G.Keyboard:RefreshControlStyle()end end)G.Keyboard.GameSettingsChangedCon=GameSettings.Changed:connect(function(H)if H=="\067\111\109\112\117\116\101\114\077\111\118\101\109\101\110\116\077\111\100\101"then G.Keyboard:RefreshControlStyle()end end)end function G.Keyboard.DisconnectEvents(H)if G.Keyboard.LocalPlayerChangedCon then G.Keyboard.LocalPlayerChangedCon:disconnect()G.Keyboard.LocalPlayerChangedCon=nil end if G.Keyboard.GameSettingsChangedCon then G.Keyboard.GameSettingsChangedCon:disconnect()G.Keyboard.GameSettingsChangedCon=nil end end function G.Keyboard.Disable(H)G.Keyboard:DisconnectEvents()local n=i()if n then n: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
--[[ Modules ]]
--
local ClickToMoveTouchControls = nil
local ControlModules = {}

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

local ThumbstickModule = require(script.MasterControl:WaitForChild("Thumbstick"))
local ThumbpadModule = require(script.MasterControl:WaitForChild("Thumbpad"))
local DPadModule = require(script.MasterControl:WaitForChild("DPad"))
local DefaultModule = ControlModules.Thumbstick
local TouchJumpModule = require(script.MasterControl:WaitForChild("TouchJump"))

local keyboardModule = require(script.MasterControl:WaitForChild("KeyboardMovement"))
ControlModules.Gamepad = require(script.MasterControl:WaitForChild("Gamepad"))

function getTouchModule()
	local module = nil
	if not IsUserChoice then
		if DevMovementMode == Enum.DevTouchMovementMode.Thumbstick then
			module = ThumbstickModule
			isJumpEnabled = true
		elseif DevMovementMode == Enum.DevTouchMovementMode.Thumbpad then
			module = ThumbpadModule
			isJumpEnabled = true
		elseif DevMovementMode == Enum.DevTouchMovementMode.DPad then
			module = DPadModule
			isJumpEnabled = false
		elseif DevMovementMode == Enum.DevTouchMovementMode.ClickToMove then
			-- Managed by CameraScript
			module = nil
		elseif DevMovementMode == Enum.DevTouchMovementMode.Scriptable then
			module = nil
		end
	else
		if
			UserMovementMode == Enum.TouchMovementMode.Default
			or UserMovementMode == Enum.TouchMovementMode.Thumbstick
		then
			module = ThumbstickModule
			isJumpEnabled = true
		elseif UserMovementMode == Enum.TouchMovementMode.Thumbpad then
			module = ThumbpadModule
			isJumpEnabled = true
		elseif UserMovementMode == Enum.TouchMovementMode.DPad then
			module = DPadModule
			isJumpEnabled = false
		elseif UserMovementMode == Enum.TouchMovementMode.ClickToMove then
			-- Managed by CameraScript
			module = nil
		end
	end

	return module
end

function setJumpModule(isEnabled)
	if not isEnabled then
		TouchJumpModule:Disable()
	elseif ControlState.Current == ControlModules.Touch then
		TouchJumpModule:Enable()
	end
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()
	if ControlModules.Touch.Current then
		ControlModules.Touch.Current:Disable()
	end
	setJumpModule(false)
	TouchJumpModule:Disable()
	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

		if isJumpEnabled then
			TouchJumpModule:Enable()
		end
	end

	-- This being within the above if statement was causing issues with ClickToMove, which isn't a module within this script.
	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
function ControlModules.Touch:Disable()
	ControlModules.Touch:DisconnectEvents()

	local newModuleToDisable = getTouchModule()

	if
		newModuleToDisable == ThumbstickModule
		or newModuleToDisable == DPadModule
		or newModuleToDisable == ThumbpadModule
	then
		newModuleToDisable:Disable()
		setJumpModule(false)
		TouchJumpModule:Disable()
	end
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:RefreshControlStyle()
	ControlModules.Keyboard:Disable()
	ControlModules.Keyboard:Enable()
end
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
		newModuleToEnable:Enable()
	end

	ControlModules.Keyboard:DisconnectEvents()
	ControlModules.Keyboard.LocalPlayerChangedCon = LocalPlayer.Changed:connect(function(property)
		if property == "DevComputerMovementMode" then
			ControlModules.Keyboard:RefreshControlStyle()
		end
	end)

	ControlModules.Keyboard.GameSettingsChangedCon = GameSettings.Changed:connect(function(property)
		if property == "ComputerMovementMode" then
			ControlModules.Keyboard:RefreshControlStyle()
		end
	end)
end
function ControlModules.Keyboard:DisconnectEvents()
	if ControlModules.Keyboard.LocalPlayerChangedCon then
		ControlModules.Keyboard.LocalPlayerChangedCon:disconnect()
		ControlModules.Keyboard.LocalPlayerChangedCon = nil
	end
	if ControlModules.Keyboard.GameSettingsChangedCon then
		ControlModules.Keyboard.GameSettingsChangedCon:disconnect()
		ControlModules.Keyboard.GameSettingsChangedCon = nil
	end
end
function ControlModules.Keyboard:Disable()
	ControlModules.Keyboard:DisconnectEvents()
	local newModuleToDisable = getKeyboardModule()
	if newModuleToDisable then
		newModuleToDisable:Disable()
	end
end

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