NiklasEi / bevy_asset_loader

Bevy plugin helping with asset loading and organization
Apache License 2.0
474 stars 52 forks source link

Array syntax in RON dynamic collections? #78

Open inodentry opened 2 years ago

inodentry commented 2 years ago

Would it be possible to do something like this?

#[derive(AssetCollection)]
struct SpriteAnimationSequences {
    // maybe this needs a new attribute?
    // `collection(array)` or something,
    // to distinguish from `Files`
    #[asset(key = "anim.jumps", collection(typed)]
    jumps: Vec<Handle<TextureAtlas>>,
}
({
    // just use RON "array syntax"
    // to list as many items as we need
    "anim.jumps": [
        TextureAtlas (
            path: "jump_long.png",
            tile_size_x: 24.,
            tile_size_y: 32.,
            columns: 16,
            rows: 1,
        ),
        TextureAtlas (
            path: "jump_med.png",
            tile_size_x: 24.,
            tile_size_y: 32.,
            columns: 12,
            rows: 1,
        ),
        TextureAtlas (
            path: "jump_short.png",
            tile_size_x: 24.,
            tile_size_y: 32.,
            columns: 8,
            rows: 1,
        ),
    ],
})
NiklasEi commented 2 years ago

I thought this would be easily implemented using an untagged enum with a Single and a Vec variant. But I ran into ron-rs/ron#217.