Skip to content

Commit a7ee25d

Browse files
committed
v1.1.0
- Allow new tweens to override existing/already-playing ones - Fix `Enum.PlaybackState` not being set to `Playing` if `DelayTime` parameter of `TweenInfo` was used
1 parent 110e913 commit a7ee25d

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
sourcemap.json

release.rbxm

250 Bytes
Binary file not shown.

src/init.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ end
3838
local MethodTween = {}
3939
MethodTween.__index = MethodTween
4040

41+
local activeTweens = setmetatable({}, {
42+
__mode = "v",
43+
})
4144
function MethodTween.new(instance: Instance, tweenInfo: TweenInfo, propertyTable: {[string]: {any}})
4245
for _, propData in propertyTable do
4346
local initialValue, finalValue = propData[1], propData[2]
@@ -60,14 +63,27 @@ function MethodTween.new(instance: Instance, tweenInfo: TweenInfo, propertyTable
6063
end
6164

6265
function MethodTween:Play()
66+
if activeTweens[self.Instance] then
67+
activeTweens[self.Instance]:Cancel()
68+
end
6369
self:_stop()
6470

6571
if self.PlaybackState ~= Enum.PlaybackState.Paused then
6672
self._time = 0
6773
end
74+
--[[
75+
I could set this to only Delayed since it's set to Playing in the delayed thread, but then the following could occur:
76+
```lua
77+
local tween = MethodTween.new(...)
78+
tween:Play()
79+
print(tween.PlaybackState) -- Delayed
80+
```
81+
]]
82+
activeTweens[self.Instance] = self
6883
self.PlaybackState = self.TweenInfo.DelayTime > 0 and Enum.PlaybackState.Delayed or Enum.PlaybackState.Playing
6984

7085
self._delayedThread = task.delay(self.TweenInfo.DelayTime, function()
86+
self.PlaybackState = Enum.PlaybackState.Playing
7187
local initialValues = {}
7288
for name, propData in self._propertyTable do
7389
initialValues[name] = propData[1]
@@ -109,6 +125,7 @@ function MethodTween:Play()
109125
end)
110126
end
111127
function MethodTween:_stop()
128+
activeTweens[self.Instance] = nil
112129
if self._updateConnection then
113130
self._updateConnection:Disconnect()
114131
self._updateConnection = nil

0 commit comments

Comments
 (0)