mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 14:51:55 +00:00
Tween module and KeyBinds module
This commit is contained in:
@@ -1,34 +1,66 @@
|
|||||||
local Binds = {}
|
local Binds = {}
|
||||||
|
local BindsMap = {}
|
||||||
Binds.__index = Binds
|
Binds.__index = Binds
|
||||||
|
|
||||||
local BindsMap = {
|
|
||||||
Keys = {}
|
|
||||||
}
|
|
||||||
BindsMap.__index = BindsMap
|
BindsMap.__index = BindsMap
|
||||||
|
|
||||||
local UIS = game:GetService("UserInputService")
|
local UIS = game:GetService("UserInputService")
|
||||||
|
|
||||||
|
export type KeyBindMap = {
|
||||||
|
[string]: {
|
||||||
|
[Enum.KeyCode]: () -> ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function Binds.constructor() --Allow multiple bindings of the same keys, no overwrites
|
function Binds.constructor() --Allow multiple bindings of the same keys, no overwrites
|
||||||
return setmetatable({}, BindsMap)
|
local RegisteredKeys: KeyBindMap = {
|
||||||
|
Began = {},
|
||||||
|
Ended = {}
|
||||||
|
}
|
||||||
|
return setmetatable({
|
||||||
|
RegisteredKeys = RegisteredKeys
|
||||||
|
}, BindsMap)
|
||||||
end
|
end
|
||||||
|
|
||||||
function BindsMap.new()
|
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`)
|
||||||
|
end
|
||||||
|
self.RegisteredKeys[Key] = Callback
|
||||||
|
end
|
||||||
|
|
||||||
|
function BindsMap.NewBindState(RegisteredKeys: KeyBindMap)
|
||||||
local InputBegan = UIS.InputBegan:Connect(function(input, gameProcessedEvent)
|
local InputBegan = UIS.InputBegan:Connect(function(input, gameProcessedEvent)
|
||||||
if not gameProcessedEvent then
|
if not gameProcessedEvent then
|
||||||
|
local switch = RegisteredKeys.Began[input.KeyCode]
|
||||||
|
if switch then
|
||||||
|
switch()
|
||||||
|
else
|
||||||
|
--switch.default()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local InputEnded = UIS.InputEnded:Connect(function(input, gameProcessedEvent)
|
local InputEnded = UIS.InputEnded:Connect(function(input, gameProcessedEvent)
|
||||||
if not gameProcessedEvent then
|
if not gameProcessedEvent then
|
||||||
|
local switch = RegisteredKeys.Ended[input.KeyCode]
|
||||||
|
if switch then
|
||||||
|
switch()
|
||||||
|
else
|
||||||
|
--switch.default()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
return setmetatable({
|
return setmetatable({
|
||||||
|
--Return these for convenience
|
||||||
InputBegan = InputBegan,
|
InputBegan = InputBegan,
|
||||||
InputEnded = InputEnded
|
InputEnded = InputEnded
|
||||||
}, BindsMap)
|
}, BindsMap)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return Binds
|
return Binds
|
||||||
54
src/shared/Tween.lua
Normal file
54
src/shared/Tween.lua
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
local Tween = {}
|
||||||
|
Tween.__index = Tween
|
||||||
|
|
||||||
|
local TS = game:GetService("TweenService")
|
||||||
|
|
||||||
|
type TweenAnimation = {[string]: any}
|
||||||
|
|
||||||
|
function Tween.constructor(
|
||||||
|
TweenSettings: TweenInfo,
|
||||||
|
Object: Instance | nil,
|
||||||
|
PreProperties: TweenAnimation | nil
|
||||||
|
)
|
||||||
|
return setmetatable({
|
||||||
|
TweenInfo = TweenSettings,
|
||||||
|
Instance = Object,
|
||||||
|
PreProperties = PreProperties
|
||||||
|
}, Tween)
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
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)
|
||||||
|
end
|
||||||
|
Object = PostInstance
|
||||||
|
end
|
||||||
|
if PostTweenSettings then
|
||||||
|
if TweenSettings then
|
||||||
|
print("Tween library: Overwriting already defined Tween settings")
|
||||||
|
end
|
||||||
|
TweenSettings = PostTweenSettings
|
||||||
|
end
|
||||||
|
|
||||||
|
local Animation = TS:Create(Object, TweenSettings, Props)
|
||||||
|
Animation:Play()
|
||||||
|
|
||||||
|
return Animation
|
||||||
|
end
|
||||||
|
|
||||||
|
return Tween
|
||||||
Reference in New Issue
Block a user