Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MODULE = { }
- local tweenService = game:GetService("TweenService")
- -- basic tweening
- function MODULE.CreateTween(instance, length, style, direction, rep, reverse, del, properties)
- return tweenService:Create(
- instance,
- TweenInfo.new(length, Enum.EasingStyle[style], Enum.EasingDirection[direction], rep, reverse, del),
- properties
- )
- end
- function MODULE.CreateSimpleTween(instance, length, style, direction, properties)
- return tweenService:Create(
- instance,
- TweenInfo.new(length, Enum.EasingStyle[style], Enum.EasingDirection[direction], 0, false, 0),
- properties
- )
- end
- function MODULE.Tween(instance, length, style, direction, rep, reverse, del, properties)
- local tween = tweenService:Create(
- instance,
- TweenInfo.new(length, Enum.EasingStyle[style], Enum.EasingDirection[direction], rep, reverse, del),
- properties
- )
- local done = false
- tween.Completed:connect(function()
- done = true
- end)
- tween:Play()
- while not done do wait() end
- end
- function MODULE.TweenSimple(instance, length, style, direction, properties)
- local tween = tweenService:Create(
- instance,
- TweenInfo.new(length, Enum.EasingStyle[style], Enum.EasingDirection[direction], 0, false, 0),
- properties
- )
- local done = false
- tween.Completed:connect(function()
- done = true
- end)
- tween:Play()
- while not done do wait() end
- end
- function MODULE.TweenAsync(instance, length, style, direction, rep, reverse, del, properties)
- tweenService:Create(
- instance,
- TweenInfo.new(length, Enum.EasingStyle[style], Enum.EasingDirection[direction], rep, reverse, del),
- properties
- ):Play()
- end
- function MODULE.TweenSimpleAsync(instance, length, style, direction, properties)
- tweenService:Create(
- instance,
- TweenInfo.new(length, Enum.EasingStyle[style], Enum.EasingDirection[direction], 0, false, 0),
- properties
- ):Play()
- end
- -- timeline animation
- -- waypoint format: { instance, length, style, direction, [repeat, reverse, delay,] async, props }
- function i_RunAnimation(self)
- if not self.Running and self.Waypoints and #self.Waypoints > 0 then
- self.Running = true
- for index, waypoint in pairs(self.Waypoints) do
- if type(waypoint) == "function" then
- waypoint()
- elseif type(waypoint) == "table" then
- if not self.Running then return end
- if #waypoint == 9 then
- if waypoint[8] then
- MODULE.TweenAsync(waypoint[1], waypoint[2], waypoint[3], waypoint[4], waypoint[5], waypoint[6], waypoint[7], waypoint[9])
- else
- MODULE.Tween(waypoint[1], waypoint[2], waypoint[3], waypoint[4], waypoint[5], waypoint[6], waypoint[7], waypoint[9])
- end
- elseif #waypoint == 6 then
- if waypoint[5] then
- MODULE.TweenSimpleAsync(waypoint[1], waypoint[2], waypoint[3], waypoint[4], waypoint[6])
- else
- MODULE.TweenSimple(waypoint[1], waypoint[2], waypoint[3], waypoint[4], waypoint[6])
- end
- else
- warn("[err]", "Unknown waypoint type or format at index", index .. ".", "(Bad data length)")
- end
- else
- warn("[err]", "Unknown waypoint type or format at index", index .. ".", "(Bad type())")
- end
- end
- self.Running = false
- end
- end
- function MODULE.CreateAnimation(waypoints)
- local animation = { }
- animation.Waypoints = waypoints and waypoints or { }
- animation.Running = false
- animation.Start = function(self, async)
- if async then
- spawn(function()
- i_RunAnimation(self)
- end)
- else
- i_RunAnimation(self)
- end
- end
- animation.SoftStop = function(self)
- self.Running = false
- end
- animation.SetWaypoints = function(self, waypoints)
- self.Waypoints = waypoints
- end
- animation.AppendWaypoint = function(self, waypoint)
- table.insert(self.Waypoints, waypoint)
- end
- animation.InsertWaypoint = function(self, index, waypoint)
- table.insert(self.Waypoints, index, waypoint)
- end
- animation.DeleteWaypoint = function(self, index)
- table.remove(self.Waypoints, index)
- end
- return animation
- end
- return MODULE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement