UDP flashlight working and fix some type errors

This commit is contained in:
2024-03-02 02:58:45 -05:00
parent dd5677daa0
commit 0d08e341b2
13 changed files with 158 additions and 132 deletions

View File

@@ -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