@@ -9,6 +9,7 @@ local require = require(script.Parent.loader).load(script)
99
1010local AnimationUtils = require (" AnimationUtils" )
1111local BaseObject = require (" BaseObject" )
12+ local Maid = require (" Maid" )
1213local Rx = require (" Rx" )
1314local Signal = require (" Signal" )
1415local ValueObject = require (" ValueObject" )
@@ -17,17 +18,19 @@ local AnimationTrackPlayer = setmetatable({}, BaseObject)
1718AnimationTrackPlayer .ClassName = " AnimationTrackPlayer"
1819AnimationTrackPlayer .__index = AnimationTrackPlayer
1920
21+ type AnimationId = string | number
22+
2023export type AnimationTrackPlayer =
2124 typeof (setmetatable (
2225 {} :: {
2326 -- Public
24- KeyframeReached : Signal .Signal < () > ,
27+ KeyframeReached : Signal .Signal <string > ,
2528
2629 -- Private
27- _animationTarget : ValueObject .ValueObject <Instance> ,
28- _trackId : ValueObject .ValueObject < string | number > ,
30+ _animationTarget : ValueObject .ValueObject < Instance ? > ,
31+ _trackId : ValueObject .ValueObject < AnimationId ? > ,
2932 _currentTrack : ValueObject .ValueObject < AnimationTrack ?> ,
30- _animationPriority : ValueObject .ValueObject <number> ,
33+ _animationPriority : ValueObject .ValueObject < number ? > ,
3134 },
3235 {} :: typeof ({ __index = AnimationTrackPlayer })
3336 ))
@@ -36,20 +39,19 @@ export type AnimationTrackPlayer =
3639--[=[
3740 Plays an animation track in the target. Async loads the track when
3841 all data is found.
39-
40- @param animationTarget Instance | Observable<Instance>
41- @param animationId string | number?
42- @return AnimationTrackPlayer
4342]=]
44- function AnimationTrackPlayer .new (animationTarget , animationId : string | number ): AnimationTrackPlayer
43+ function AnimationTrackPlayer .new (
44+ animationTarget : ValueObject.Mountable<Instance ? >,
45+ animationId : AnimationId ?
46+ ): AnimationTrackPlayer
4547 local self : AnimationTrackPlayer = setmetatable (BaseObject .new () :: any , AnimationTrackPlayer )
4648
4749 self ._animationTarget = self ._maid :Add (ValueObject .new (nil ))
4850 self ._trackId = self ._maid :Add (ValueObject .new (nil ))
4951 self ._currentTrack = self ._maid :Add (ValueObject .new (nil ))
5052 self ._animationPriority = self ._maid :Add (ValueObject .new (nil ))
5153
52- self .KeyframeReached = self ._maid :Add (Signal .new ())
54+ self .KeyframeReached = self ._maid :Add (Signal .new () :: any )
5355
5456 if animationTarget then
5557 self :SetAnimationTarget (animationTarget )
@@ -64,7 +66,7 @@ function AnimationTrackPlayer.new(animationTarget, animationId: string | number)
6466 return self
6567end
6668
67- function AnimationTrackPlayer : _setupState ()
69+ function AnimationTrackPlayer . _setupState ( self : AnimationTrackPlayer ): ()
6870 self ._maid :GiveTask (Rx .combineLatest ({
6971 animationTarget = self ._animationTarget :Observe (),
7072 trackId = self ._trackId :Observe (),
@@ -95,7 +97,7 @@ function AnimationTrackPlayer:_setupState()
9597 end
9698
9799 local maid = brio :ToMaid ()
98- local track = brio :GetValue ()
100+ local track = brio :GetValue () :: AnimationTrack
99101
100102 maid :GiveTask (track .KeyframeReached :Connect (function (...)
101103 self .KeyframeReached :Fire (... )
@@ -105,39 +107,40 @@ end
105107
106108--[=[
107109 Sets the animation id to play
108-
109- @param animationId string | number
110110]=]
111- function AnimationTrackPlayer :SetAnimationId (animationId : string | number )
111+ function AnimationTrackPlayer .SetAnimationId (
112+ self : AnimationTrackPlayer ,
113+ animationId : ValueObject.Mountable<AnimationId ? >
114+ ): Maid .MaidTask
112115 return self ._trackId :Mount (animationId )
113116end
114117
115118--[=[
116119 Returns the current animation id
117-
118- @return string | number
119120]=]
120- function AnimationTrackPlayer : GetAnimationId (): string | number
121+ function AnimationTrackPlayer . GetAnimationId (self : AnimationTrackPlayer ): AnimationId ?
121122 return self ._trackId .Value
122123end
123124
124125--[=[
125126 Sets an animation target to play the animation on
126-
127- @param animationTarget Instance | Observable<Instance>
128127]=]
129- function AnimationTrackPlayer :SetAnimationTarget (animationTarget )
128+ function AnimationTrackPlayer .SetAnimationTarget (
129+ self : AnimationTrackPlayer ,
130+ animationTarget : ValueObject.Mountable<Instance ? >
131+ ): Maid .MaidTask
130132 return self ._animationTarget :Mount (animationTarget )
131133end
132134
133135--[=[
134136 Sets the weight target if it hasn't been set
135-
136- @param weight number
137- @param fadeTime number
138137]=]
139- function AnimationTrackPlayer :SetWeightTargetIfNotSet (weight : number , fadeTime : number )
140- self ._maid ._adjustWeight = self :_onEachTrack (function (track )
138+ function AnimationTrackPlayer .SetWeightTargetIfNotSet (
139+ self : AnimationTrackPlayer ,
140+ weight : number ? ,
141+ fadeTime : number ?
142+ ): ()
143+ self ._maid ._adjustWeight = self :_onEachTrack (function (track : AnimationTrack )
141144 if track .WeightTarget ~= weight then
142145 track :AdjustWeight (weight , fadeTime )
143146 end
146149
147150--[=[
148151 Plays the current animation specified
149-
150- @param fadeTime number
151- @param weight number
152- @param speed number
153152]=]
154- function AnimationTrackPlayer : Play (fadeTime : number , weight : number , speed : number )
153+ function AnimationTrackPlayer . Play (self : AnimationTrackPlayer , fadeTime : number ? , weight : number ? , speed : number ): ( )
155154 if weight then
156155 self ._maid ._adjustWeight = nil
157156 end
@@ -161,63 +160,53 @@ function AnimationTrackPlayer:Play(fadeTime: number, weight: number, speed: numb
161160 end
162161
163162 self ._maid ._stop = nil
164- self ._maid ._play = self :_onEachTrack (function (track )
163+ self ._maid ._play = self :_onEachTrack (function (track : AnimationTrack )
165164 track :Play (fadeTime , weight , speed )
166165 end )
167166end
168167
169168--[=[
170169 Stops the current animation
171-
172- @param fadeTime number
173170]=]
174- function AnimationTrackPlayer : Stop (fadeTime : number )
171+ function AnimationTrackPlayer . Stop (self : AnimationTrackPlayer , fadeTime : number ? ): ( )
175172 self ._maid ._play = nil
176- self ._maid ._stop = self :_onEachTrack (function (track )
173+ self ._maid ._stop = self :_onEachTrack (function (track : AnimationTrack )
177174 track :Stop (fadeTime )
178175 end )
179176end
180177
181178--[=[
182179 Adjusts the weight of the animation track
183-
184- @param weight number
185- @param fadeTime number
186180]=]
187- function AnimationTrackPlayer : AdjustWeight (weight : number , fadeTime : number )
188- self ._maid ._adjustWeight = self :_onEachTrack (function (track )
181+ function AnimationTrackPlayer . AdjustWeight (self : AnimationTrackPlayer , weight : number ? , fadeTime : number ? ): ( )
182+ self ._maid ._adjustWeight = self :_onEachTrack (function (track : AnimationTrack )
189183 track :AdjustWeight (weight , fadeTime )
190184 end )
191185end
192186
193187--[=[
194188 Adjusts the speed of the animation track
195-
196- @param speed number
197- @param fadeTime number
198189]=]
199- function AnimationTrackPlayer : AdjustSpeed (speed : number , fadeTime : number )
200- self ._maid ._adjustSpeed = self :_onEachTrack (function (track )
201- track :AdjustSpeed (speed , fadeTime )
190+ function AnimationTrackPlayer . AdjustSpeed (self : AnimationTrackPlayer , speed : number ? ): ( )
191+ self ._maid ._adjustSpeed = self :_onEachTrack (function (track : AnimationTrack )
192+ track :AdjustSpeed (speed )
202193 end )
203194end
204195
205196--[=[
206197 Returns true if playing
207-
208- @return boolean
209198]=]
210- function AnimationTrackPlayer : IsPlaying (): boolean
211- local track = self ._currentTrack .Value
199+ function AnimationTrackPlayer . IsPlaying (self : AnimationTrackPlayer ): boolean
200+ local track : AnimationTrack ? = self ._currentTrack .Value
212201 if track then
213202 return track .IsPlaying
214203 else
215204 return false
216205 end
217206end
218207
219- function AnimationTrackPlayer : _onEachTrack (callback )
220- return self ._currentTrack :Observe ():Subscribe (function (track )
208+ function AnimationTrackPlayer . _onEachTrack (self : AnimationTrackPlayer , callback )
209+ return self ._currentTrack :Observe ():Subscribe (function (track : AnimationTrack ? )
221210 if track ~= nil then
222211 callback (track )
223212 end
0 commit comments