Skip to content

Commit

Permalink
(0.658.0.6580461)
Browse files Browse the repository at this point in the history
  • Loading branch information
EgoMoose authored and github-actions[bot] committed Jan 30, 2025
1 parent f0546c6 commit 8ef13a7
Show file tree
Hide file tree
Showing 10 changed files with 305 additions and 203 deletions.
227 changes: 135 additions & 92 deletions src/PlayerModulePatched/CameraModule/BaseCamera.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
--!nonstrict
--!nolint DeprecatedApi
--[[
BaseCamera - Abstract base class for camera control modules
2018 Camera Update - AllYourBlox
--]]
-- BaseCamera - Abstract base class for camera control modules

--[[ Local Constants ]]--
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local VRService = game:GetService("VRService")
local UserGameSettings = UserSettings():GetService("UserGameSettings")

local CommonUtils = script.Parent.Parent:WaitForChild("CommonUtils")
local ConnectionUtil = require(CommonUtils:WaitForChild("ConnectionUtil"))
local FlagUtil = require(CommonUtils:WaitForChild("FlagUtil"))

local CameraUtils = require(script.Parent:WaitForChild("CameraUtils"))
local ZoomController = require(script.Parent:WaitForChild("ZoomController"))
local CameraToggleStateController = require(script.Parent:WaitForChild("CameraToggleStateController"))
local CameraInput = require(script.Parent:WaitForChild("CameraInput"))
local CameraUI = require(script.Parent:WaitForChild("CameraUI"))

local player = Players.LocalPlayer

