@@ -895,26 +895,49 @@ impl AssetServer {
895
895
& self ,
896
896
id : impl Into < UntypedAssetId > ,
897
897
) -> Option < ( LoadState , DependencyLoadState , RecursiveDependencyLoadState ) > {
898
+ self . data . infos . read ( ) . get ( id. into ( ) ) . map ( |i| {
899
+ (
900
+ i. load_state . clone ( ) ,
901
+ i. dep_load_state . clone ( ) ,
902
+ i. rec_dep_load_state . clone ( ) ,
903
+ )
904
+ } )
905
+ }
906
+
907
+ /// Retrieves the main [`LoadState`] of a given asset `id`.
908
+ ///
909
+ /// Note that this is "just" the root asset load state. To get the load state of
910
+ /// its dependencies or recursive dependencies, see [`AssetServer::get_dependency_load_state`]
911
+ /// and [`AssetServer::get_recursive_dependency_load_state`] respectively.
912
+ pub fn get_load_state ( & self , id : impl Into < UntypedAssetId > ) -> Option < LoadState > {
898
913
self . data
899
914
. infos
900
915
. read ( )
901
916
. get ( id. into ( ) )
902
- . map ( |i| ( i. load_state . clone ( ) , i . dep_load_state , i . rec_dep_load_state ) )
917
+ . map ( |i| i. load_state . clone ( ) )
903
918
}
904
919
905
- /// Retrieves the main [`LoadState `] of a given asset `id`.
920
+ /// Retrieves the [`DependencyLoadState `] of a given asset `id`'s dependencies .
906
921
///
907
- /// Note that this is "just" the root asset load state. To check if an asset _and_ its recursive
908
- /// dependencies have loaded, see [`AssetServer::is_loaded_with_dependencies`].
909
- pub fn get_load_state ( & self , id : impl Into < UntypedAssetId > ) -> Option < LoadState > {
922
+ /// Note that this is only the load state of direct dependencies of the root asset. To get
923
+ /// the load state of the root asset itself or its recursive dependencies, see
924
+ /// [`AssetServer::get_load_state`] and [`AssetServer::get_recursive_dependency_load_state`] respectively.
925
+ pub fn get_dependency_load_state (
926
+ & self ,
927
+ id : impl Into < UntypedAssetId > ,
928
+ ) -> Option < DependencyLoadState > {
910
929
self . data
911
930
. infos
912
931
. read ( )
913
932
. get ( id. into ( ) )
914
- . map ( |i| i. load_state . clone ( ) )
933
+ . map ( |i| i. dep_load_state . clone ( ) )
915
934
}
916
935
917
- /// Retrieves the [`RecursiveDependencyLoadState`] of a given asset `id`.
936
+ /// Retrieves the main [`RecursiveDependencyLoadState`] of a given asset `id`'s recursive dependencies.
937
+ ///
938
+ /// Note that this is only the load state of recursive dependencies of the root asset. To get
939
+ /// the load state of the root asset itself or its direct dependencies only, see
940
+ /// [`AssetServer::get_load_state`] and [`AssetServer::get_dependency_load_state`] respectively.
918
941
pub fn get_recursive_dependency_load_state (
919
942
& self ,
920
943
id : impl Into < UntypedAssetId > ,
@@ -923,15 +946,30 @@ impl AssetServer {
923
946
. infos
924
947
. read ( )
925
948
. get ( id. into ( ) )
926
- . map ( |i| i. rec_dep_load_state )
949
+ . map ( |i| i. rec_dep_load_state . clone ( ) )
927
950
}
928
951
929
952
/// Retrieves the main [`LoadState`] of a given asset `id`.
953
+ ///
954
+ /// This is the same as [`AssetServer::get_load_state`] except the result is unwrapped. If
955
+ /// the result is None, [`LoadState::NotLoaded`] is returned.
930
956
pub fn load_state ( & self , id : impl Into < UntypedAssetId > ) -> LoadState {
931
957
self . get_load_state ( id) . unwrap_or ( LoadState :: NotLoaded )
932
958
}
933
959
960
+ /// Retrieves the [`DependencyLoadState`] of a given asset `id`.
961
+ ///
962
+ /// This is the same as [`AssetServer::get_dependency_load_state`] except the result is unwrapped. If
963
+ /// the result is None, [`DependencyLoadState::NotLoaded`] is returned.
964
+ pub fn dependency_load_state ( & self , id : impl Into < UntypedAssetId > ) -> DependencyLoadState {
965
+ self . get_dependency_load_state ( id)
966
+ . unwrap_or ( DependencyLoadState :: NotLoaded )
967
+ }
968
+
934
969
/// Retrieves the [`RecursiveDependencyLoadState`] of a given asset `id`.
970
+ ///
971
+ /// This is the same as [`AssetServer::get_recursive_dependency_load_state`] except the result is unwrapped. If
972
+ /// the result is None, [`RecursiveDependencyLoadState::NotLoaded`] is returned.
935
973
pub fn recursive_dependency_load_state (
936
974
& self ,
937
975
id : impl Into < UntypedAssetId > ,
@@ -940,11 +978,30 @@ impl AssetServer {
940
978
. unwrap_or ( RecursiveDependencyLoadState :: NotLoaded )
941
979
}
942
980
943
- /// Returns true if the asset and all of its dependencies (recursive) have been loaded.
981
+ /// Convenience method that returns true if the asset has been loaded.
982
+ pub fn is_loaded ( & self , id : impl Into < UntypedAssetId > ) -> bool {
983
+ matches ! ( self . load_state( id) , LoadState :: Loaded )
984
+ }
985
+
986
+ /// Convenience method that returns true if the asset and all of its direct dependencies have been loaded.
944
987
pub fn is_loaded_with_dependencies ( & self , id : impl Into < UntypedAssetId > ) -> bool {
945
- let id = id. into ( ) ;
946
- self . load_state ( id) == LoadState :: Loaded
947
- && self . recursive_dependency_load_state ( id) == RecursiveDependencyLoadState :: Loaded
988
+ matches ! (
989
+ self . get_load_states( id) ,
990
+ Some ( ( LoadState :: Loaded , DependencyLoadState :: Loaded , _) )
991
+ )
992
+ }
993
+
994
+ /// Convenience method that returns true if the asset, all of its dependencies, and all of its recursive
995
+ /// dependencies have been loaded.
996
+ pub fn is_loaded_with_recursive_dependencies ( & self , id : impl Into < UntypedAssetId > ) -> bool {
997
+ matches ! (
998
+ self . get_load_states( id) ,
999
+ Some ( (
1000
+ LoadState :: Loaded ,
1001
+ DependencyLoadState :: Loaded ,
1002
+ RecursiveDependencyLoadState :: Loaded
1003
+ ) )
1004
+ )
948
1005
}
949
1006
950
1007
/// Returns an active handle for the given path, if the asset at the given path has already started loading,
@@ -1361,11 +1418,11 @@ pub enum LoadState {
1361
1418
/// The asset has been loaded and has been added to the [`World`]
1362
1419
Loaded ,
1363
1420
/// The asset failed to load.
1364
- Failed ( Box < AssetLoadError > ) ,
1421
+ Failed ( Arc < AssetLoadError > ) ,
1365
1422
}
1366
1423
1367
1424
/// The load state of an asset's dependencies.
1368
- #[ derive( Component , Copy , Clone , Debug , Eq , PartialEq , Ord , PartialOrd ) ]
1425
+ #[ derive( Component , Clone , Debug , Eq , PartialEq ) ]
1369
1426
pub enum DependencyLoadState {
1370
1427
/// The asset has not started loading yet
1371
1428
NotLoaded ,
@@ -1374,11 +1431,11 @@ pub enum DependencyLoadState {
1374
1431
/// Dependencies have all loaded
1375
1432
Loaded ,
1376
1433
/// One or more dependencies have failed to load
1377
- Failed ,
1434
+ Failed ( Arc < AssetLoadError > ) ,
1378
1435
}
1379
1436
1380
1437
/// The recursive load state of an asset's dependencies.
1381
- #[ derive( Component , Copy , Clone , Debug , Eq , PartialEq , Ord , PartialOrd ) ]
1438
+ #[ derive( Component , Clone , Debug , Eq , PartialEq ) ]
1382
1439
pub enum RecursiveDependencyLoadState {
1383
1440
/// The asset has not started loading yet
1384
1441
NotLoaded ,
@@ -1387,7 +1444,7 @@ pub enum RecursiveDependencyLoadState {
1387
1444
/// Dependencies in this asset's dependency tree have all loaded
1388
1445
Loaded ,
1389
1446
/// One or more dependencies have failed to load in this asset's dependency tree
1390
- Failed ,
1447
+ Failed ( Arc < AssetLoadError > ) ,
1391
1448
}
1392
1449
1393
1450
/// An error that occurs during an [`Asset`] load.
0 commit comments