Skip to content

Commit

Permalink
feat(unstable-load-from-file): load animation files with .ron exten…
Browse files Browse the repository at this point in the history
…sion
  • Loading branch information
jcornaz committed Jun 20, 2022
1 parent 44b58bc commit b5288ac
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ all-features = true

[features]
default = []
unstable-load-from-file = ["serde", "serde_yaml", "anyhow", "bevy_utils"]
unstable-load-from-file = ["serde", "serde_yaml", "ron", "anyhow", "bevy_utils"]

[dependencies]
bevy_core = { version = "0.7.0", default-features = false }
Expand Down
5 changes: 5 additions & 0 deletions assets/coin.animation.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(
mode: Repeat,
frame_duration: Some(100),
frames: [0, 1, 2, 3, 4],
)
8 changes: 6 additions & 2 deletions src/animation/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ impl AssetLoader for SpriteSheetAnimationLoader {
load_context: &'a mut LoadContext<'_>,
) -> BoxedFuture<'a, Result<(), anyhow::Error>> {
Box::pin(async move {
let custom_asset = SpriteSheetAnimation::from_yaml_bytes(bytes)?;
let custom_asset = match load_context.path().extension().unwrap().to_str().unwrap() {
"yaml" | "yml" => SpriteSheetAnimation::from_yaml_bytes(bytes)?,
"ron" => SpriteSheetAnimation::from_ron_bytes(bytes)?,
_ => unreachable!(),
};
load_context.set_default_asset(LoadedAsset::new(custom_asset));
Ok(())
})
}

fn extensions(&self) -> &[&str] {
&["animation.yml", "animation.yaml"]
&["animation.yml", "animation.yaml", "animation.ron"]
}
}

0 comments on commit b5288ac

Please sign in to comment.