Skip to content

Commit cc75def

Browse files
committed
Add second stage to Progress type
1 parent 686620f commit cc75def

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

BaboonAPI/api-post/TrackReloader.fs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,26 @@ open BaboonAPI.Internal
66
open BaboonAPI.Utility
77

88
/// <summary>Reload the list of tracks and collections asynchronously.</summary>
9+
/// <param name="onProgress">Progress callback, will receive all progress events</param>
910
/// <returns>A YieldTask that must be started using StartCoroutine.</returns>
1011
let reloadAll (onProgress: Progress -> unit) = Unity.task {
1112
match! TrackAccessor.loadAsyncWithProgress onProgress with
1213
| Ok () ->
13-
do! TrackAccessor.loadCollectionsAsync()
14+
do! TrackAccessor.loadCollectionsAsyncWithProgress onProgress
1415
return Ok ()
1516
| Error e ->
1617
return Error e
1718
}
1819

1920
/// <summary>Reload the list of tracks and collections asynchronously.</summary>
21+
/// <param name="onProgress">Progress callback, will receive all progress events</param>
2022
/// <remarks>C# Action variant.</remarks>
2123
/// <returns>A YieldTask that must be started using StartCoroutine.</returns>
2224
let ReloadAll (onProgress: Progress Action) = reloadAll (FuncConvert.FromAction onProgress)
2325

2426
/// <summary>Reload the list of tracks asynchronously, then update existing collections with the new tracks.</summary>
27+
/// <remarks>The <paramref name="onProgress"/> callback will only be called up to FirstStageDone.</remarks>
28+
/// <param name="onProgress">Progress callback, will received events up to FirstStageDone</param>
2529
/// <returns>A YieldTask that must be started using StartCoroutine.</returns>
2630
let reloadTracks (onProgress: Progress -> unit) = Unity.task {
2731
match! TrackAccessor.loadAsyncWithProgress onProgress with
@@ -33,6 +37,7 @@ let reloadTracks (onProgress: Progress -> unit) = Unity.task {
3337
}
3438

3539
/// <summary>Reload the list of tracks asynchronously, then update existing collections with the new tracks.</summary>
40+
/// <param name="onProgress">Progress callback, will received events up to FirstStageDone</param>
3641
/// <remarks>C# Action variant.</remarks>
3742
/// <returns>A YieldTask that must be started using StartCoroutine.</returns>
3843
let ReloadTracks (onProgress: Progress Action) = reloadTracks (FuncConvert.FromAction onProgress)

BaboonAPI/api/TrackRegistry.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ type TracksLoadedInfo =
163163
type Progress =
164164
| LoadingTracks of ProgressUpdate
165165
| LoadingCollections of ProgressUpdate
166-
| Done of TracksLoadedInfo
166+
| FirstStageDone of TracksLoadedInfo
167+
| ResolvingCollections of ProgressUpdate
168+
| SecondStageDone of ProgressUpdate
167169

168170
/// <summary>
169171
/// Event-based API for registering new tracks.

BaboonAPI/internal/TrackAccessor.fs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ type TrackLoader() =
134134

135135
member _.LoadTracks onProgress =
136136
let info = makeTrackLoader onProgress |> onTracksLoaded
137-
onProgress (Done info)
137+
onProgress (FirstStageDone info)
138138

139139
member _.LoadTracksAsync onProgress =
140140
Unity.task {
@@ -146,7 +146,7 @@ type TrackLoader() =
146146

147147
if task.IsCompletedSuccessfully then
148148
let info = onTracksLoaded task.Result
149-
onProgress (Done info)
149+
onProgress (FirstStageDone info)
150150
return Ok ()
151151
elif task.IsFaulted then
152152
return Error (task.Exception :> exn)
@@ -155,15 +155,16 @@ type TrackLoader() =
155155
}
156156

157157
/// Resolve all track collections asynchronously and update base game about it
158-
member _.ResolveCollections () =
158+
member _.ResolveCollections onProgress =
159159
Unity.task {
160160
GlobalVariables.all_track_collections.Clear()
161161

162162
for index, collection in Seq.indexed collections do
163163
let! resolved = collection.Resolve(index)
164+
onProgress (ResolvingCollections { loaded = index + 1 })
164165
GlobalVariables.all_track_collections.Add resolved
165166

166-
()
167+
onProgress (SecondStageDone { loaded = GlobalVariables.all_track_collections.Count })
167168
}
168169

169170
/// Update all track collections without doing a full async resolve
@@ -217,7 +218,10 @@ let loadAsyncWithProgress onProgress =
217218
trackLoader.LoadTracksAsync onProgress
218219

219220
let loadCollectionsAsync () =
220-
trackLoader.ResolveCollections()
221+
trackLoader.ResolveCollections ignore
222+
223+
let loadCollectionsAsyncWithProgress onProgress =
224+
trackLoader.ResolveCollections onProgress
221225

222226
let updateCollections () =
223227
trackLoader.UpdateCollections()

0 commit comments

Comments
 (0)