Skip to content

Commit

Permalink
deduplicate logic
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Dec 1, 2023
1 parent ac2c541 commit 0121e52
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/http_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit 0121e52

Please sign in to comment.