local FFlagUserFixGamepadMaxZoom
do
local success, result = pcall(function()
Expand All @@ -18,12 +27,12 @@ do
FFlagUserFixGamepadMaxZoom = success and result
end
local FFlagUserFixCameraOffsetJitter = FlagUtil.getUserFlag("UserFixCameraOffsetJitter2")
local FFlagUserOrganizeBaseCameraConnections = FlagUtil.getUserFlag("UserOrganizeBaseCameraConnections")

local UNIT_Z = Vector3.new(0,0,1)
local X1_Y0_Z1 = Vector3.new(1,0,1) --Note: not a unit vector, used for projecting onto XZ plane

local DEFAULT_DISTANCE = 12.5 -- Studs
local PORTRAIT_DEFAULT_DISTANCE = 25 -- Studs
local FIRST_PERSON_DISTANCE_THRESHOLD = 1.0 -- Below this value, snap into first person

-- Note: DotProduct check in CoordinateFrame::lookAt() prevents using values within about
Expand All @@ -32,16 +41,11 @@ local MIN_Y = math.rad(-80)
local MAX_Y = math.rad(80)

local VR_ANGLE = math.rad(15)
local VR_LOW_INTENSITY_ROTATION = Vector2.new(math.rad(15), 0)
local VR_HIGH_INTENSITY_ROTATION = Vector2.new(math.rad(45), 0)
local VR_LOW_INTENSITY_REPEAT = 0.1
local VR_HIGH_INTENSITY_REPEAT = 0.4

local ZERO_VECTOR2 = Vector2.new(0,0)
local ZERO_VECTOR3 = Vector3.new(0,0,0)

local SEAT_OFFSET = Vector3.new(0,5,0)
local VR_SEAT_OFFSET = Vector3.new(0,4,0)
local HEAD_OFFSET = Vector3.new(0,1.5,0)
local R15_HEAD_OFFSET = Vector3.new(0, 1.5, 0)
local R15_HEAD_OFFSET_NO_SCALING = Vector3.new(0, 2, 0)
Expand All @@ -50,28 +54,34 @@ local HUMANOID_ROOT_PART_SIZE = Vector3.new(2, 2, 1)
local ZOOM_SENSITIVITY_CURVATURE = 0.5
local FIRST_PERSON_DISTANCE_MIN = 0.5

local CameraUtils = require(script.Parent:WaitForChild("CameraUtils"))
local ZoomController = require(script.Parent:WaitForChild("ZoomController"))
local CameraToggleStateController = require(script.Parent:WaitForChild("CameraToggleStateController"))
local CameraInput = require(script.Parent:WaitForChild("CameraInput"))
local CameraUI = require(script.Parent:WaitForChild("CameraUI"))
local CONNECTIONS = {
CHARACTER_ADDED = "CHARACTER_ADDED",
CAMERA_MODE_CHANGED = "CAMERA_MODE_CHANGED",
CAMERA_MIN_DISTANCE_CHANGED = "CAMERA_MIN_DISTANCE_CHANGED",
CAMERA_MAX_DISTANCE_CHANGED = "CAMERA_MAX_DISTANCE_CHANGED",
}

--[[ Roblox Services ]]--
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local StarterGui = game:GetService("StarterGui")
local VRService = game:GetService("VRService")
local UserGameSettings = UserSettings():GetService("UserGameSettings")
type BaseCameraClass = {
__index: BaseCameraClass,
new: () -> BaseCamera,

local player = Players.LocalPlayer
-- Initializes the module based on any relevant data and sets up connections
-- to check for changes
_setUpConfigurations: (self: BaseCamera) -> (),
}

export type BaseCamera = typeof(setmetatable({} :: {
_connections: ConnectionUtil.ConnectionUtil,
}, {} :: BaseCameraClass))

--[[ The Module ]]--
local BaseCamera = {}
BaseCamera.__index = BaseCamera

function BaseCamera.new()
local self = setmetatable({}, BaseCamera)

self._connections = ConnectionUtil.new()

self.gamepadZoomLevels = {0, 10, 20} -- zoom levels that are cycled through on a gamepad R3 press

-- So that derived classes have access to this
Expand Down Expand Up @@ -126,58 +136,59 @@ function BaseCamera.new()

-- Mouse locked formerly known as shift lock mode
self.mouseLockOffset = ZERO_VECTOR3

if not FFlagUserOrganizeBaseCameraConnections then
if player.Character then
self:OnCharacterAdded(player.Character)
end

player.CharacterAdded:Connect(function(char)
self:OnCharacterAdded(char)
end)

if self.playerCameraModeChangeConn then self.playerCameraModeChangeConn:Disconnect() end
self.playerCameraModeChangeConn = player:GetPropertyChangedSignal("CameraMode"):Connect(function()
self:OnPlayerCameraPropertyChange()
end)

if self.minDistanceChangeConn then self.minDistanceChangeConn:Disconnect() end
self.minDistanceChangeConn = player:GetPropertyChangedSignal("CameraMinZoomDistance"):Connect(function()
self:OnPlayerCameraPropertyChange()
end)

if self.maxDistanceChangeConn then self.maxDistanceChangeConn:Disconnect() end
self.maxDistanceChangeConn = player:GetPropertyChangedSignal("CameraMaxZoomDistance"):Connect(function()
self:OnPlayerCameraPropertyChange()
end)

if self.playerDevTouchMoveModeChangeConn then self.playerDevTouchMoveModeChangeConn:Disconnect() end
self.playerDevTouchMoveModeChangeConn = player:GetPropertyChangedSignal("DevTouchMovementMode"):Connect(function()
self:OnDevTouchMovementModeChanged()
end)
self:OnDevTouchMovementModeChanged() -- Init

if self.gameSettingsTouchMoveMoveChangeConn then self.gameSettingsTouchMoveMoveChangeConn:Disconnect() end
self.gameSettingsTouchMoveMoveChangeConn = UserGameSettings:GetPropertyChangedSignal("TouchMovementMode"):Connect(function()
self:OnGameSettingsTouchMovementModeChanged()
end)
self:OnGameSettingsTouchMovementModeChanged() -- Init


-- Initialization things used to always execute at game load time, but now these camera modules are instantiated
-- when needed, so the code here may run well after the start of the game

if player.Character then
self:OnCharacterAdded(player.Character)
end

player.CharacterAdded:Connect(function(char)
self:OnCharacterAdded(char)
end)

if self.playerCameraModeChangeConn then self.playerCameraModeChangeConn:Disconnect() end
self.playerCameraModeChangeConn = player:GetPropertyChangedSignal("CameraMode"):Connect(function()
self:OnPlayerCameraPropertyChange()
end)

if self.minDistanceChangeConn then self.minDistanceChangeConn:Disconnect() end
self.minDistanceChangeConn = player:GetPropertyChangedSignal("CameraMinZoomDistance"):Connect(function()
self:OnPlayerCameraPropertyChange()
end)

if self.maxDistanceChangeConn then self.maxDistanceChangeConn:Disconnect() end
self.maxDistanceChangeConn = player:GetPropertyChangedSignal("CameraMaxZoomDistance"):Connect(function()
self.hasGameLoaded = game:IsLoaded()
if not self.hasGameLoaded then
self.gameLoadedConn = game.Loaded:Connect(function()
self.hasGameLoaded = true
self.gameLoadedConn:Disconnect()
self.gameLoadedConn = nil
end)
end

self:OnPlayerCameraPropertyChange()
end)

if self.playerDevTouchMoveModeChangeConn then self.playerDevTouchMoveModeChangeConn:Disconnect() end
self.playerDevTouchMoveModeChangeConn = player:GetPropertyChangedSignal("DevTouchMovementMode"):Connect(function()
self:OnDevTouchMovementModeChanged()
end)
self:OnDevTouchMovementModeChanged() -- Init

if self.gameSettingsTouchMoveMoveChangeConn then self.gameSettingsTouchMoveMoveChangeConn:Disconnect() end
self.gameSettingsTouchMoveMoveChangeConn = UserGameSettings:GetPropertyChangedSignal("TouchMovementMode"):Connect(function()
self:OnGameSettingsTouchMovementModeChanged()
end)
self:OnGameSettingsTouchMovementModeChanged() -- Init

end

UserGameSettings:SetCameraYInvertVisible()
UserGameSettings:SetGamepadCameraSensitivityVisible()

self.hasGameLoaded = game:IsLoaded()
if not self.hasGameLoaded then
self.gameLoadedConn = game.Loaded:Connect(function()
self.hasGameLoaded = true
self.gameLoadedConn:Disconnect()
self.gameLoadedConn = nil
end)
end

self:OnPlayerCameraPropertyChange()


return self
end
Expand All @@ -186,6 +197,28 @@ function BaseCamera:GetModuleName()
return "BaseCamera"
end

if FFlagUserOrganizeBaseCameraConnections then
function BaseCamera:_setUpConfigurations()
self._connections:trackConnection(CONNECTIONS.CHARACTER_ADDED, player.CharacterAdded:Connect(function(char)
self:OnCharacterAdded(char)
end))
if player.Character then
self:OnCharacterAdded(player.Character)
end

self._connections:trackConnection(CONNECTIONS.CAMERA_MODE_CHANGED, player:GetPropertyChangedSignal("CameraMode"):Connect(function()
self:OnPlayerCameraPropertyChange()
end))
self._connections:trackConnection(CONNECTIONS.CAMERA_MIN_DISTANCE_CHANGED, player:GetPropertyChangedSignal("CameraMinZoomDistance"):Connect(function()
self:OnPlayerCameraPropertyChange()
end))
self._connections:trackConnection(CONNECTIONS.CAMERA_MAX_DISTANCE_CHANGED, player:GetPropertyChangedSignal("CameraMaxZoomDistance"):Connect(function()
self:OnPlayerCameraPropertyChange()
end))
self:OnPlayerCameraPropertyChange()
end
end

function BaseCamera:OnCharacterAdded(char)
self.resetCameraAngle = self.resetCameraAngle or self:GetEnabled()
self.humanoidRootPart = nil
Expand Down Expand Up @@ -507,32 +540,34 @@ function BaseCamera:OnCurrentCameraChanged()
end
end

function BaseCamera:OnDynamicThumbstickEnabled()
if UserInputService.TouchEnabled then
self.isDynamicThumbstickEnabled = true
if not FFlagUserOrganizeBaseCameraConnections then
function BaseCamera:OnDynamicThumbstickEnabled()
if UserInputService.TouchEnabled then
self.isDynamicThumbstickEnabled = true
end
end
end

function BaseCamera:OnDynamicThumbstickDisabled()
self.isDynamicThumbstickEnabled = false
end
function BaseCamera:OnDynamicThumbstickDisabled()
self.isDynamicThumbstickEnabled = false
end

function BaseCamera:OnGameSettingsTouchMovementModeChanged()
if player.DevTouchMovementMode == Enum.DevTouchMovementMode.UserChoice then
if (UserGameSettings.TouchMovementMode == Enum.TouchMovementMode.DynamicThumbstick
or UserGameSettings.TouchMovementMode == Enum.TouchMovementMode.Default) then
self:OnDynamicThumbstickEnabled()
else
self:OnDynamicThumbstickDisabled()
function BaseCamera:OnGameSettingsTouchMovementModeChanged()
if player.DevTouchMovementMode == Enum.DevTouchMovementMode.UserChoice then
if (UserGameSettings.TouchMovementMode == Enum.TouchMovementMode.DynamicThumbstick
or UserGameSettings.TouchMovementMode == Enum.TouchMovementMode.Default) then
self:OnDynamicThumbstickEnabled()
else
self:OnDynamicThumbstickDisabled()
end
end
end
end

function BaseCamera:OnDevTouchMovementModeChanged()
if player.DevTouchMovementMode == Enum.DevTouchMovementMode.DynamicThumbstick then
self:OnDynamicThumbstickEnabled()
else
self:OnGameSettingsTouchMovementModeChanged()
function BaseCamera:OnDevTouchMovementModeChanged()
if player.DevTouchMovementMode == Enum.DevTouchMovementMode.DynamicThumbstick then
self:OnDynamicThumbstickEnabled()
else
self:OnGameSettingsTouchMovementModeChanged()
end
end
end

Expand Down Expand Up @@ -602,6 +637,10 @@ end

function BaseCamera:OnEnabledChanged()
if self.enabled then
if FFlagUserOrganizeBaseCameraConnections then
self:_setUpConfigurations()
end

CameraInput.setInputEnabled(true)

self.gamepadZoomPressConnection = CameraInput.gamepadZoomPress:Connect(function()
Expand All @@ -621,6 +660,10 @@ function BaseCamera:OnEnabledChanged()
end)
self:OnCurrentCameraChanged()
else
if FFlagUserOrganizeBaseCameraConnections then
self._connections:disconnectAll()
end

CameraInput.setInputEnabled(false)

if self.gamepadZoomPressConnection then
Expand Down
7 changes: 1 addition & 6 deletions src/PlayerModulePatched/CameraModule/OrbitalCamera.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
2018 Camera Update - AllYourBlox
--]]

