@quenty/animations 8.17.2 → 8.17.3

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,14 @@
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.17.3](https://github.com/Quenty/NevermoreEngine/compare/@quenty/animations@8.17.2...@quenty/animations@8.17.3) (2025-04-10)
7
+
8
+ **Note:** Version bump only for package @quenty/animations
9
+
10
+
11
+
12
+
13
+
6
14
  ## [8.17.2](https://github.com/Quenty/NevermoreEngine/compare/@quenty/animations@8.17.0...@quenty/animations@8.17.2) (2025-04-07)
7
15
 
8
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/animations",
3
- "version": "8.17.2",
3
+ "version": "8.17.3",
4
4
  "description": "Utility methods for playing back animations on Roblox",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -25,20 +25,20 @@
25
25
  "Quenty"
26
26
  ],
27
27
  "dependencies": {
28
- "@quenty/baseobject": "^10.8.2",
28
+ "@quenty/baseobject": "^10.8.3",
29
29
  "@quenty/enumutils": "^3.4.2",
30
30
  "@quenty/humanoidanimatorutils": "^3.1.2",
31
- "@quenty/loader": "^10.8.2",
32
- "@quenty/maid": "^3.4.2",
33
- "@quenty/promise": "^10.10.3",
34
- "@quenty/promisemaid": "^5.10.3",
35
- "@quenty/rbxasset": "^5.8.2",
36
- "@quenty/rx": "^13.17.2",
37
- "@quenty/signal": "^7.10.2",
38
- "@quenty/valueobject": "^13.17.2"
31
+ "@quenty/loader": "^10.8.3",
32
+ "@quenty/maid": "^3.4.3",
33
+ "@quenty/promise": "^10.10.4",
34
+ "@quenty/promisemaid": "^5.10.4",
35
+ "@quenty/rbxasset": "^5.8.3",
36
+ "@quenty/rx": "^13.17.3",
37
+ "@quenty/signal": "^7.10.3",
38
+ "@quenty/valueobject": "^13.17.3"
39
39
  },
40
40
  "publishConfig": {
41
41
  "access": "public"
42
42
  },
43
- "gitHead": "64def70499ec067077ee39f279936b620b217847"
43
+ "gitHead": "b06c070ae91d5dab7bd8de6e290ad2caabb15d8f"
44
44
  }
@@ -1,3 +1,4 @@
1
+ --!strict
1
2
  --[=[
2
3
  Acts as a priority slot which can be overridden and play any animation in.
3
4
  See Roblox's animation system for more information.
@@ -18,14 +19,26 @@ local AnimationSlotPlayer = setmetatable({}, BaseObject)
18
19
  AnimationSlotPlayer.ClassName = "AnimationSlotPlayer"
19
20
  AnimationSlotPlayer.__index = AnimationSlotPlayer
20
21
 
22
+ export type AnimationSlotPlayer = typeof(setmetatable(
23
+ {} :: {
24
+ _maid: Maid.Maid,
25
+ _animationTarget: ValueObject.ValueObject<Instance>,
26
+ _defaultFadeTime: ValueObject.ValueObject<number>,
27
+ _defaultAnimationPriority: ValueObject.ValueObject<Enum.AnimationPriority>,
28
+ _currentAnimationTrackData: ValueObject.ValueObject<any>,
29
+ _currentAnimationId: ValueObject.ValueObject<string>,
30
+ },
31
+ {} :: typeof({ __index = AnimationSlotPlayer })
32
+ )) & BaseObject.BaseObject
33
+
21
34
  --[=[
22
35
  Creates a new AnimationSlotPlayer with a target to play the animation on.
23
36
 
24
37
  @param animationTarget Instance? | Observable<Instance>
25
38
  @return AnimationSlotPlayer
26
39
  ]=]
27
- function AnimationSlotPlayer.new(animationTarget)
28
- local self = setmetatable(BaseObject.new(), AnimationSlotPlayer)
40
+ function AnimationSlotPlayer.new(animationTarget): AnimationSlotPlayer
41
+ local self: AnimationSlotPlayer = setmetatable(BaseObject.new() :: any, AnimationSlotPlayer)
29
42
 
30
43
  self._animationTarget = self._maid:Add(ValueObject.new(nil))
31
44
  self._defaultFadeTime = self._maid:Add(ValueObject.new(0.1, "number"))
@@ -45,7 +58,7 @@ end
45
58
 
46
59
  @param defaultFadeTime number
47
60
  ]=]
