@@ -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,39 +18,38 @@ local AnimationTrackPlayer = setmetatable({}, BaseObject)
1718AnimationTrackPlayer .ClassName = " AnimationTrackPlayer"
1819AnimationTrackPlayer .__index = AnimationTrackPlayer
1920
20- export type AnimationTrackPlayer =
21- typeof ( setmetatable (
22- {} :: {
23- -- Public
24- KeyframeReached : Signal . Signal < () > ,
25-
26- -- Private
27- _animationTarget : ValueObject . ValueObject <Instance> ,
28- _trackId : ValueObject .ValueObject < string | number > ,
29- _currentTrack : ValueObject .ValueObject < AnimationTrack ?> ,
30- _animationPriority : ValueObject .ValueObject <number > ,
31- } ,
32- {} :: typeof ({ __index = AnimationTrackPlayer })
33- ) )
34- & BaseObject .BaseObject
21+ type AnimationId = string | number
22+
23+ export type AnimationTrackPlayer = typeof ( setmetatable (
24+ {} :: {
25+ -- Public
26+ KeyframeReached : Signal . Signal <string> ,
27+
28+ -- Private
29+ _animationTarget : ValueObject .ValueObject < Instance ? > ,
30+ _trackId : ValueObject .ValueObject < AnimationId ?> ,
31+ _currentTrack : ValueObject .ValueObject < AnimationTrack ? > ,
32+ _animationPriority : ValueObject . ValueObject < number ? > ,
33+ },
34+ {} :: typeof ({ __index = AnimationTrackPlayer } )
35+ )) & BaseObject .BaseObject
3536
3637--[=[
3738 Plays an animation track in the target. Async loads the track when
3839 all data is found.
39-
40- @param animationTarget Instance | Observable<Instance>
41- @param animationId string | number?
42- @return AnimationTrackPlayer
4340]=]
44- function AnimationTrackPlayer .new (animationTarget , animationId : string | number ): AnimationTrackPlayer
41+ function AnimationTrackPlayer .new (
42+ animationTarget : ValueObject.Mountable<Instance ? >,
43+ animationId : AnimationId ?
44+ ): AnimationTrackPlayer
4545 local self : AnimationTrackPlayer = setmetatable (BaseObject .new () :: any , AnimationTrackPlayer )
4646
4747 self ._animationTarget = self ._maid :Add (ValueObject .new (nil ))
4848 self ._trackId = self ._maid :Add (ValueObject .new (nil ))
4949 self ._currentTrack = self ._maid :Add (ValueObject .new (nil ))
5050 self ._animationPriority = self ._maid :Add (ValueObject .new (nil ))
5151
52- self .KeyframeReached = self ._maid :Add (Signal .new ())
52+ self .KeyframeReached = self ._maid :Add (Signal .new () :: any )
5353
5454 if animationTarget then
5555 self :SetAnimationTarget (animationTarget )
@@ -64,7 +64,7 @@ function AnimationTrackPlayer.new(animationTarget, animationId: string | number)
6464 return self
6565end
6666
67- function AnimationTrackPlayer : _setupState ()
67+ function AnimationTrackPlayer . _setupState ( self : AnimationTrackPlayer ): ()
6868 self ._maid :GiveTask (Rx .combineLatest ({
6969 animationTarget = self ._animationTarget :Observe (),
7070 trackId = self ._trackId :Observe (),
@@ -95,7 +95,7 @@ function AnimationTrackPlayer:_setupState()
9595 end
9696
9797 local maid = brio :ToMaid ()
98- local track = brio :GetValue ()
98+ local track = brio :GetValue () :: AnimationTrack
9999
100100 maid :GiveTask (track .KeyframeReached :Connect (function (...)
101101 self .KeyframeReached :Fire (... )
@@ -105,39 +105,40 @@ end
105105
106106--[=[
107107 Sets the animation id to play
108-
109- @param animationId string | number
110108]=]
111- function AnimationTrackPlayer :SetAnimationId (animationId : string | number )
109+ function AnimationTrackPlayer .SetAnimationId (
110+ self : AnimationTrackPlayer ,
111+ animationId : ValueObject.Mountable<AnimationId ? >
112+ ): Maid .MaidTask
112113 return self ._trackId :Mount (animationId )
113114end
114115
115116--[=[
116117 Returns the current animation id
117-
118- @return string | number
119118]=]
120- function AnimationTrackPlayer : GetAnimationId (): string | number
119+ function AnimationTrackPlayer . GetAnimationId (self : AnimationTrackPlayer ): AnimationId ?
121120 return self ._trackId .Value
122121end
123122
124123--[=[
125124 Sets an animation target to play the animation on
126-
127- @param animationTarget Instance | Observable<Instance>
128125]=]
129- function AnimationTrackPlayer :SetAnimationTarget (animationTarget )
126+ function AnimationTrackPlayer .SetAnimationTarget (
127+ self : AnimationTrackPlayer ,
128+ animationTarget : ValueObject.Mountable<Instance ? >
129+ ): Maid .MaidTask
130130 return self ._animationTarget :Mount (animationTarget )
131131end
132132
133133--[=[
134134 Sets the weight target if it hasn't been set
135-
136- @param weight number
137- @param fadeTime number
138135]=]
139- function AnimationTrackPlayer :SetWeightTargetIfNotSet (weight : number , fadeTime : number )
140- self ._maid ._adjustWeight = self :_onEachTrack (function (track )
136+ function AnimationTrackPlayer .SetWeightTargetIfNotSet (
137+ self : AnimationTrackPlayer ,
138+ weight : number ? ,
139+ fadeTime : number ?
140+ ): ()
141+ self ._maid ._adjustWeight = self :_onEachTrack (function (track : AnimationTrack )
141142 if track .WeightTarget ~= weight then
142143 track :AdjustWeight (weight , fadeTime )
143144 end
146147
147148--[=[
148149 Plays the current animation specified
149-
150- @param fadeTime number
151- @param weight number
152- @param speed number
153150]=]
154- function AnimationTrackPlayer : Play (fadeTime : number , weight : number , speed : number )
151+ function AnimationTrackPlayer . Play (self : AnimationTrackPlayer , fadeTime : number ? , weight : number ? , speed : number ): ( )
155152 if weight then
156153 self ._maid ._adjustWeight = nil
157154 end
@@ -161,63 +158,53 @@ function AnimationTrackPlayer:Play(fadeTime: number, weight: number, speed: numb
161158 end
162159
163160 self ._maid ._stop = nil
164- self ._maid ._play = self :_onEachTrack (function (track )
161+ self ._maid ._play = self :_onEachTrack (function (track : AnimationTrack )
165162 track :Play (fadeTime , weight , speed )
166163 end )
167164end
168165
169166--[=[
170167 Stops the current animation
171-
172- @param fadeTime number
173168]=]
174- function AnimationTrackPlayer : Stop (fadeTime : number )
169+ function AnimationTrackPlayer . Stop (self : AnimationTrackPlayer , fadeTime : number ? ): ( )
175170 self ._maid ._play = nil
176- self ._maid ._stop = self :_onEachTrack (function (track )
171+ self ._maid ._stop = self :_onEachTrack (function (track : AnimationTrack )
177172 track :Stop (fadeTime )
178173 end )
179174end
180175
181176--[=[
182177 Adjusts the weight of the animation track
183-
184- @param weight number
185- @param fadeTime number
186178]=]
187- function AnimationTrackPlayer : AdjustWeight (weight : number , fadeTime : number )
188- self ._maid ._adjustWeight = self :_onEachTrack (function (track )
179+ function AnimationTrackPlayer . AdjustWeight (self : AnimationTrackPlayer , weight : number ? , fadeTime : number ? ): ( )
180+ self ._maid ._adjustWeight = self :_onEachTrack (function (track : AnimationTrack )
189181 track :AdjustWeight (weight , fadeTime )
190182 end )
191183end
192184
193185--[=[
194186 Adjusts the speed of the animation track
195-
196- @param speed number
197- @param fadeTime number
198187]=]
199- function AnimationTrackPlayer : AdjustSpeed (speed : number , fadeTime : number )
200- self ._maid ._adjustSpeed = self :_onEachTrack (function (track )
201- track :AdjustSpeed (speed , fadeTime )
188+ function AnimationTrackPlayer . AdjustSpeed (self : AnimationTrackPlayer , speed : number ? ): ( )
189+ self ._maid ._adjustSpeed = self :_onEachTrack (function (track : AnimationTrack )
190+ track :AdjustSpeed (speed )
202191 end )
203192end
204193
205194--[=[
206195 Returns true if playing
207-
208- @return boolean
209196]=]
210- function AnimationTrackPlayer : IsPlaying (): boolean
211- local track = self ._currentTrack .Value
197+ function AnimationTrackPlayer . IsPlaying (self : AnimationTrackPlayer ): boolean
198+ local track : AnimationTrack ? = self ._currentTrack .Value
212199 if track then
213200 return track .IsPlaying
214201 else
215202 return false
216203 end
217204end
218205
219- function AnimationTrackPlayer : _onEachTrack (callback )
220- return self ._currentTrack :Observe ():Subscribe (function (track )
206+ function AnimationTrackPlayer . _onEachTrack (self : AnimationTrackPlayer , callback )
207+ return self ._currentTrack :Observe ():Subscribe (function (track : AnimationTrack ? )
221208 if track ~= nil then
222209 callback (track )
223210 end
0 commit comments