local CommonUtils = script.Parent.Parent:WaitForChild("CommonUtils")
local FlagUtil = require(CommonUtils:WaitForChild("FlagUtil"))

-- Local private variables and constants
local UNIT_Z = Vector3.new(0,0,1)
local X1_Y0_Z1 = Vector3.new(1,0,1) --Note: not a unit vector, used for projecting onto XZ plane
Expand Down Expand Up @@ -36,8 +33,6 @@ local CameraInput = require(script.Parent:WaitForChild("CameraInput"))
--[[ Services ]]--
local PlayersService = game:GetService('Players')

local FFlagUserFixOrbitalCam = FlagUtil.getUserFlag("UserFixOrbitalCam")

--[[ The Module ]]--
local BaseCamera = require(script.Parent:WaitForChild("BaseCamera"))
local OrbitalCamera = setmetatable({}, BaseCamera)
Expand Down Expand Up @@ -222,7 +217,7 @@ end
function OrbitalCamera:Update(dt: number): (CFrame, CFrame)
local now = tick()
local timeDelta = (now - self.lastUpdate)
local userPanningTheCamera = CameraInput.getRotation(if FFlagUserFixOrbitalCam then dt else nil) ~= Vector2.new()
local userPanningTheCamera = CameraInput.getRotation(dt) ~= Vector2.new()
local camera = workspace.CurrentCamera
local newCameraCFrame = camera.CFrame
local newCameraFocus = camera.Focus
Expand Down
4 changes: 4 additions & 0 deletions src/PlayerModulePatched/ControlModule/TouchJump.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ local CommonUtils = script.Parent.Parent:WaitForChild("CommonUtils")
local FlagUtil = require(CommonUtils:WaitForChild("FlagUtil"))

local FFlagUserUpdateTouchJump = FlagUtil.getUserFlag("UserUpdateTouchJump3")
local FFlagUserControlModuleEnableIdempotent = FlagUtil.getUserFlag("UserControlModuleEnableIdempotent")
local ConnectionUtil
local CharacterUtil
if FFlagUserUpdateTouchJump then
Expand Down Expand Up @@ -272,6 +273,9 @@ function TouchJump:Enable(enable, parentFrame)
if parentFrame then
self.parentUIFrame = parentFrame
end
if FFlagUserControlModuleEnableIdempotent then
if self.externallyEnabled == enable then return end
end
self.externallyEnabled = enable
if FFlagUserUpdateTouchJump then
self:UpdateEnabled()
Expand Down
Loading

0 comments on commit 8ef13a7

Please sign in to comment.