mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 14:51:55 +00:00
Big client character refactor
This commit is contained in:
@@ -28,11 +28,16 @@ export type Math = {
|
||||
OutBounce: EaseFunction,
|
||||
InQuad: EaseFunction,
|
||||
RotationMatrix: (X: number, Y: number, Z: number) -> RotationMatrix,
|
||||
Scalar: (X1: number, Y1: number, X2: number, Y2: number) -> Scalar
|
||||
Scalar: (X1: number, Y1: number, X2: number, Y2: number) -> Scalar,
|
||||
maxmin: (min: number, n: number, max: number) -> number
|
||||
}
|
||||
|
||||
local Math = {} :: Math
|
||||
|
||||
function Math.maxmin(min, n, max)
|
||||
return math.max(min, math.min(n, max))
|
||||
end
|
||||
|
||||
function Math.RotationMatrix(X: number, Y: number, Z: number): RotationMatrix
|
||||
return {
|
||||
Ixx = math.cos(Z)*math.cos(X)-math.sin(Z)*math.sin(X)*math.sin(Y);
|
||||
|
||||
@@ -2,34 +2,51 @@
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
--I couldn't get ContextActionService to work how i wanted it to
|
||||
--Couldn't get ContextActionService to work how i wanted
|
||||
|
||||
local BindLink = {}
|
||||
BindLink.__index = BindLink
|
||||
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
|
||||
type Impl_Constructor = {
|
||||
__index: Impl_Constructor,
|
||||
constructor: Constructor_Fun,
|
||||
--Class functions
|
||||
CharacterKeyBinds: (self: ClassConstructor) -> (),
|
||||
AddInputBegan: (self: ClassConstructor, Keys: {Enum.KeyCode}, Callback: CallbackFunction) -> (),
|
||||
AddInputEnded: (self: ClassConstructor, Keys: {Enum.KeyCode}, Callback: CallbackFunction) -> (),
|
||||
KeyHold: (self: ClassConstructor, Key: Enum.KeyCode) -> boolean
|
||||
}
|
||||
|
||||
type Constructor_Fun = (gameProcessing: boolean) -> ClassConstructor
|
||||
type Constructor_Return_Props = {
|
||||
BindMap: KeyBindMap,
|
||||
InputBegan: InputBegan,
|
||||
InputEnded: InputEnded
|
||||
}
|
||||
|
||||
type CallbackFunction = (KeyPressed: Enum.KeyCode) -> ()
|
||||
|
||||
export type KeyBindMap = {
|
||||
[string]: {
|
||||
[Enum.KeyCode]: (KeyPressed: Enum.KeyCode) -> ()
|
||||
}
|
||||
}
|
||||
type BindConstructor = {
|
||||
BindMap: KeyBindMap,
|
||||
InputBegan: InputBegan,
|
||||
InputEnded: InputEnded
|
||||
}
|
||||
|
||||
export type InputBegan = RBXScriptConnection
|
||||
export type InputEnded = RBXScriptConnection
|
||||
type CallbackFunction = (KeyPressed: Enum.KeyCode) -> ()
|
||||
|
||||
export type KeyBindsConstructor = ClassConstructor
|
||||
|
||||
local BindLink = {} :: Impl_Constructor
|
||||
BindLink.__index = BindLink
|
||||
|
||||
local UIS = game:GetService("UserInputService")
|
||||
|
||||
function BindLink.constructor(gameProcessing: boolean) --Allow multiple bindings of the same keys, no overwrites
|
||||
local self = {} :: BindConstructor
|
||||
local self = {} :: Constructor_Return_Props
|
||||
self.BindMap = {
|
||||
Began = {},
|
||||
Ended = {}
|
||||
}
|
||||
|
||||
--Return these for convenience
|
||||
self.InputBegan = UIS.InputBegan:Connect(function(input, gameProcessedEvent)
|
||||
if gameProcessing and gameProcessedEvent or not gameProcessedEvent then
|
||||
@@ -55,9 +72,9 @@ function BindLink.constructor(gameProcessing: boolean) --Allow multiple bindings
|
||||
return setmetatable(self, BindLink)
|
||||
end
|
||||
|
||||
function BindLink:AddInputBegan(Keys: {Enum.KeyCode}, Callback: CallbackFunction)
|
||||
for i = 1, #Keys do
|
||||
local Key = Keys[i]
|
||||
function BindLink:AddInputBegan(Keys, Callback)
|
||||
for n: number = 1, #Keys do
|
||||
local Key = Keys[n]
|
||||
if self.BindMap.Began[Key] then
|
||||
warn(`Key >began< "{Key.Name}" is already binded on this KeyBind map`, debug.traceback())
|
||||
end
|
||||
@@ -65,9 +82,9 @@ function BindLink:AddInputBegan(Keys: {Enum.KeyCode}, Callback: CallbackFunction
|
||||
end
|
||||
end
|
||||
|
||||
function BindLink:AddInputEnded(Keys: {Enum.KeyCode}, Callback: CallbackFunction)
|
||||
for i = 1, #Keys do
|
||||
local Key = Keys[i]
|
||||
function BindLink:AddInputEnded(Keys, Callback)
|
||||
for n: number = 1, #Keys do
|
||||
local Key = Keys[n]
|
||||
if self.BindMap.Ended[Key] then
|
||||
warn(`Key >ended< "{Key.Name}" is already binded on this KeyBind map`, debug.traceback())
|
||||
end
|
||||
@@ -75,7 +92,7 @@ function BindLink:AddInputEnded(Keys: {Enum.KeyCode}, Callback: CallbackFunction
|
||||
end
|
||||
end
|
||||
|
||||
function BindLink:KeyHold(Key: Enum.KeyCode): boolean
|
||||
function BindLink:KeyHold(Key)
|
||||
return UIS:IsKeyDown(Key)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user