48
- function AnimationSlotPlayer:SetDefaultFadeTime(defaultFadeTime: number)
61
+ function AnimationSlotPlayer.SetDefaultFadeTime(self: AnimationSlotPlayer, defaultFadeTime: number)
49
62
  self._defaultFadeTime.Value = defaultFadeTime
50
63
  end
51
64
 
@@ -54,8 +67,11 @@ end
54
67
 
55
68
  @param defaultAnimationPriority number
56
69
  ]=]
57
- function AnimationSlotPlayer:SetDefaultAnimationPriority(defaultAnimationPriority)
58
- assert(EnumUtils.isOfType(Enum.AnimationPriority, defaultAnimationPriority) or defaultAnimationPriority == nil, "Bad defaultAnimationPriority")
70
+ function AnimationSlotPlayer.SetDefaultAnimationPriority(self: AnimationSlotPlayer, defaultAnimationPriority)
71
+ assert(
72
+ EnumUtils.isOfType(Enum.AnimationPriority, defaultAnimationPriority) or defaultAnimationPriority == nil,
73
+ "Bad defaultAnimationPriority"
74
+ )
59
75
 
60
76
  self._defaultAnimationPriority.Value = defaultAnimationPriority
61
77
  end
@@ -65,10 +81,18 @@ end
65
81
 
66
82
  @param animationTarget Instance | Observable<Instance>
67
83
  ]=]
68
- function AnimationSlotPlayer:SetAnimationTarget(animationTarget)
84
+ function AnimationSlotPlayer.SetAnimationTarget(self: AnimationSlotPlayer, animationTarget)
69
85
  self._animationTarget:Mount(animationTarget)
70
86
  end
71
87
 
88
+ type AnimationData = {
89
+ animationId: string,
90
+ track: AnimationTrack,
91
+ originalSpeed: number?,
92
+ originalWeight: number?,
93
+ originalPriority: Enum.AnimationPriority?,
94
+ }
95
+
72
96
  --[=[
73
97
  Adjusts the speed of the animation playing in the slot
74
98
 
@@ -76,7 +100,7 @@ end
76
100
  @param speed number
77
101
  @return () -> () -- Callback to clean things up
78
102
  ]=]
79
- function AnimationSlotPlayer:AdjustSpeed(id: string | number, speed: number)
103
+ function AnimationSlotPlayer.AdjustSpeed(self: AnimationSlotPlayer, id: string | number, speed: number)
80
104
  assert(RbxAssetUtils.isConvertableToRbxAsset(id), "Bad id")
81
105
  assert(type(speed) == "number", "Bad speed")
82
106
 
@@ -84,8 +108,9 @@ function AnimationSlotPlayer:AdjustSpeed(id: string | number, speed: number)
84
108
 
85
109
  local topMaid = Maid.new()
86
110
 
