mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-18 12:31:54 +00:00
rename everything to .luau extension
This commit is contained in:
78
src/shared/Tween.luau
Normal file
78
src/shared/Tween.luau
Normal file
@@ -0,0 +1,78 @@
|
||||
--!optimize 2
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
--Weird type hack for allowing more than 1 property to be defined inside a tween
|
||||
--Couldnt get type packs working
|
||||
type TweenAnimation<T,U> = {
|
||||
[string]: T | U --I hate "any"
|
||||
}
|
||||
|
||||
type ClassConstructor<T,U> = typeof(setmetatable({} :: Constructor_Return_Props<T,U>, {} :: Impl_Constructor))
|
||||
type Impl_Constructor = {
|
||||
__index: Impl_Constructor,
|
||||
constructor: Constructor_Fun,
|
||||
--Class functions
|
||||
Start: <T,U>(self: ClassConstructor<T,U>, PostInstance: Instance?, PostProperties: TweenAnimation<T,U>?, PostTweenSettings: TweenInfo?) -> Tween,
|
||||
}
|
||||
|
||||
type Constructor_Fun = <T,U>(TweenSettings: TweenInfo?, Object: Instance?, PreProperties: TweenAnimation<T,U>?) -> ClassConstructor<T,U>
|
||||
type Constructor_Return_Props<T,U> = {
|
||||
TweenInfo: TweenInfo?,
|
||||
Instance: Instance?,
|
||||
PreProperties: TweenAnimation<T,U>?,
|
||||
}
|
||||
|
||||
export type TweenClass<T,U> = ClassConstructor<T,U>
|
||||
export type TweenConstructor = Impl_Constructor
|
||||
|
||||
local Tween = {} :: Impl_Constructor
|
||||
Tween.__index = Tween
|
||||
|
||||
local TS = game:GetService("TweenService")
|
||||
|
||||
function Tween.constructor(TweenSettings, Object, PreProperties)
|
||||
return setmetatable({
|
||||
TweenInfo = TweenSettings,
|
||||
Instance = Object,
|
||||
PreProperties = PreProperties
|
||||
}, Tween)
|
||||
end
|
||||
|
||||
function Tween:Start<T,U>(PostInstance, PostProperties, PostTweenSettings)
|
||||
local Props = self.PreProperties
|
||||
local Object = self.Instance
|
||||
local TweenSettings = self.TweenInfo
|
||||
|
||||
if PostProperties then
|
||||
if self.PreProperties then
|
||||
if Props then
|
||||
warn("Tween library: Combining PostProperties and PreProperties together", debug.traceback())
|
||||
for tween_prop, tween_value in PostProperties do
|
||||
Props[tween_prop] = tween_value
|
||||
end
|
||||
end
|
||||
else
|
||||
Props = PostProperties
|
||||
end
|
||||
end
|
||||
if PostInstance then
|
||||
if Object then
|
||||
warn("Tween library: Overwriting an already defined animating object old=", Object, "new=", PostInstance, debug.traceback())
|
||||
end
|
||||
Object = PostInstance
|
||||
end
|
||||
if PostTweenSettings then
|
||||
if TweenSettings then
|
||||
warn("Tween library: Overwriting already defined Tween settings", debug.traceback())
|
||||
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