Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
StarArawn authored Aug 14, 2024
2 parents 0a5432f + 68b2c94 commit d3b1480
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.8.1

- Added the `E: EntityEvent` bound to `EventlistenerPlugin<E>`, to move compile errors from adding the plugin, to the event itself.
- Fixed a benchmark bug.
- Added helpful error message when `EntityEvent` derive macro fails to find `#[target]`.

# 0.8.0

- Updated to Bevy `0.14.0`
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resolver = "2"

[package]
name = "bevy_eventlistener"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Event listeners and callbacks for bevy"
license = "MIT OR Apache-2.0"
Expand Down
3 changes: 2 additions & 1 deletion benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ fn event_listeners(c: &mut Criterion) {
(
spawn_listener_hierarchy,
add_listeners_to_hierarchy::<DENSITY, 1>,
),
)
.chain(),
)
.add_plugins(EventListenerPlugin::<TestEvent<1>>::default())
.add_systems(First, send_events::<1, N_EVENTS>);
Expand Down
2 changes: 1 addition & 1 deletion macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_eventlistener_derive"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
description = "Event listeners and callbacks for bevy"
license = "MIT OR Apache-2.0"
Expand Down
14 changes: 8 additions & 6 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ pub fn derive(input: TokenStream) -> TokenStream {
// Get attributes #[..] on each field
for attr in field.attrs.iter() {
// Parse the attribute
match attr.meta {
// Find the duplicated idents
syn::Meta::Path(ref path) if path.get_ident().unwrap() == "target" => {
target = Some(field.ident.clone());
if let syn::Meta::Path(ref path) = attr.meta {
if let Some(ident) = path.get_ident() {
if ident == "target" {
target = Some(field.ident.clone());
}
}
_ => (),
}
}
}
Expand All @@ -44,7 +44,9 @@ pub fn derive(input: TokenStream) -> TokenStream {
_ => panic!("Must be a struct"),
}

let target = target.unwrap();
let Some(target) = target else {
panic!("Missing `#[target] attribute. You must annotate the field with the target Entity, or instead manually implement EntityEvent.")
};

let gen = quote! {
impl #impl_generics EntityEvent for #name #ty_generics #where_clause {
Expand Down
4 changes: 2 additions & 2 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use crate::{event_dispatcher::EventDispatcher, event_listener::EntityEvent};
pub struct EventListenerSet;

/// Adds event listening and bubbling support for event `E`.
pub struct EventListenerPlugin<E>(std::marker::PhantomData<E>);
pub struct EventListenerPlugin<E: EntityEvent>(std::marker::PhantomData<E>);

impl<E> Default for EventListenerPlugin<E> {
impl<E: EntityEvent> Default for EventListenerPlugin<E> {
fn default() -> Self {
Self(std::marker::PhantomData)
}
Expand Down

0 comments on commit d3b1480

Please sign in to comment.