Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • microhacks/micro-bevy-world-utils
1 result
Show changes
Commits on Source (2)
[package]
name = "micro_bevy_world_utils"
version = "0.5.0"
version = "0.7.0"
edition = "2021"
license = "Apache-2.0"
description = "Handy, reusable utilities for working with direct world access in a Bevy exclusive system"
......@@ -10,6 +10,4 @@ authors = [
repository = "https://lab.lcr.gr/microhacks/micro-bevy-world-utils"
[dependencies]
bevy_ecs = "0.14"
bevy_hierarchy = "0.14"
bevy_ecs = "0.16"
......@@ -35,6 +35,7 @@ the given entities, the result will be `None`
| world_utiles ver | bevy ver |
|------------------|----------|
| 0.6 | 0.15 |
| 0.5 | 0.14 |
| 0.4 | 0.13 |
| 0.3 | 0.11 |
......
......@@ -16,10 +16,8 @@
//!
//! `{specifier}` takes the following form: `[any_](left|right)[[_any]_parent]`
//!
//! - `any_` implies that no components need to be matched for that side of the query to be
//! successful. This would be equivalent to supplying `()` to the version without `any_`
//! - `_parent` implies that the returned entity for that side will, if a match is found, be the
//! _parent_ entity of the matching input entity.
//! - `any_` implies that no components need to be matched for that side of the query to be successful. This would be equivalent to supplying `()` to the version without `any_`
//! - `_parent` implies that the returned entity for that side will, if a match is found, be the _parent_ entity of the matching input entity.
//!
//! **N.B.** The left component will always be queried first
//!
......@@ -37,7 +35,7 @@ use bevy_ecs::{
system::{Query, SystemState},
world::World,
};
use bevy_hierarchy::Parent;
use bevy_ecs::hierarchy::ChildOf;
pub type Left = Entity;
pub type Right = Entity;
......@@ -74,20 +72,20 @@ fn inner_get_left_right_parent_entities<
) -> Option<SortedEntities> {
let mut state = SystemState::<(
Query<(), LeftSide>,
Query<&Parent, RightSide>,
Query<&ChildOf, RightSide>,
Query<(), ParentSide>,
)>::new(world);
let (left_query, right_query, parent_query) = state.get(world);
if left_query.contains(*first) {
if let Ok(parent) = right_query.get(*second) {
let parent = parent.get();
if let Ok(related) = right_query.get(*second) {
let parent = related.parent();
if parent_query.contains(parent) {
return Some((*first, parent));
}
}
} else if left_query.contains(*second) {
if let Ok(parent) = right_query.get(*first) {
let parent = parent.get();
if let Ok(related) = right_query.get(*first) {
let parent = related.parent();
if parent_query.contains(parent) {
return Some((*second, parent));
}
......@@ -108,25 +106,25 @@ fn inner_get_left_parent_right_parent_entities<
second: &Entity,
) -> Option<SortedEntities> {
let mut state = SystemState::<(
Query<&Parent, LeftSide>,
Query<&Parent, RightSide>,
Query<&ChildOf, LeftSide>,
Query<&ChildOf, RightSide>,
Query<(), LeftParent>,
Query<(), RightParent>,
)>::new(world);
let (left_query, right_query, left_parent_query, right_parent_query) = state.get(world);
if let Ok(left_parent) = left_query.get(*first) {
if left_parent_query.contains(left_parent.get()) {
if left_parent_query.contains(left_parent.parent()) {
if let Ok(right_parent) = right_query.get(*second) {
if right_parent_query.contains(right_parent.get()) {
return Some((left_parent.get(), right_parent.get()));
if right_parent_query.contains(right_parent.parent()) {
return Some((left_parent.parent(), right_parent.parent()));
}
}
}
} else if let Ok(left_parent) = left_query.get(*second) {
if left_parent_query.contains(left_parent.get()) {
if left_parent_query.contains(left_parent.parent()) {
if let Ok(right_parent) = right_query.get(*first) {
if right_parent_query.contains(right_parent.get()) {
return Some((left_parent.get(), right_parent.get()));
if right_parent_query.contains(right_parent.parent()) {
return Some((left_parent.parent(), right_parent.parent()));
}
}
}
......@@ -231,15 +229,15 @@ pub fn get_any_left_parent_any_right_parent_entities<
///
/// #[derive(Event)]
/// struct MyEventType {
/// message: usize
/// message: usize
/// }
///
/// // Do some app setup
///
/// use micro_bevy_world_utils::send_event;
/// pub fn my_world_system(world: &mut World) {
/// // Do some processing here
/// send_event(world, MyEventType { message: 1234 });
/// // Do some processing here
/// send_event(world, MyEventType { message: 1234 });
/// }
/// ```
pub fn send_event<Event: bevy_ecs::event::Event + Sync + Send + 'static>(
......@@ -248,7 +246,7 @@ pub fn send_event<Event: bevy_ecs::event::Event + Sync + Send + 'static>(
) {
SystemState::<EventWriter<Event>>::new(world)
.get_mut(world)
.send(event);
.write(event);
}
/// Clone the data from a specific component of the target entity, as long as that entity
......