Server character restructure

This commit is contained in:
2024-04-20 15:05:43 -04:00
parent 4baf7bff51
commit b82606d64c
21 changed files with 2 additions and 2 deletions

View File

@@ -0,0 +1,125 @@
--!optimize 2
--!native
--!strict
type CharacterSharedFolder = Folder
type TCP = RemoteEvent
local CharacterModule = {}
CharacterModule.__index = CharacterModule
local RS = game:GetService("RunService")
local Storage = game:GetService("ReplicatedStorage")
local ClientStorage = Storage:WaitForChild("Client") :: Folder
local preprocessor = {}
local CharacterShared: Folder
function preprocessor.CharacterShared(): CharacterSharedFolder
return CharacterShared
end
_G.include = function(this: LuaSourceContainer, FunName: string, ...)
if this:IsDescendantOf(script) then --getfenv is being removed
local switch = preprocessor[FunName]
return type(switch) == "function" and switch(...) or switch
else
warn(`Preprocessor append failed "{FunName}"`, debug.traceback())
return nil
end
end
function CharacterModule.constructor(Character)
CharacterShared = Character:WaitForChild("shared")
local HumanoidRPSettings = require(script:WaitForChild("HumanoidRootPart"))
local CameraModule = require(script:WaitForChild("Camera"))
local HumanoidModule = require(script:WaitForChild("Humanoid"))
local SpineModule = require(script:WaitForChild("SpineKinematics"))
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Humanoid = Character:WaitForChild("Humanoid")
local self = {}
self.ActionsTCP = CharacterShared:WaitForChild("Actions")
self.ActionsModule = require(script:WaitForChild("Actions"))
self.BindModule = require(ClientStorage:WaitForChild("KeyBinds"))
self.CurrentCamera = workspace.CurrentCamera
self.HRPSettings = HumanoidRPSettings.constructor(HumanoidRootPart)
self.CameraConsturctor = CameraModule.constructor(self.CurrentCamera, HumanoidRootPart, Humanoid)
self.HumanoidSettings = HumanoidModule.constructor(Humanoid)
self.SpineMovement = SpineModule.constructor(self.CurrentCamera)
return setmetatable(self, CharacterModule)
end
function CharacterModule:CharacterKeyBinds()
local ClientBindMap = self.BindModule.constructor(false)
local Actions = self.ActionsModule.constructor(self.HumanoidSettings, self.CurrentCamera, self.ActionsTCP)
--Crouch
ClientBindMap:AddInputBegan({Enum.KeyCode.RightControl, Enum.KeyCode.LeftControl}, function(_KeyPressed)
Actions:EnableCrouch()
end)
ClientBindMap:AddInputEnded({Enum.KeyCode.RightControl, Enum.KeyCode.LeftControl}, function(_KeyPressed)
Actions:DisableCrouch()
end)
--Walk
ClientBindMap:AddInputBegan({
Enum.KeyCode.LeftAlt,
Enum.KeyCode.RightAlt,
Enum.KeyCode.LeftShift,
Enum.KeyCode.RightShift
}, function(_KeyPressed)
Actions:EnableSneak()
end)
ClientBindMap:AddInputEnded({
Enum.KeyCode.LeftAlt,
Enum.KeyCode.RightAlt,
Enum.KeyCode.LeftShift,
Enum.KeyCode.RightShift
}, function(_KeyPressed)
Actions:DisableSneak()
end)
--Flashlight
ClientBindMap:AddInputBegan({Enum.KeyCode.F}, function(KeyPressed: Enum.KeyCode)
Actions:ToggleFlashlight(KeyPressed)
end)
end
function CharacterModule:Crosshair()
local RootVelocity = ClientStorage:WaitForChild("RootVelocity") :: BindableEvent
local RootVelocityStep = RS.Heartbeat:ConnectParallel(function(_dt)
RootVelocity:Fire(self.HRPSettings:Velocity())
end)
return RootVelocityStep
end
function CharacterModule:SetWalkSpeed()
self.HumanoidSettings:SetWalkSpeed()
end
function CharacterModule:SetJumpHeight()
self.HumanoidSettings:SetJumpHeight()
end
function CharacterModule:DisableRobloxSounds()
self.HRPSettings:DisableRobloxSounds()
end
function CharacterModule:EnableCameraBobbing()
self.CameraConsturctor:EnableBobbing()
end
function CharacterModule:EnableSpineMovement()
self.SpineMovement:Enable()
end
_G.include = nil
return CharacterModule