NiklasEi / bevy_asset_loader

Bevy plugin helping with asset loading and organization
Apache License 2.0
452 stars 53 forks source link

Custom hashmap keys #153

Closed Jessie8Bit closed 5 months ago

Jessie8Bit commented 9 months ago

Hello,

I would like to use an custom key for an mapped asset collection. Would it be possible to implement something like this:

#[derive(AssetCollection, Resource)]
pub struct ObjectCollection {
    #[asset(path = "meshes/objects", collection(typed, mapped))]
    pub meshes: HashMap<AssetId, Handle<Mesh>>,
}

pub struct AssetId(String);

impl From<String> for AssetId {
    fn from(name: String) -> Self {
        Self(Path::new(name.as_str()).with_extension("").file_name().unwrap().to_str().unwrap().to_owned())
    }
}