bevy_assets_extensions 0.7.1

Extensions for bevy assets, with support of collection as assets and a loader manager.
Documentation
use bevy::{
    asset::{ErasedLoadedAsset, LoadedAsset},
    platform::collections::HashMap,
    prelude::*,
};
use serde::{Deserialize, Serialize};

use super::{AssetsBundle, BundleValue, call_load_from};

crate::reflect_serde::reflect_serde!(TextureSlicer => texture_slicer);

/// Entry in a bundle
#[derive(Deserialize, Serialize, Debug)]
#[non_exhaustive]
pub enum BundleEntry {
    /// Load asset from the given file.
    File(String),
    /// Bundle of assets.
    Bundle(HashMap<String, BundleEntry>),
    /// List of assets.
    List(Vec<BundleEntry>),
    /// List of string
    StringList(Vec<String>),
    /// Indicate a text resource
    Text(String),
    /// A Value
    Value(BundleValue),
    /// Floating-point number
    Float(f64),
    /// Ui Rectangle
    UiRect(UiRect),
    /// Color
    Color(Color),
    /// Texture Slicer
    #[serde(
        serialize_with = "ser_reflect_texture_slicer",
        deserialize_with = "de_reflect_texture_slicer"
    )]
    /// Floating-point number
    TextureSlicer(TextureSlicer),
    /// Texture Atlas layout
    #[cfg(feature = "atlas_layout")]
    TextureAtlasLayout(crate::assets::atlas_layout::AtlasLayoutDefinition),
}

impl BundleEntry {
    /// Load the asset described by this entry.
    pub async fn load_asset(
        self,
        key: &str,
        load_context: &mut bevy::asset::LoadContext<'_>,
    ) -> Result<ErasedLoadedAsset> {
        match self {
            BundleEntry::File(path) => {
                let path = load_context.asset_path().parent().unwrap().resolve(&path)?;
                Ok(load_context
                    .loader()
                    .immediate()
                    .with_unknown_type()
                    .load(path)
                    .await?)
            }
            BundleEntry::Bundle(assets) => Ok(LoadedAsset::new_with_dependencies(
                call_load_from!(
                    AssetsBundle,
                    key.to_string(),
                    BundleEntry::Bundle(assets),
                    load_context
                )
                .await?,
            )
            .into()),
            BundleEntry::List(_) => todo!(),
            BundleEntry::StringList(_) => todo!(),
            BundleEntry::Text(content) => Ok(LoadedAsset::new_with_dependencies(
                crate::prelude::assets::Text::new(content),
            )
            .into()),
            BundleEntry::Value(_) => todo!(),
            BundleEntry::Float(_) => todo!(),
            BundleEntry::Color(_) => todo!(),
            BundleEntry::UiRect(_) => todo!(),
            BundleEntry::TextureSlicer(_) => todo!(),
            #[cfg(feature = "atlas_layout")]
            BundleEntry::TextureAtlasLayout(layout) => {
                let atlas: TextureAtlasLayout = layout.into();
                Ok(LoadedAsset::new_with_dependencies(atlas).into())
            }
        }
    }
}