Skip to content

Allow registering one-shot system in bsn! #24002

@hxYuki

Description

@hxYuki

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

Allow registering and storing one-shot system enables a decoupled way triggering callbacks.

For example, a Button will do some stuff on Pointer<Press>, and it can also be triggered by pressing "A" button from gamepad when "focused".

bsn! {
    Button
    ...
    on(|ev: On<Pointer<Press>>, mut command: Commands, buttons: Query<&Action>| {
        buttons
            .get(ev.entity)
            .map(|Action(action)| {
                command.run_system(*action);
            })
            .unwrap();
    })
    ...
}

// and in the system handling focused button
fn trigger_focused_button(..., buttons: Query<&Action> ) {
    // the logic to get current focused button
    // ...

    let focused_button = ... // the focused button entity

    buttons
        .get(focused_button)
        .map(|_, Action(action)| {
            command.run_system(*action);
        })
        .unwrap();
}

What solution would you like?

bsn! {
    Button
    Action(callback_system) // helper function may needed
}

#[derive(Component, FromTemplate)]
struct Action(SystemId); 

fn callback_system(...) { ... }

Register once or per scene?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsA-ScenesComposing and serializing ECS objectsC-FeatureA new feature, making something new possibleD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesS-Needs-DesignThis issue requires design work to think about how it would best be accomplishedX-UncontroversialThis work is generally agreed upon

    Type

    No type

    Projects

    Status

    Needs SME Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions