Camera zoom keybind and starting camera bobbing animations

This commit is contained in:
2023-12-20 17:44:46 -05:00
parent bfca13ed6e
commit b879e5ac85
6 changed files with 141 additions and 76 deletions

View File

@@ -1,7 +1,5 @@
local Binds = {}
local BindsMap = {}
Binds.__index = Binds
BindsMap.__index = BindsMap
local BindLink = {}
BindLink.__index = BindLink
local UIS = game:GetService("UserInputService")
@@ -10,57 +8,64 @@ export type KeyBindMap = {
[Enum.KeyCode]: () -> ()
}
}
function Binds.constructor() --Allow multiple bindings of the same keys, no overwrites
local RegisteredKeys: KeyBindMap = {
Began = {},
Ended = {}
}
return setmetatable({
RegisteredKeys = RegisteredKeys
}, BindsMap)
end
export type InputBegan = RBXScriptConnection
export type InputEnded = RBXScriptConnection
type CallbackFunction = () -> ()
function Binds:Add(Key: Enum.KeyCode, Callback: CallbackFunction)
local k = self.RegisteredKeys[Key]
if k then
warn(`Key "{Key.Name}" is already binded on this KeyBind map`)
function BindLink.constructor() --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 not gameProcessedEvent then
local switch = self.BindMap.Began[input.KeyCode]
if switch then
switch()
else
--switch.default()
end
end
end)
self.InputEnded = UIS.InputEnded:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent then
local switch = self.BindMap.Ended[input.KeyCode]
if switch then
switch()
else
--switch.default()
end
end
end)
return setmetatable(self, BindLink)
end
function BindLink:AddInputBegan(Key: Enum.KeyCode, Callback: CallbackFunction)
if self.BindMap.Began[Key] then
warn(`Key >began< "{Key.Name}" is already binded on this KeyBind map`, debug.traceback())
end
self.RegisteredKeys[Key] = Callback
self.BindMap.Began[Key] = Callback
end
function BindsMap.NewBindState(RegisteredKeys: KeyBindMap)
local InputBegan = UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent then
local switch = RegisteredKeys.Began[input.KeyCode]
if switch then
switch()
else
--switch.default()
end
end
end)
local InputEnded = UIS.InputEnded:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent then
local switch = RegisteredKeys.Ended[input.KeyCode]
if switch then
switch()
else
--switch.default()
end
end
end)
return setmetatable({
--Return these for convenience
InputBegan = InputBegan,
InputEnded = InputEnded
}, BindsMap)
function BindLink:AddInputEnded(Key: Enum.KeyCode, Callback: CallbackFunction)
if self.BindMap.Ended[Key] then
warn(`Key >ended< "{Key.Name}" is already binded on this KeyBind map`, debug.traceback())
end
self.BindMap.Ended[Key] = Callback
end
function BindLink:KeyHold(Key: Enum.KeyCode): boolean
return UIS:IsKeyDown(Key)
end
return Binds
return BindLink

View File

@@ -5,11 +5,7 @@ local TS = game:GetService("TweenService")
type TweenAnimation = {[string]: any}
function Tween.constructor(
TweenSettings: TweenInfo,
Object: Instance | nil,
PreProperties: TweenAnimation | nil
)
function Tween.constructor(TweenSettings: TweenInfo | nil, Object: Instance | nil, PreProperties: TweenAnimation | nil)
return setmetatable({
TweenInfo = TweenSettings,
Instance = Object,
@@ -17,30 +13,30 @@ function Tween.constructor(
}, Tween)
end
function Tween:Start(
PostInstance: Instance | nil,
PostProperties: TweenAnimation | nil,
PostTweenSettings: TweenInfo | nil
): Tween
function Tween:Start(PostInstance: Instance | nil, PostProperties: TweenAnimation | nil, PostTweenSettings: TweenInfo | nil): Tween
local Props = self.PreProperties
local Object = self.Instance
local TweenSettings = self.TweenInfo
if PostProperties and self.PreProperties then
for tween_prop, tween_value in PostProperties do
Props[tween_prop] = tween_value
if PostProperties then
if self.PreProperties then
for tween_prop, tween_value in PostProperties do
Props[tween_prop] = tween_value
end
print("Tween library: Combining PostProperties and PreProperties together", debug.traceback())
else
Props = PostProperties
end
print("Tween library: Combining PostProperties and PreProperties")
end
if PostInstance then
if Object then
print("Tween library: Overwriting an already defined animating object old=", Object, "new=", PostInstance)
print("Tween library: Overwriting an already defined animating object old=", Object, "new=", PostInstance, debug.traceback())
end
Object = PostInstance
end
if PostTweenSettings then
if TweenSettings then
print("Tween library: Overwriting already defined Tween settings")
print("Tween library: Overwriting already defined Tween settings", debug.traceback())
end
TweenSettings = PostTweenSettings
end