Skip to content

Allow the creation of handles from runtime values in bsn! #23822

@hxYuki

Description

@hxYuki

What problem does this solve or what need does it fill?

You will still need to pass a handle from outside or add it manually in template(...).

pub fn demo(atlas: Handle<TextureAtlasLayout>) -> impl Scene {
    bsn! {
        ImageNode {
            image: "images/button.png",
            texture_atlas: { TextureAtlasTemplate {
                layout: HandleTemplate::Handle(atlas.clone()),
                index: 0,
            }},
        }
    }
}

// or
pub fn demo2() -> impl Scene {
    bsn! {
        template(|ctx| {
            Ok(ImageNode {
                image: ctx.resource::<AssetServer>().load("images/button.png"),
                texture_atlas: Some(TextureAtlas {
                    layout: ctx.resource_mut::<Assets<TextureAtlasLayout>>().add(
                        TextureAtlasLayout::from_grid(UVec2::new(65, 12), 1, 3, None, None)
                    ),
                    index: 0,
                }),
                ..default()
            })
        })
    }
}

Allowing create a handle in-place when authoring a scene function. It is more ergonomic to compose related data of one component.

What solution would you like?

Add a HandleTemplate::Insert(...) to create a handle directly from value.

pub fn demo() -> impl Scene {
    bsn! {
        ImageNode {
            image: "images/button.png",
            texture_atlas: { TextureAtlasTemplate {
                layout: HandleTemplate::Insert(TextureAtlasLayout::from_grid(UVec2::new(65, 12), 1, 3, None, None)),
                index: 0,
            }},
        }
    }
}

Additional context

This may also works when composing a bsn file, I think.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AssetsLoad files from disk to use for things like images, models, and soundsA-ScenesComposing and serializing ECS objectsC-FeatureA new feature, making something new possibleD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesS-BlockedThis cannot move forward until something else changesX-UncontroversialThis work is generally agreed upon

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Needs SME Triage

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions