Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.97 KB | None | 0 0
  1. MODULE = { }
  2.  
  3. local tweenService = game:GetService("TweenService")
  4.  
  5. -- basic tweening
  6. function MODULE.CreateTween(instance, length, style, direction, rep, reverse, del, properties)
  7.     return tweenService:Create(
  8.         instance,
  9.         TweenInfo.new(length, Enum.EasingStyle[style], Enum.EasingDirection[direction], rep, reverse, del),
  10.         properties
  11.     )
  12. end
  13.  
  14. function MODULE.CreateSimpleTween(instance, length, style, direction, properties)
  15.     return tweenService:Create(
  16.         instance,
  17.         TweenInfo.new(length, Enum.EasingStyle[style], Enum.EasingDirection[direction], 0, false, 0),
  18.         properties
  19.     )
  20. end
  21.  
  22. function MODULE.Tween(instance, length, style, direction, rep, reverse, del, properties)
  23.     local tween = tweenService:Create(
  24.         instance,
  25.         TweenInfo.new(length, Enum.EasingStyle[style], Enum.EasingDirection[direction], rep, reverse, del),
  26.         properties
  27.     )
  28.     local done = false
  29.    
  30.     tween.Completed:connect(function()
  31.         done = true
  32.     end)
  33.    
  34.     tween:Play()
  35.    
  36.     while not done do wait() end
  37. end
  38.  
  39. function MODULE.TweenSimple(instance, length, style, direction, properties)
  40.     local tween = tweenService:Create(
  41.         instance,
  42.         TweenInfo.new(length, Enum.EasingStyle[style], Enum.EasingDirection[direction], 0, false, 0),
  43.         properties
  44.     )
  45.     local done = false
  46.    
  47.     tween.Completed:connect(function()
  48.         done = true
  49.     end)
  50.    
  51.     tween:Play()
  52.    
  53.     while not done do wait() end
  54. end
  55.  
  56. function MODULE.TweenAsync(instance, length, style, direction, rep, reverse, del, properties)
  57.     tweenService:Create(
  58.         instance,
  59.         TweenInfo.new(length, Enum.EasingStyle[style], Enum.EasingDirection[direction], rep, reverse, del),
  60.         properties
  61.     ):Play()
  62. end
  63.  
  64. function MODULE.TweenSimpleAsync(instance, length, style, direction, properties)
  65.     tweenService:Create(
  66.         instance,
  67.         TweenInfo.new(length, Enum.EasingStyle[style], Enum.EasingDirection[direction], 0, false, 0),
  68.         properties
  69.     ):Play()
  70. end
  71.  
  72. -- timeline animation
  73. -- waypoint format: { instance, length, style, direction, [repeat, reverse, delay,] async, props }
  74. function i_RunAnimation(self)
  75.     if not self.Running and self.Waypoints and #self.Waypoints > 0 then
  76.         self.Running = true
  77.        
  78.         for index, waypoint in pairs(self.Waypoints) do
  79.             if type(waypoint) == "function" then
  80.                 waypoint()
  81.             elseif type(waypoint) == "table" then
  82.                 if not self.Running then return end
  83.                
  84.                 if #waypoint == 9 then
  85.                     if waypoint[8] then
  86.                         MODULE.TweenAsync(waypoint[1], waypoint[2], waypoint[3], waypoint[4], waypoint[5], waypoint[6], waypoint[7], waypoint[9])
  87.                     else
  88.                         MODULE.Tween(waypoint[1], waypoint[2], waypoint[3], waypoint[4], waypoint[5], waypoint[6], waypoint[7], waypoint[9])
  89.                     end
  90.                 elseif #waypoint == 6 then
  91.                     if waypoint[5] then
  92.                         MODULE.TweenSimpleAsync(waypoint[1], waypoint[2], waypoint[3], waypoint[4], waypoint[6])
  93.                     else
  94.                         MODULE.TweenSimple(waypoint[1], waypoint[2], waypoint[3], waypoint[4], waypoint[6])
  95.                     end
  96.                 else
  97.                     warn("[err]", "Unknown waypoint type or format at index", index .. ".", "(Bad data length)")
  98.                 end
  99.             else
  100.                 warn("[err]", "Unknown waypoint type or format at index", index .. ".", "(Bad type())")
  101.             end
  102.         end
  103.        
  104.         self.Running = false
  105.     end
  106. end
  107.  
  108. function MODULE.CreateAnimation(waypoints)
  109.     local animation = { }
  110.     animation.Waypoints = waypoints and waypoints or { }
  111.     animation.Running = false
  112.    
  113.     animation.Start = function(self, async)
  114.         if async then
  115.             spawn(function()
  116.                 i_RunAnimation(self)
  117.             end)
  118.         else
  119.             i_RunAnimation(self)
  120.         end
  121.     end
  122.    
  123.     animation.SoftStop = function(self)
  124.         self.Running = false
  125.     end
  126.    
  127.     animation.SetWaypoints = function(self, waypoints)
  128.         self.Waypoints = waypoints
  129.     end
  130.    
  131.     animation.AppendWaypoint = function(self, waypoint)
  132.         table.insert(self.Waypoints, waypoint)
  133.     end
  134.    
  135.     animation.InsertWaypoint = function(self, index, waypoint)
  136.         table.insert(self.Waypoints, index, waypoint)
  137.     end
  138.    
  139.     animation.DeleteWaypoint = function(self, index)
  140.         table.remove(self.Waypoints, index)
  141.     end
  142.    
  143.     return animation
  144. end
  145.  
  146. return MODULE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement