Skip to content

Commit 1a19df4

Browse files
committed
fix: Enhance annotations
1 parent 63c1483 commit 1a19df4

File tree

2 files changed

+53
-73
lines changed

2 files changed

+53
-73
lines changed

src/animations/src/Shared/AnimationTrackPlayer.lua

Lines changed: 51 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ local require = require(script.Parent.loader).load(script)
99

1010
local AnimationUtils = require("AnimationUtils")
1111
local BaseObject = require("BaseObject")
12+
local Maid = require("Maid")
1213
local Rx = require("Rx")
1314
local Signal = require("Signal")
1415
local ValueObject = require("ValueObject")
@@ -17,39 +18,38 @@ local AnimationTrackPlayer = setmetatable({}, BaseObject)
1718
AnimationTrackPlayer.ClassName = "AnimationTrackPlayer"
1819
AnimationTrackPlayer.__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
6565
end
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)
113114
end
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
122121
end
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)
131131
end
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
@@ -146,12 +147,8 @@ 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)
167164
end
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)
179174
end
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)
191183
end
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)
203192
end
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
217204
end
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

src/canceltoken/src/Shared/CancelToken.lua

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ local CancelToken = {}
1717
CancelToken.ClassName = "CancelToken"
1818
CancelToken.__index = CancelToken
1919

20-
export type Executor = (cancel: () -> (), maid: any) -> ()
20+
export type Executor = (cancel: () -> (), maid: Maid.Maid) -> ()
2121

2222
export type CancelToken = typeof(setmetatable(
2323
{} :: {
@@ -71,10 +71,7 @@ function CancelToken.isCancelToken(value: any): boolean
7171
end
7272

7373
--[=[
74-
Constructs a new CancelToken that cancels whenever the maid does.
75-
76-
@param maid Maid
77-
@return CancelToken
74+
Constructs a new CancelToken that cancels whenever the maid does
7875
]=]
7976
function CancelToken.fromMaid(maid: Maid.Maid): CancelToken
8077
local token = CancelToken.new(EMPTY_FUNCTION)
@@ -92,9 +89,6 @@ end
9289

9390
--[=[
9491
Cancels after the set amount of seconds
95-
96-
@param seconds number
97-
@return CancelToken
9892
]=]
9993
function CancelToken.fromSeconds(seconds: number): CancelToken
10094
assert(type(seconds) == "number", "Bad seconds")
@@ -115,7 +109,6 @@ end
115109

116110
--[=[
117111
Returns true if cancelled
118-
@return boolean
119112
]=]
120113
function CancelToken.IsCancelled(self: CancelToken): boolean
121114
return self.PromiseCancelled:IsFulfilled()

0 commit comments

Comments
 (0)