Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Events to opt out of being targeted or untargeted for Observers #14843

Open
ItsDoot opened this issue Aug 21, 2024 · 1 comment
Open

Allow Events to opt out of being targeted or untargeted for Observers #14843

ItsDoot opened this issue Aug 21, 2024 · 1 comment
Labels
A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible D-Macros Code that generates Rust code D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes

Comments

@ItsDoot
Copy link
Contributor

ItsDoot commented Aug 21, 2024

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

Not all Event types can work well when targeted at an entity, or not targeted at an entity. This can end up surprising to users of these event types when they don't read the event's documentation about this, or if the documentation doesn't exist in the first place.

What solution would you like?

Allow Events to opt out of having a target or not having a target by providing two new subtraits:

trait TargetedEvent: Event {}
trait UntargetedEvent: Event {}

That are automatically implemented by default for a given type when using #[derive(Event)], but can be opted out of via a macro attribute:

#[derive(Event)]
#[event(untargeted = false)] // Opt out of untargeted, aka Commands::trigger
#[event(targeted = false)] // Opt out of targeted, aka Commands::trigger_targets
struct MyEvent {
}

Then, Commands/World/etc should have their related signatures updated to be:

impl Commands {
    pub fn trigger(&mut self, event: impl UntargetedEvent);
    pub fn trigger_targets(&mut self, event: impl TargetedEvent, targets: impl TriggerTargets);
}

What alternative(s) have you considered?

Add documentation to all event types that are used with observers.

@ItsDoot ItsDoot added C-Feature A new feature, making something new possible A-ECS Entities, components, systems, and events D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes D-Macros Code that generates Rust code labels Aug 21, 2024
@benfrankel
Copy link
Contributor

benfrankel commented Sep 3, 2024

The same issue is also described in #14272 (without a proposed solution).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible D-Macros Code that generates Rust code D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes
Projects
None yet
Development

No branches or pull requests

2 participants