1- use crate :: io:: {
2- get_meta_path, AssetReader , AssetReaderError , EmptyPathStream , PathStream , Reader , VecReader ,
1+ use crate :: {
2+ io:: {
3+ get_meta_path, AssetLoadRetrySettings , AssetReader , AssetReaderError , EmptyPathStream ,
4+ PathStream , Reader , VecReader ,
5+ } ,
6+ retry:: { IoErrorRetrySettingsProvider , ProvideAssetLoadRetrySettings } ,
7+ UntypedAssetLoadFailedEvent ,
38} ;
49use bevy_log:: error;
510use bevy_utils:: BoxedFuture ;
@@ -12,15 +17,24 @@ use web_sys::Response;
1217/// Reader implementation for loading assets via HTTP in WASM.
1318pub struct HttpWasmAssetReader {
1419 root_path : PathBuf ,
20+ retry_settings_provider : Box < dyn ProvideAssetLoadRetrySettings > ,
1521}
1622
1723impl HttpWasmAssetReader {
1824 /// Creates a new `WasmAssetReader`. The path provided will be used to build URLs to query for assets.
1925 pub fn new < P : AsRef < Path > > ( path : P ) -> Self {
2026 Self {
2127 root_path : path. as_ref ( ) . to_owned ( ) ,
28+ retry_settings_provider : Box :: new ( IoErrorRetrySettingsProvider :: from (
29+ AssetLoadRetrySettings :: network_default ( ) ,
30+ ) ) ,
2231 }
2332 }
33+ /// Overrides the default retry settings.
34+ pub fn with_retry_defaults ( mut self , provider : Box < dyn ProvideAssetLoadRetrySettings > ) -> Self {
35+ self . retry_settings_provider = provider;
36+ self
37+ }
2438}
2539
2640fn js_value_to_err < ' a > ( context : & ' a str ) -> impl FnOnce ( JsValue ) -> std:: io:: Error + ' a {
@@ -95,4 +109,12 @@ impl AssetReader for HttpWasmAssetReader {
95109 error ! ( "Reading directories is not supported with the HttpWasmAssetReader" ) ;
96110 Box :: pin ( async move { Ok ( false ) } )
97111 }
112+
113+ fn get_default_retry_settings (
114+ & self ,
115+ load_error : & UntypedAssetLoadFailedEvent ,
116+ ) -> AssetLoadRetrySettings {
117+ self . retry_settings_provider
118+ . get_retry_settings ( AssetLoadRetrySettings :: no_retries ( ) , load_error)
119+ }
98120}
0 commit comments