From 0121e528116d817bb2922fbbb8e572330d79f78c Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 1 Dec 2023 01:08:20 +0100 Subject: [PATCH] deduplicate logic --- src/http_assets.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/http_assets.rs b/src/http_assets.rs index 8f7545a..6ca9fa9 100644 --- a/src/http_assets.rs +++ b/src/http_assets.rs @@ -48,25 +48,20 @@ impl AssetReader for HttpAssetReader { } let path = path.display().to_string(); - let mut bytes = vec![]; - if self.tile { + let path = if self.tile { // `tile://` urls are special for now, because we can't use `/` in the tile paths, // as that will cause texture loading to be attempted in the subfolders instead of the root. let (x, rest) = path.split_once('_').unwrap(); - let path = format!("{}lod1/{}/{x}/{rest}", self.base_url, TILE_ZOOM); - bevy_web_asset::WebAssetReader::Https - .read(Path::new(&path)) - .await? - .read_to_end(&mut bytes) - .await?; + format!("{}lod1/{}/{x}/{rest}", self.base_url, TILE_ZOOM) } else { - let path = format!("{}{path}", self.base_url); - bevy_web_asset::WebAssetReader::Https - .read(Path::new(&path)) - .await? - .read_to_end(&mut bytes) - .await?; + format!("{}{path}", self.base_url) }; + let mut bytes = vec![]; + bevy_web_asset::WebAssetReader::Https + .read(Path::new(&path)) + .await? + .read_to_end(&mut bytes) + .await?; if let Some(cache_path) = cache_path { // Write asset to cache, but ensure only one HttpAssetReader writes at any given point in time if self.sync.write().unwrap().insert(cache_path.clone()) {