Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,048 changes: 603 additions & 445 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ version = "0.1.0"
edition = "2021"

[dependencies]
bevy = "0.15.2"
bevy = "0.16.1"
variadics_please = "1.1.0"

[dev-dependencies]
proptest = "1.6.0"
proptest-derive = "0.5.1"
blake2 = "0.10.2"
proptest = "1.7.0"
proptest-derive = "0.6.0"
blake2 = "0.10.6"
2 changes: 1 addition & 1 deletion mvp-effects.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*Need to research.. Could lead to confusing experience about which system the parameter is local to.*

# Event Effects
- [x] `EventSend`
- [x] `EventWrite`

# Components Effects
- [x] `ComponentsPut`
Expand Down
2 changes: 1 addition & 1 deletion src/effect.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy::ecs::system::SystemParam;
use bevy::prelude::*;
use bevy::utils::all_tuples;
use variadics_please::all_tuples;

/// Define a state transition in `bevy`'s ECS.
///
Expand Down
15 changes: 8 additions & 7 deletions src/effects/components.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::marker::PhantomData;

use bevy::ecs::query::{QueryFilter, ReadOnlyQueryData, WorldQuery};
use bevy::ecs::component::Mutable;
use bevy::ecs::query::{QueryData, QueryFilter, ReadOnlyQueryData};
use bevy::ecs::system::SystemParam;
use bevy::prelude::*;
use bevy::utils::all_tuples;
use variadics_please::all_tuples;

use crate::Effect;

