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,970 changes: 1,161 additions & 809 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exclude = ["assets/", "ci/", ".github/"]
members = ["effect_derive"]

[dependencies]
bevy = { version = "0.18.0", default-features = false }
bevy = { version = "0.19.0", default-features = false }
bevy_pipe_affect_derive = { version = "0.3.0", path = "effect_derive", optional = true }

# bevy with no default features actually depends on all of these, no need to hide them behind flags
Expand All @@ -23,7 +23,7 @@ variadics_please = "1.1.0"
either = "1.15.0"

[dev-dependencies]
bevy = { version = "0.18.0" }
bevy = { version = "0.19.0" }
proptest = "1.8.0"
proptest-derive = "0.6.0"
blake2 = "0.10.6"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ $ cargo run --release --all-features --example example-name
## Compatibility
| bevy | bevy_pipe_affect |
| --- | --- |
| 0.19 | main |
| 0.18 | 0.3 |
| 0.18 | 0.2 |
| 0.17 | 0.1 |
Expand Down
2 changes: 2 additions & 0 deletions src/effects/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ use crate::Effect;
/// struct InitScores(Vec<Entity>);
///
/// impl Command for InitScores {
/// type Out = ();
///
/// fn apply(self, world: &mut World) {
/// world.insert_batch_if_new(self.0.into_iter().map(|entity| (entity, Score(0))));
/// }
Expand Down
33 changes: 10 additions & 23 deletions src/effects/entity_command.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! [`Effect`]s that queue entity-specific `Commands`.
use std::marker::PhantomData;

use bevy::ecs::error::CommandWithEntity;
use bevy::prelude::*;

use crate::Effect;
Expand All @@ -20,7 +19,6 @@ use crate::Effect;
/// In this example, a system is written that removes all components from the `Player` entity
/// except for the `Player` component.
/// ```rust
/// use bevy::ecs::error::CommandWithEntity;
/// use bevy::ecs::system::entity_command::retain;
/// use bevy::ecs::world::error::EntityMutableFetchError;
/// use bevy::prelude::*;
Expand All @@ -32,11 +30,7 @@ use crate::Effect;
/// /// Pure system using effects.
/// fn reset_player_pure(
/// player: Single<Entity, With<Player>>,
/// ) -> EntityCommandQueue<
/// impl EntityCommand<()> + CommandWithEntity<Result<(), EntityMutableFetchError>> + use<>,
/// (),
/// Result<(), EntityMutableFetchError>,
/// > {
/// ) -> EntityCommandQueue<impl EntityCommand + use<>> {
/// entity_command_queue(*player, retain::<Player>())
/// }
///
Expand Down Expand Up @@ -105,42 +99,35 @@ use crate::Effect;
/// ```
#[doc = include_str!("defer_command_note.md")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct EntityCommandQueue<C, T, M>
pub struct EntityCommandQueue<C>
where
C: EntityCommand<T> + CommandWithEntity<M>,
C: EntityCommand,
{
entity: Entity,
command: C,
entity_command_out: PhantomData<T>,
command_with_entity_out: PhantomData<M>,
}

impl<C, T, M> EntityCommandQueue<C, T, M>
impl<C> EntityCommandQueue<C>
where
C: EntityCommand<T> + CommandWithEntity<M>,
C: EntityCommand,
{
/// Construct a new [`EntityCommandQueue`]
pub fn new(entity: Entity, command: C) -> Self {
EntityCommandQueue {
entity,
command,
entity_command_out: PhantomData,
command_with_entity_out: PhantomData,
}
EntityCommandQueue { entity, command }
}
}

/// Construct a new [`EntityCommandQueue`] [`Effect`].
pub fn entity_command_queue<C, T, M>(entity: Entity, command: C) -> EntityCommandQueue<C, T, M>
pub fn entity_command_queue<C>(entity: Entity, command: C) -> EntityCommandQueue<C>
where
C: EntityCommand<T> + CommandWithEntity<M>,
C: EntityCommand,
{
EntityCommandQueue::new(entity, command)
}

