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 dc98313
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions crates/bevy_asset/src/asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub enum AssetServerError {
MissingAssetLoader(Option<String>),
#[error("the given type does not match the type of the loaded asset")]
IncorrectHandleType,
#[error("the given asset does not have a filename")]
AssetWithoutFilename,
#[error("encountered an error while loading an asset")]
AssetLoaderError(anyhow::Error),
#[error("`PathLoader` encountered an error")]
Expand Down Expand Up @@ -132,11 +134,26 @@ 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..];
return self.get_asset_loader(extension);
}

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

0 comments on commit dc98313

Please sign in to comment.