From b5288acd3e6d99fddf136443e8b4a62d5a66e752 Mon Sep 17 00:00:00 2001 From: Jonathan Cornaz Date: Mon, 20 Jun 2022 20:16:37 +0000 Subject: [PATCH] feat(unstable-load-from-file): load animation files with `.ron` extension --- Cargo.toml | 2 +- assets/coin.animation.ron | 5 +++++ src/animation/load.rs | 8 ++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 assets/coin.animation.ron diff --git a/Cargo.toml b/Cargo.toml index 3d77e10..3651737 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/assets/coin.animation.ron b/assets/coin.animation.ron new file mode 100644 index 0000000..198c3b4 --- /dev/null +++ b/assets/coin.animation.ron @@ -0,0 +1,5 @@ +( + mode: Repeat, + frame_duration: Some(100), + frames: [0, 1, 2, 3, 4], +) diff --git a/src/animation/load.rs b/src/animation/load.rs index b9ef60e..c2cde75 100644 --- a/src/animation/load.rs +++ b/src/animation/load.rs @@ -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"] } }