5 releases (3 breaking)

0.4.0 Apr 16, 2022
0.3.1 Mar 15, 2022
0.3.0 Jan 10, 2022
0.2.0 Apr 19, 2021
0.1.0 Feb 1, 2021

#34 in #ron

Download history 22/week @ 2024-03-11 15/week @ 2024-03-18 2/week @ 2024-03-25 77/week @ 2024-04-01 10/week @ 2024-04-08 9/week @ 2024-04-15 27/week @ 2024-04-22 7/week @ 2024-04-29 10/week @ 2024-05-06 9/week @ 2024-05-13 15/week @ 2024-05-20 10/week @ 2024-05-27 23/week @ 2024-06-03 9/week @ 2024-06-10 6/week @ 2024-06-17 14/week @ 2024-06-24

54 downloads per month
Used in material_designer

MIT license

24KB
50 lines

Custom RON Assets for Bevy

This crate allows you to easily register arbitrary custom data to be loaded by Bevy as an Asset, from files using the RON format.

It minimizes the amount of boilerplate needed for such custom asset types.

You only need to derive the required traits on your custom type, and add a RonAssetPlugin to your App!

Caveat: you need to come up with a unique file name extension for each new asset type. Bevy also requires a unique UUID for TypeUuid.

#[derive(serde::Deserialize)]
#[derive(TypeUuid)]
#[uuid = "1df82c01-9c71-4fa8-adc4-78c5822268f8"]
struct GameItemDescriptionAsset {
    damage: f32,
    durability: f32,
    min_level: u8,
}

fn main() {
    App::new()
        // bevy
        .add_plugins(DefaultPlugins)
        // our asset
        .add_plugin(
            // load `*.item` files
            RonAssetPlugin::<GameItemDescriptionAsset>::new(&["item"])
        )
        .add_startup_system(setup)
        .run();
}

fn setup(server: Res<AssetServer>) {
    // load our item configs!
    let handles = server.load_folder("items");

    // TODO: store the handles somewhere
}

Now you can just create files like assets/items/big_gun.item:

(
  damage: 25.0,
  durability: 170.0,
  min_level: 4,
)

See examples/load_rons.rs for a more elaborate example!

$ cargo run --example load_rons

Compatible Bevy versions

Compatibility of published bevy_asset_ron versions:

bevy bevy_asset_ron
0.7 0.4
0.6 0.3
0.5 0.2
0.4 0.1

Dependencies

~18–36MB
~543K SLoC