Expand Down Expand Up @@ -38,7 +39,7 @@ macro_rules! impl_effect_for_components_put {
($(($C:ident, $c:ident, $r:ident)),*) => {
impl<$($C,)* Filter> Effect for ComponentsPut<($($C,)*), Filter>
where
$($C: Component + Clone),*,
$($C: Component<Mutability = Mutable> + Clone),*,
Filter: QueryFilter + 'static,
{
type MutParam = Query<'static, 'static, ($(&'static mut $C,)*), Filter>;
Expand All @@ -63,7 +64,7 @@ all_tuples!(impl_effect_for_components_put, 1, 15, C, c, r);
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub struct ComponentsWith<F, C, Data = (), Filter = ()>
where
F: for<'a> Fn(C, <Data as WorldQuery>::Item<'a>) -> C + Send + Sync,
F: for<'a> Fn(C, <Data as QueryData>::Item<'a>) -> C + Send + Sync,
C: Clone,
Data: ReadOnlyQueryData,
Filter: QueryFilter,
Expand All @@ -76,7 +77,7 @@ where

impl<F, C, Data, Filter> ComponentsWith<F, C, Data, Filter>
where
F: for<'a> Fn(C, <Data as WorldQuery>::Item<'a>) -> C + Send + Sync,
F: for<'a> Fn(C, <Data as QueryData>::Item<'a>) -> C + Send + Sync,
C: Clone,
Data: ReadOnlyQueryData,
Filter: QueryFilter,
Expand All @@ -96,8 +97,8 @@ macro_rules! impl_effect_for_components_with {
($(($C:ident, $c:ident, $r:ident)),*) => {
impl<F, $($C,)* Data, Filter> Effect for ComponentsWith<F, ($($C,)*), Data, Filter>
where
F: for<'a> Fn(($($C,)*), <Data as WorldQuery>::Item<'a>) -> ($($C,)*) + Send + Sync,
$($C: Component + Clone),*,
F: for<'a> Fn(($($C,)*), <Data as QueryData>::Item<'a>) -> ($($C,)*) + Send + Sync,
$($C: Component<Mutability = Mutable> + Clone),*,
Data: ReadOnlyQueryData + 'static,
Filter: QueryFilter + 'static,
{
Expand Down
15 changes: 8 additions & 7 deletions src/effects/entity_components.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::marker::PhantomData;

use bevy::ecs::query::{ReadOnlyQueryData, WorldQuery};
use bevy::ecs::component::Mutable;
use bevy::ecs::query::{QueryData, ReadOnlyQueryData};
use bevy::ecs::system::SystemParam;
use bevy::prelude::*;
use bevy::utils::all_tuples;
use variadics_please::all_tuples;

use crate::Effect;

Expand All @@ -27,7 +28,7 @@ macro_rules! impl_effect_for_entity_components_put {
($(($C:ident, $c:ident, $r:ident)),*) => {
impl<$($C),*> Effect for EntityComponentsPut<($($C,)*)>
where
$($C: Component,)*
$($C: Component<Mutability = Mutable>,)*
{
type MutParam = Query<'static, 'static, ($(&'static mut $C,)*)>;

Expand Down Expand Up @@ -58,7 +59,7 @@ all_tuples!(impl_effect_for_entity_components_put, 1, 15, C, c, r);
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct EntityComponentsWith<F, C, Data = ()>
where
F: for<'a> Fn(C, <Data as WorldQuery>::Item<'a>) -> C + Send + Sync,
F: for<'a> Fn(C, <Data as QueryData>::Item<'a>) -> C + Send + Sync,
C: Clone,
Data: ReadOnlyQueryData,
{
Expand All @@ -70,7 +71,7 @@ where

impl<F, C, Data> EntityComponentsWith<F, C, Data>
where
F: for<'a> Fn(C, <Data as WorldQuery>::Item<'a>) -> C + Send + Sync,
F: for<'a> Fn(C, <Data as QueryData>::Item<'a>) -> C + Send + Sync,
C: Clone,
Data: ReadOnlyQueryData,
{
Expand All @@ -89,8 +90,8 @@ macro_rules! impl_effect_for_entity_components_with {
($(($C:ident, $c:ident, $r:ident)),*) => {
impl<F, $($C,)* Data> Effect for EntityComponentsWith<F, ($($C,)*), Data>
where
F: for<'a> Fn(($($C,)*), <Data as WorldQuery>::Item<'a>) -> ($($C,)*) + Send + Sync,
$($C: Component + Clone,)*
F: for<'a> Fn(($($C,)*), <Data as QueryData>::Item<'a>) -> ($($C,)*) + Send + Sync,
$($C: Component<Mutability = Mutable> + Clone,)*
Data: ReadOnlyQueryData + 'static,
{
type MutParam = Query<'static, 'static, (($(&'static mut $C,)*), Data)>;
Expand Down
8 changes: 4 additions & 4 deletions src/effects/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ use crate::Effect;

/// [`Effect`] that sends an event `E` to the corresponding `EventWriter`.
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub struct EventSend<E>(pub E)
pub struct EventWrite<E>(pub E)
where
E: Event;

impl<E> Effect for EventSend<E>
impl<E> Effect for EventWrite<E>
where
E: Event,
{
type MutParam = EventWriter<'static, E>;

fn affect(self, param: &mut <Self::MutParam as bevy::ecs::system::SystemParam>::Item<'_, '_>) {
param.send(self.0);
param.write(self.0);
}
}

Expand All @@ -34,7 +34,7 @@ mod tests {

let mut events_clone = events.clone();
app.add_event::<NumberEvent>()
.add_systems(Update, (move || EventSend(events_clone.remove(0))).pipe(affect));
.add_systems(Update, (move || EventWrite(events_clone.remove(0))).pipe(affect));

for expected in events {
app.update();
Expand Down
2 changes: 1 addition & 1 deletion src/effects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod resource;
pub use resource::{ResPut, ResWith};

mod event;
pub use event::EventSend;
pub use event::EventWrite;

mod components;
pub use components::{ComponentsPut, ComponentsWith};
Expand Down
2 changes: 1 addition & 1 deletion src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub use crate::effects::{
ComponentsWith,
EntityComponentsPut,
EntityComponentsWith,
EventSend,
EventWrite,
ResPut,
ResWith,
};
Expand Down