mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 23:01:53 +00:00
UDP flashlight working and fix some type errors
This commit is contained in:
@@ -7,37 +7,34 @@
|
||||
local BindLink = {}
|
||||
BindLink.__index = BindLink
|
||||
|
||||
local UIS = game:GetService("UserInputService")
|
||||
|
||||
export type KeyBindMap = {
|
||||
[string]: {
|
||||
[Enum.KeyCode]: () -> ()
|
||||
[Enum.KeyCode]: (KeyPressed: Enum.KeyCode) -> ()
|
||||
}
|
||||
}
|
||||
export type InputBegan = RBXScriptConnection
|
||||
export type InputEnded = RBXScriptConnection
|
||||
|
||||
type CallbackFunction = () -> ()
|
||||
type BindConstructor = {
|
||||
BindMap: KeyBindMap,
|
||||
InputBegan: InputBegan,
|
||||
InputEnded: InputEnded
|
||||
}
|
||||
|
||||
local UIS = game:GetService("UserInputService")
|
||||
|
||||
function BindLink.constructor(gameProcessing: boolean) --Allow multiple bindings of the same keys, no overwrites
|
||||
type BindConstructor = {
|
||||
BindMap: KeyBindMap,
|
||||
InputBegan: InputBegan,
|
||||
InputEnded: InputEnded
|
||||
}
|
||||
|
||||
local self = {} :: BindConstructor
|
||||
self.BindMap = {
|
||||
Began = {},
|
||||
Ended = {}
|
||||
}
|
||||
|
||||
--Return these for convenience
|
||||
self.InputBegan = UIS.InputBegan:Connect(function(input, gameProcessedEvent)
|
||||
if gameProcessing and gameProcessedEvent or not gameProcessedEvent then
|
||||
local switch = self.BindMap.Began[input.KeyCode]
|
||||
if switch then
|
||||
switch()
|
||||
switch(input.KeyCode)
|
||||
else
|
||||
--switch.default()
|
||||
end
|
||||
@@ -47,7 +44,7 @@ function BindLink.constructor(gameProcessing: boolean) --Allow multiple bindings
|
||||
if gameProcessing and gameProcessedEvent or not gameProcessedEvent then
|
||||
local switch = self.BindMap.Ended[input.KeyCode]
|
||||
if switch then
|
||||
switch()
|
||||
switch(input.KeyCode)
|
||||
else
|
||||
--switch.default()
|
||||
end
|
||||
@@ -60,7 +57,6 @@ end
|
||||
function BindLink:AddInputBegan(Keys: {Enum.KeyCode}, Callback: CallbackFunction)
|
||||
for i = 1, #Keys do
|
||||
local Key = Keys[i]
|
||||
|
||||
if self.BindMap.Began[Key] then
|
||||
warn(`Key >began< "{Key.Name}" is already binded on this KeyBind map`, debug.traceback())
|
||||
end
|
||||
@@ -71,7 +67,6 @@ end
|
||||
function BindLink:AddInputEnded(Keys: {Enum.KeyCode}, Callback: CallbackFunction)
|
||||
for i = 1, #Keys do
|
||||
local Key = Keys[i]
|
||||
|
||||
if self.BindMap.Ended[Key] then
|
||||
warn(`Key >ended< "{Key.Name}" is already binded on this KeyBind map`, debug.traceback())
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user