111
+ -- stylua: ignore
87
112
  topMaid:GiveTask(self._currentAnimationTrackData
88
- :ObserveBrio(function(data)
113
+ :ObserveBrio(function(data: AnimationData)
89
114
  return data and data.animationId == animationId
90
115
  end)
91
116
  :Subscribe(function(brio)
@@ -93,7 +118,7 @@ function AnimationSlotPlayer:AdjustSpeed(id: string | number, speed: number)
93
118
  return
94
119
  end
95
120
 
96
- local data = brio:GetValue()
121
+ local data: AnimationData = brio:GetValue()
97
122
  local maid = brio:ToMaid()
98
123
 
99
124
  data.track:AdjustSpeed(speed)
@@ -111,7 +136,7 @@ function AnimationSlotPlayer:AdjustSpeed(id: string | number, speed: number)
111
136
  self._maid._currentSpeedAdjustment = topMaid
112
137
 
113
138
  return function()
114
- if self._maid._currentSpeedAdjustment == topMaid then
139
+ if self._maid._currentSpeedAdjustment :: any == topMaid then
115
140
  self._maid._currentSpeedAdjustment = nil
116
141
  end
117
142
  end
@@ -125,7 +150,7 @@ end
125
150
  @param fadeTime number?
126
151
  @return () -> () -- Callback to clean things up
127
152
  ]=]
128
- function AnimationSlotPlayer:AdjustWeight(id: string, weight: number, fadeTime: number?)
153
+ function AnimationSlotPlayer.AdjustWeight(self: AnimationSlotPlayer, id: string, weight: number, fadeTime: number?)
129
154
  assert(RbxAssetUtils.isConvertableToRbxAsset(id), "Bad id")
130
155
  assert(type(weight) == "number", "Bad weight")
131
156
  assert(type(fadeTime) == "number" or fadeTime == nil, "Bad fadeTime")
@@ -134,6 +159,7 @@ function AnimationSlotPlayer:AdjustWeight(id: string, weight: number, fadeTime:
134
159
 
135
160
  local topMaid = Maid.new()
136
161
 
162
+ -- stylua: ignore
137
163
  topMaid:GiveTask(self._currentAnimationTrackData
138
164
  :ObserveBrio(function(data)
139
165
  return data and data.animationId == animationId
@@ -143,7 +169,7 @@ function AnimationSlotPlayer:AdjustWeight(id: string, weight: number, fadeTime:
143
169
  return
144
170
  end
145
171
 
146
- local data = brio:GetValue()
172
+ local data: AnimationData = brio:GetValue()
147
173
  local maid = brio:ToMaid()
148
174
 
149
175
  data.track:AdjustWeight(weight, fadeTime)
@@ -161,7 +187,7 @@ function AnimationSlotPlayer:AdjustWeight(id: string, weight: number, fadeTime:
161
187
  self._maid._currentWeightAdjustment = topMaid
162
188
 
163
189
  return function()
164
- if self._maid._currentWeightAdjustment == topMaid then
190
+ if self._maid._currentWeightAdjustment :: any == topMaid then
165
191
  self._maid._currentWeightAdjustment = nil
166
192
  end
167
193
  end
@@ -177,7 +203,14 @@ end
177
203
  @param priority Enum.AnimationPriority?
178
204
  @return () -> () -- Callback to clean things up
179
205
  ]=]
180
- function AnimationSlotPlayer:Play(id: string | number, fadeTime: number?, weight: number?, speed: number?, priority: Enum.AnimationPriority?): () -> ()
206
+ function AnimationSlotPlayer.Play(
207
+ self: AnimationSlotPlayer,
208
+ id: string | number,
209
+ fadeTime: number?,
210
+ weight: number?,
211
+ speed: number?,
212
+ priority: Enum.AnimationPriority?
213
+ ): () -> ()
181
214
  fadeTime = fadeTime or self._defaultFadeTime.Value
182
215
  priority = priority or self._defaultAnimationPriority.Value
183
216
  weight = weight or 1 -- We need to explicitly adjust the weight here
@@ -186,45 +219,47 @@ function AnimationSlotPlayer:Play(id: string | number, fadeTime: number?, weight
186
219
 
187
220
  local animationId = RbxAssetUtils.toRbxAssetId(id)
188
221
 
189
- topMaid:GiveTask(self._animationTarget:ObserveBrio(function(target)
190
- return target ~= nil
191
- end):Subscribe(function(brio)
192
- if brio:IsDead() then
193
- return
194
- end
195
-
196
- local animationTarget = brio:GetValue()
197
- local maid = brio:ToMaid()
198
-
199
- local track = AnimationUtils.playAnimation(animationTarget, animationId, fadeTime, weight, speed, priority)
200
- if track then
201
- local data = {
202
- animationId = animationId;
203
- track = track;
204
- originalSpeed = speed;
205
- originalWeight = weight;
206
- originalPriority = priority;
207
- }
222
+ topMaid:GiveTask(self._animationTarget
223
+ :ObserveBrio(function(target)
224
+ return target ~= nil
225
+ end)
226
+ :Subscribe(function(brio)
227
+ if brio:IsDead() then
228
+ return
229
+ end
208
230
 
209
- self._currentAnimationTrackData.Value = data
210
- maid:GiveTask(function()
211
- if self._currentAnimationTrackData.Value == data then
212
- self._currentAnimationTrackData.Value = nil
213
- end
214
- end)
231
+ local animationTarget: any = brio:GetValue()
232
+ local maid = brio:ToMaid()
215
233
 
216
- maid:GiveTask(function()
217
- track:AdjustWeight(0, fadeTime or self._defaultFadeTime.Value)
218
- end)
219
- else
220
- warn("[AnimationSlotPlayer] - Failed to get animation to play")
221
- end
222
- end))
234
+ local track = AnimationUtils.playAnimation(animationTarget, animationId, fadeTime, weight, speed, priority)
235
+ if track then
236
+ local data = {
237
+ animationId = animationId,
238
+ track = track,
239
+ originalSpeed = speed,
240
+ originalWeight = weight,
241
+ originalPriority = priority,
242
+ }
243
+
244
+ self._currentAnimationTrackData.Value = data
245
+ maid:GiveTask(function()
246
+ if self._currentAnimationTrackData.Value == data then
247
+ self._currentAnimationTrackData.Value = nil
248
+ end
249
+ end)
250
+
251
+ maid:GiveTask(function()
252
+ track:AdjustWeight(0, fadeTime or self._defaultFadeTime.Value)
253
+ end)
254
+ else
255
+ warn("[AnimationSlotPlayer] - Failed to get animation to play")
256
+ end
257
+ end))
223
258
 
224
259
  self._maid._current = topMaid
225
260
 
226
261
  return function()
227
- if self._maid._current == topMaid then
262
+ if self._maid._current :: any == topMaid then
228
263
  self._maid._current = nil
229
264
  end
230
265
  end
@@ -233,7 +268,7 @@ end
233
268
  --[=[
234
269
  Stops the current animation playing
235
270
  ]=]
236
- function AnimationSlotPlayer:Stop()
271
+ function AnimationSlotPlayer.Stop(self: AnimationSlotPlayer)
237
272
  self._maid._current = nil
238
273
  end
239
274
 
@@ -17,6 +17,20 @@ local AnimationTrackPlayer = setmetatable({}, BaseObject)
17
17
  AnimationTrackPlayer.ClassName = "AnimationTrackPlayer"
18
18
  AnimationTrackPlayer.__index = AnimationTrackPlayer
19
19
 
20
+ export type AnimationTrackPlayer = typeof(setmetatable(
21
+ {} :: {
22
+ -- Public
23
+ KeyframeReached: Signal.Signal<()>,
24
+
25
+ -- Private
26
+ _animationTarget: ValueObject.ValueObject<Instance>,
27
+ _trackId: ValueObject.ValueObject<string | number>,
28
+ _currentTrack: ValueObject.ValueObject<AnimationTrack?>,
29
+ _animationPriority: ValueObject.ValueObject<number>,
30
+ },
31
+ {} :: typeof({ __index = AnimationTrackPlayer })
32
+ )) & BaseObject.BaseObject
33
+
20
34
  --[=[
21
35
  Plays an animation track in the target. Async loads the track when
22
36
  all data is found.
@@ -25,8 +39,8 @@ AnimationTrackPlayer.__index = AnimationTrackPlayer
25
39
  @param animationId string | number?
26
40
  @return AnimationTrackPlayer
27
41
  ]=]
28
- function AnimationTrackPlayer.new(animationTarget, animationId)
29
- local self = setmetatable(BaseObject.new() :: any, AnimationTrackPlayer)
42
+ function AnimationTrackPlayer.new(animationTarget, animationId: string | number): AnimationTrackPlayer
43
+ local self: AnimationTrackPlayer = setmetatable(BaseObject.new() :: any, AnimationTrackPlayer)
30
44
 
31
45
  self._animationTarget = self._maid:Add(ValueObject.new(nil))
32
46
  self._trackId = self._maid:Add(ValueObject.new(nil))
@@ -50,33 +64,41 @@ end
50
64
 
51
65
  function AnimationTrackPlayer:_setupState()
52
66
  self._maid:GiveTask(Rx.combineLatest({
53
- animationTarget = self._animationTarget:Observe();
54
- trackId = self._trackId:Observe();
55
- animationPriority = self._animationPriority:Observe();
56
- }):Pipe({
57
- Rx.throttleDefer();
58
- }):Subscribe(function(state)
59
- if state.animationTarget and state.trackId then
60
- self._currentTrack.Value = AnimationUtils.getOrCreateAnimationTrack(state.animationTarget, state.trackId, state.animationPriority)
61
- else
62
- self._currentTrack.Value = nil
63
- end
64
- end))
65
-
66
- self._maid:GiveTask(self._currentTrack:ObserveBrio(function(track)
67
- return track ~= nil
68
- end):Subscribe(function(brio)
69
- if brio:IsDead() then
70
- return
71
- end
72
-
73
- local maid = brio:ToMaid()
74
- local track = brio:GetValue()
67
+ animationTarget = self._animationTarget:Observe(),
68
+ trackId = self._trackId:Observe(),
69
+ animationPriority = self._animationPriority:Observe(),
70
+ })
71
+ :Pipe({
72
+ Rx.throttleDefer() :: any,
73
+ })
74
+ :Subscribe(function(state)
75
+ if state.animationTarget and state.trackId then
76
+ self._currentTrack.Value = AnimationUtils.getOrCreateAnimationTrack(
77
+ state.animationTarget,
78
+ state.trackId,
79
+ state.animationPriority
80
+ )
81
+ else
82
+ self._currentTrack.Value = nil
83
+ end
84
+ end))
75
85
 
76
- maid:GiveTask(track.KeyframeReached:Connect(function(...)
77
- self.KeyframeReached:Fire(...)
86
+ self._maid:GiveTask(self._currentTrack
87
+ :ObserveBrio(function(track)
88
+ return track ~= nil
89
+ end)
90
+ :Subscribe(function(brio)
91
+ if brio:IsDead() then
92
+ return
93
+ end
94
+
95
+ local maid = brio:ToMaid()
96
+ local track = brio:GetValue()
97
+
98
+ maid:GiveTask(track.KeyframeReached:Connect(function(...)
99
+ self.KeyframeReached:Fire(...)
100
+ end))
78
101
  end))
79
- end))
80
102
  end
81
103
 
82
104
  --[=[
@@ -84,7 +106,7 @@ end
84
106
 
85
107
  @param animationId string | number
86
108
  ]=]
87
- function AnimationTrackPlayer:SetAnimationId(animationId)
109
+ function AnimationTrackPlayer:SetAnimationId(animationId: string | number)
88
110
  return self._trackId:Mount(animationId)
89
111
  end
90
112
 
@@ -93,7 +115,7 @@ end
93
115
 
94
116
  @return string | number
95
117
  ]=]
96
- function AnimationTrackPlayer:GetAnimationId()
118
+ function AnimationTrackPlayer:GetAnimationId(): string | number
97
119
  return self._trackId.Value
98
120
  end
99
121
 
@@ -1,3 +1,4 @@
1
+ --!strict
1
2
  --[=[
2
3
  @class AnimationUtils
3
4
  ]=]