Skip to content

Commit

Permalink
Process Asset File Extensions With Multiple Dots
Browse files Browse the repository at this point in the history
Fixes #1276
  • Loading branch information
zicklag committed Jan 21, 2021
1 parent a880b54 commit b60126c
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions crates/bevy_asset/src/asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,27 @@ impl AssetServer {
&self,
path: P,
) -> Result<Arc<Box<dyn AssetLoader>>, AssetServerError> {
path.as_ref()
.extension()
.and_then(|e| e.to_str())
// Get filename
let s = path
.as_ref()
.file_name()
.ok_or(AssetServerError::MissingAssetLoader(None))
.and_then(|extension| self.get_asset_loader(extension))
.and_then(|x| x.to_str().ok_or(AssetServerError::MissingAssetLoader(None)))?;

// If the filename has multiple dots, try to match on a multi-dot file extension
if s.split('.').count() > 1 {
if let Ok(loader) = self.get_asset_loader(&s[s.find('.').unwrap() + 1..]) {
return Ok(loader);
}
}

// Just get the file extension normaly if that doesn't work
let extension = &s[s
.rfind('.')
.ok_or(AssetServerError::MissingAssetLoader(None))?
+ 1..];

self.get_asset_loader(extension)
}

pub fn get_handle_path<H: Into<HandleId>>(&self, handle: H) -> Option<AssetPath<'_>> {
Expand Down

0 comments on commit b60126c

Please sign in to comment.