@quenty/animations 7.0.0 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [8.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/animations@7.0.0...@quenty/animations@8.0.0) (2024-02-19)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add AnimationPromiseUtils.promiseLoaded(animationTrack) and other helper calls ([5f743bf](https://github.com/Quenty/NevermoreEngine/commit/5f743bf3bc877af91fb91074aa7d4b03d29a09c4))
12
+
13
+
14
+
15
+
16
+
6
17
  # [7.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/animations@6.0.0...@quenty/animations@7.0.0) (2024-02-14)
7
18
 
8
19
  **Note:** Version bump only for package @quenty/animations
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/animations",
3
- "version": "7.0.0",
3
+ "version": "8.0.0",
4
4
  "description": "Utility methods for playing back animations on Roblox",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -40,5 +40,5 @@
40
40
  "publishConfig": {
41
41
  "access": "public"
42
42
  },
43
- "gitHead": "63f949a67b77d3edc98b358cace163da8c789e9f"
43
+ "gitHead": "1258d00e6b21e727109e5eaf99574a06874ca5a6"
44
44
  }
@@ -4,12 +4,23 @@
4
4
 
5
5
  local require = require(script.Parent.loader).load(script)
6
6
 
7
+ local RunService = game:GetService("RunService")
8
+
7
9
  local Promise = require("Promise")
8
10
  local PromiseMaidUtils = require("PromiseMaidUtils")
9
11
 
10
12
  local AnimationPromiseUtils = {}
11
13
 
14
+ --[=[
15
+ Promises that the track is finished
16
+
17
+ @param animationTrack AnimationTrack
18
+ @param endMarkerName string | nil
19
+ @return Promise
20
+ ]=]
12
21
  function AnimationPromiseUtils.promiseFinished(animationTrack, endMarkerName)
22
+ assert(typeof(animationTrack) == "Instance", "Bad animationTrack")
23
+ assert(type(endMarkerName) == "string" or endMarkerName == nil, "Bad endMarkerName")
13
24
  local promise = Promise.new()
14
25
 
15
26
  PromiseMaidUtils.whilePromise(promise, function(maid)
@@ -35,4 +46,83 @@ function AnimationPromiseUtils.promiseFinished(animationTrack, endMarkerName)
35
46
  return promise
36
47
  end
37
48
 
49
+ --[=[
50
+ Promises that the track has been loaded
51
+
52
+ @param animationTrack AnimationTrack
53
+ @return Promise
54
+ ]=]
55
+ function AnimationPromiseUtils.promiseLoaded(animationTrack)
56
+ assert(typeof(animationTrack) == "Instance", "Bad animationTrack")
57
+
58
+ if animationTrack.Length > 0 then
59
+ return Promise.resolved()
60
+ end
61
+
62
+ local promise = Promise.new()
63
+
64
+ PromiseMaidUtils.whilePromise(promise, function(maid)
65
+ maid:GiveTask(animationTrack:GetPropertyChangedSignal("Length"):Connect(function()
66
+ if animationTrack.Length > 0 then
67
+ promise:Resolve()
68
+ end
69
+ end))
70
+
71
+ maid:GiveTask(RunService.Stepped:Connect(function()
72
+ if animationTrack.Length > 0 then
73
+ promise:Resolve()
74
+ end
75
+ end))
76
+
77
+ maid:GiveTask(animationTrack.Ended:Connect(function()
78
+ promise:Resolve()
79
+ end))
80
+
81
+ maid:GiveTask(animationTrack.Stopped:Connect(function()
82
+ promise:Resolve()
83
+ end))
84
+
85
+ maid:GiveTask(animationTrack.Destroying:Connect(function()
86
+ promise:Resolve()
87
+ end))
88
+ end)
89
+
90
+ return promise
91
+ end
92
+
93
+ --[=[
94
+ Promises that the track reached a keyframe or is finished
95
+
96
+ @param animationTrack AnimationTrack
97
+ @param keyframeName string
98
+ @return Promise
99
+ ]=]
100
+ function AnimationPromiseUtils.promiseKeyframeReached(animationTrack, keyframeName)
101
+ assert(typeof(animationTrack) == "Instance", "Bad animationTrack")
102
+ assert(type(keyframeName) == "string", "Bad endMarkerName")
103
+
104
+ local promise = Promise.new()
105
+
106
+ PromiseMaidUtils.whilePromise(promise, function(maid)
107
+ maid:GiveTask(animationTrack.Ended:Connect(function()
108
+ promise:Resolve()
109
+ end))
110
+
111
+ maid:GiveTask(animationTrack.Stopped:Connect(function()
112
+ promise:Resolve()
113
+ end))
114
+
115
+ maid:GiveTask(animationTrack.Destroying:Connect(function()
116
+ promise:Resolve()
117
+ end))
118
+
119
+ maid:GiveTask(animationTrack:GetMarkerReachedSignal(keyframeName):Connect(function()
120
+ promise:Resolve()
121
+ end))
122
+ end)
123
+
124
+ return promise
125
+ end
126
+
127
+
38
128
  return AnimationPromiseUtils
@@ -17,20 +17,12 @@ AnimationTrackPlayer.__index = AnimationTrackPlayer
17
17
  function AnimationTrackPlayer.new(animationTarget, animationId)
18
18
  local self = setmetatable(BaseObject.new(), AnimationTrackPlayer)
19
19
 
20
- self._animationTarget = ValueObject.new(nil)
21
- self._maid:GiveTask(self._animationTarget)
20
+ self._animationTarget = self._maid:Add(ValueObject.new(nil))
21
+ self._trackId = self._maid:Add(ValueObject.new(nil))
22
+ self._currentTrack = self._maid:Add(ValueObject.new(nil))
23
+ self._animationPriority = self._maid:Add(ValueObject.new(nil))
22
24
 
23
- self._trackId = ValueObject.new(nil)
24
- self._maid:GiveTask(self._trackId)
25
-
26
- self._currentTrack = ValueObject.new(nil)
27
- self._maid:GiveTask(self._currentTrack)
28
-
29
- self.KeyframeReached = Signal.new()
30
- self._maid:GiveTask(self.KeyframeReached)
31
-
32
- self._animationPriority = ValueObject.new(nil)
33
- self._maid:GiveTask(self._animationPriority)
25
+ self.KeyframeReached = self._maid:Add(Signal.new())
34
26
 
35
27
  if animationTarget then
36
28
  self:SetAnimationTarget(animationTarget)