impl<C, T, M> Effect for EntityCommandQueue<C, T, M>
impl<C> Effect for EntityCommandQueue<C>
where
C: EntityCommand<T> + CommandWithEntity<M>,
C: EntityCommand,
{
type MutParam = Commands<'static, 'static>;

Expand Down
6 changes: 3 additions & 3 deletions src/effects/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! On top of the types shown here, this implements [`Effect`] for...
//! - `Result<T, E>` where `T: Effect` and `E: Into<BevyError>`
use bevy::ecs::error::{DefaultErrorHandler, ErrorContext};
use bevy::ecs::error::{ErrorContext, FallbackErrorHandler};
use bevy::ecs::system::{SystemChangeTick, SystemName};
use bevy::prelude::*;

Expand Down Expand Up @@ -33,7 +33,7 @@ use crate::Effect;
/// bevy::ecs::system::assert_is_system(zero_red_clear_color_srgba.pipe(affect))
/// ```
///
/// Using a plain `Result` as an effect works too, but uses `bevy`'s `DefaultErrorHandler`.
/// Using a plain `Result` as an effect works too, but uses `bevy`'s `FallbackErrorHandler`.
///
/// Can be constructed with [`affect_or_handle`].
#[derive(derive_more::Debug)]
Expand Down Expand Up @@ -123,7 +123,7 @@ where
Er: Into<BevyError>,
{
type MutParam = (
Option<Res<'static, DefaultErrorHandler>>,
Option<Res<'static, FallbackErrorHandler>>,
(Ef::MutParam, SystemName, SystemChangeTick),
);

Expand Down
4 changes: 2 additions & 2 deletions src/effects/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ where
/// });
/// }
/// #
/// # use bevy::ecs::error::{ignore, DefaultErrorHandler};
/// # use bevy::ecs::error::{ignore, FallbackErrorHandler};
/// # use proptest::prelude::*;
/// #
/// # fn app_setup(
Expand All @@ -147,7 +147,7 @@ where
/// # ) -> App {
/// # let mut app = App::new();
/// # app.add_message::<Winner>()
/// # .insert_resource(DefaultErrorHandler(ignore));
/// # .insert_resource(FallbackErrorHandler(ignore));
/// #
/// # let entities = component_table
/// # .into_iter()
Expand Down
7 changes: 4 additions & 3 deletions src/effects/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ where
type MutParam = Query<'static, 'static, QueryDataE::MutQueryData, Filter>;

fn affect(self, param: &mut <Self::MutParam as bevy::ecs::system::SystemParam>::Item<'_, '_>) {
param
.iter_mut()
.for_each(|mut query_data| self.query_data_effect.clone().affect(&mut query_data));
let mut iter = param.iter_mut();
while let Some(mut query_data) = iter.fetch_next() {
self.query_data_effect.clone().affect(&mut query_data);
}
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/effects/query_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{Effect, EffectOut};

/// [`Effect`] that applies the given [`QueryDataEffect`] to the given entity.
///
/// Produces an error (handled by `bevy`'s `DefaultErrorHandler`) if the entity does not exist in
/// Produces an error (handled by `bevy`'s `FallbackErrorHandler`) if the entity does not exist in
/// the [`QueryDataEffect::Filter`] (and the optional `Filter` generic).
///
/// Can be constructed by [`query_entity_affect`].
Expand Down Expand Up @@ -43,13 +43,13 @@ use crate::{Effect, EffectOut};
/// query.get_mut(top_player.0)?.0 = 0.5;
/// Ok(())
/// }
/// # use bevy::ecs::error::{ignore, DefaultErrorHandler};
/// # use bevy::ecs::error::{ignore, FallbackErrorHandler};
/// # use proptest::prelude::*;
/// #
/// # fn app_setup(entity_table: Vec<Option<Defense>>, top_player_index: usize) -> App {
/// # let mut app = App::new();
/// #
/// # app.insert_resource(DefaultErrorHandler(ignore));
/// # app.insert_resource(FallbackErrorHandler(ignore));
/// #
/// # let entities = entity_table.into_iter().fold(
/// # vec![app.world_mut().spawn_empty().id()],
Expand Down Expand Up @@ -162,7 +162,7 @@ where
/// [`Effect`] that applies the given mapping of `QueryData` to [`QueryDataEffect`] to the given
/// entity, and applies the [`QueryDataEffect`].
///
/// Produces an error (handled by `bevy`'s `DefaultErrorHandler`) if the entity isn't selected by
/// Produces an error (handled by `bevy`'s `FallbackErrorHandler`) if the entity isn't selected by
/// `QueryDataIn`'s or `QueryDataE`'s filters or the optional `Filter` generic.
///
/// Can be constructed by [`query_entity_map`].
Expand Down Expand Up @@ -203,13 +203,13 @@ where
/// attack_multiplier.0 = 1.0 + ((100.0 - health.0) / 100.0);
/// Ok(())
/// }
/// # use bevy::ecs::error::{ignore, DefaultErrorHandler};
/// # use bevy::ecs::error::{ignore, FallbackErrorHandler};
/// # use proptest::prelude::*;
/// #
/// # fn app_setup(entity_table: Vec<(Option<Health>, Option<AttackMultiplier>)>, bottom_player_index: usize) -> App {
/// # let mut app = App::new();
/// #
/// # app.insert_resource(DefaultErrorHandler(ignore));
/// # app.insert_resource(FallbackErrorHandler(ignore));
/// #
/// # let entities = entity_table.into_iter().fold(
/// # vec![app.world_mut().spawn_empty().id()],
Expand Down Expand Up @@ -345,7 +345,7 @@ where
/// (as an `EffectOut<Effect, QueryDataEffect>` to the given entity, and applies the
/// [`QueryDataEffect`] + [`Effect`].
///
/// Produces an error (handled by `bevy`'s `DefaultErrorHandler`) if the entity isn't selected by
/// Produces an error (handled by `bevy`'s `FallbackErrorHandler`) if the entity isn't selected by
/// `QueryDataIn`'s or `QueryDataE`'s filters or the optional `Filter` generic.
///
/// Can be constructed by [`query_entity_map_and`].
Expand Down Expand Up @@ -395,13 +395,13 @@ where
/// }
/// Ok(())
/// }
/// # use bevy::ecs::error::{ignore, DefaultErrorHandler};
/// # use bevy::ecs::error::{ignore, FallbackErrorHandler};
/// # use proptest::prelude::*;
/// #
/// # fn app_setup(entity_table: Vec<Option<Health>>, cursed_player_index: usize) -> App {
/// # let mut app = App::new();
/// #
/// # app.insert_resource(DefaultErrorHandler(ignore));
/// # app.insert_resource(FallbackErrorHandler(ignore));
/// #
/// # let entities = entity_table.into_iter().fold(
/// # vec![app.world_mut().spawn_empty().id()],
Expand Down
15 changes: 8 additions & 7 deletions src/effects/resource.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! [`Effect`]s that modify resources.
use std::any::type_name;

use bevy::ecs::component::Mutable;
use bevy::ecs::system::SystemParam;
use bevy::prelude::*;

Expand Down Expand Up @@ -61,7 +62,7 @@ use crate::effect::Effect;
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub struct ResSet<R>
where
R: Resource,
R: Resource + Component<Mutability = Mutable>,
{
/// The value that the resource will be set to.
pub value: R,
Expand All @@ -70,14 +71,14 @@ where
/// Construct a new [`ResSet`] [`Effect`].
pub fn res_set<R>(value: R) -> ResSet<R>
where
R: Resource,
R: Resource + Component<Mutability = Mutable>,
{
ResSet { value }
}

impl<R> Effect for ResSet<R>
where
R: Resource,
R: Resource + Component<Mutability = Mutable>,
{
type MutParam = ResMut<'static, R>;

Expand Down Expand Up @@ -141,7 +142,7 @@ where
#[derive(derive_more::Debug)]
pub struct ResSetWith<R>
where
R: Resource,
R: Resource + Component<Mutability = Mutable>,
{
/// The function that maps the resource to its new value.
#[debug("{} -> {}", type_name::<&R>(), type_name::<R>())]
Expand All @@ -152,14 +153,14 @@ where
pub fn res_set_with<F, R>(f: F) -> ResSetWith<R>
where
F: FnOnce(&R) -> R + 'static,
R: Resource,
R: Resource + Component<Mutability = Mutable>,
{
ResSetWith { f: Box::new(f) }
}

impl<R> Default for ResSetWith<R>
where
R: Resource + Clone,
R: Resource + Component<Mutability = Mutable> + Clone,
{
fn default() -> Self {
res_set_with(|r: &R| r.clone())
Expand All @@ -168,7 +169,7 @@ where

impl<R> Effect for ResSetWith<R>
where
R: Resource,
R: Resource + Component<Mutability = Mutable>,
{
type MutParam = ResMut<'static, R>;

Expand Down
2 changes: 1 addition & 1 deletion tests/derive_compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn effect_with_effect_parameter_implements_effect() {
>());
}

#[derive(Clone, Component, Resource)]
#[derive(Clone, Resource)]
struct MyComponentResource;

#[derive(Effect)]
Expand Down
Loading