ron_asset_manager

Crates.ioron_asset_manager
lib.rsron_asset_manager
version0.1.1
sourcesrc
created_at2024-11-09 10:51:38.766628
updated_at2024-11-09 11:03:31.827312
descriptionA dead simple crate to manage Ron based assets which depend on other assets.
homepage
repositoryhttps://github.com/Lommix/ron_asset_manager.git
max_upload_size
id1441976
size18,794
Lorenz (Lommix)

documentation

README

ron asset manager

License: MIT or Apache 2.0 Crate

A dead simple crate to manage Ron based assets which depend on other assets.

Assets can hot reload into a running game state. Use it to your advantage!

How to

Shandle<T> is a thin wrapper around Handle<T> that can be serialized by behaving like a asset path in serialized form.

This crates provides the RonAsset derive macro, RonAssetPlugin and the Shandle. The idea is to mark asset dependencies via attribute.

Currently there is #[asset], #[asset_vec], #[asset_map].

Example

#[derive(Asset, TypePath, RonAsset, Deserialize)]
pub struct Wizard{
    #[asset]
    pub sprite: Shandle<Image>,

    #[asset_map]
    pub sound: HashMap<String, Shandle<AudioSource>>,

    #[asset_vec]
    pub spells: Vec<Shandle<Actions>>,
}

// also you need to register your type.
fn build(&self, app: &mut App) {
    app.add_plugins(RonAssetPlugin::<Wizard>::default());
}

// that's all, time to use it
fn spawn_wizard(server: Res<AssetServer>){
    let wizard_handle = server.load("/enemies/wizard.ron")
    ...
}
(
    sprite: "sprite/wizard.png",
    spells: {
        "death" : "audio/wizard_death.ogg",
        "hit"   : "audio/wizard_hit.ogg",
        "angry" : "audio/wizard_angy.ogg",
    },
    spells: (
        "spells/fireball.ron",
        "spells/lightning.ron",
    )
)

Future plans

Nested structs via another attribute #[ron_struct(field1, field2)].

Commit count: 12

cargo fmt