Skip to content

Commit

Permalink
fix: implement MapEntities for OnTrigger
Browse files Browse the repository at this point in the history
  • Loading branch information
mrchantey committed Oct 8, 2024
1 parent af7aafe commit b40ae76
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ where
trigger: &Trigger<Self::Event, Self::TriggerBundle>,
(entity, action): (Entity, &OnTrigger<Self>),
) {
// log::info!("InsertOnTrigger: {:?}", std::any::type_name::<M::Out>());
let out = M::map(trigger, (entity, &action.params));
action.target.insert(commands, entity, out);
}
Expand Down
13 changes: 12 additions & 1 deletion crates/beet_flow/src/actions/on_trigger/on_trigger_action.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::prelude::*;
use bevy::ecs::entity::MapEntities;
use bevy::ecs::reflect::ReflectMapEntities;
use bevy::prelude::*;
use std::marker::PhantomData;

Expand All @@ -8,7 +10,7 @@ use std::marker::PhantomData;
/// The default behavior is to watch and modify itsself.
///
#[derive(Component, Reflect)]
#[reflect(Default, Component)]
#[reflect(Default, Component, MapEntities)]
pub struct OnTrigger<Handler: OnTriggerHandler> {
pub params: Handler::Params,
/// The entities to watch, defaults to [`Self`] if this is empty
Expand All @@ -26,6 +28,15 @@ where
fn default() -> Self { Self::new(Handler::Params::default()) }
}

impl<Handler: OnTriggerHandler> MapEntities for OnTrigger<Handler> {
fn map_entities<M: EntityMapper>(&mut self, entity_mapper: &mut M) {
for entity in self.sources.iter_mut() {
*entity = entity_mapper.map_entity(*entity);
}
self.target.map_entities(entity_mapper);
}
}

impl<Handler: OnTriggerHandler> OnTrigger<Handler> {
pub fn new(params: Handler::Params) -> Self {
Self {
Expand Down
18 changes: 18 additions & 0 deletions crates/beet_flow/src/actions/on_trigger/trigger_target.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bevy::ecs::entity::MapEntities;
use bevy::prelude::*;


Expand All @@ -12,6 +13,23 @@ pub enum TriggerTarget {
Global,
}


impl MapEntities for TriggerTarget {
fn map_entities<M: EntityMapper>(&mut self, entity_mapper: &mut M) {
match self {
Self::This => {}
Self::Entity(entity) => *entity = entity_mapper.map_entity(*entity),
Self::Entities(entities) => {
for entity in entities.iter_mut() {
*entity = entity_mapper.map_entity(*entity);
}
}
Self::Global => {}
}
}
}


impl TriggerTarget {
pub fn trigger(
&self,
Expand Down
1 change: 0 additions & 1 deletion crates/beet_spatial/src/movement/integrate_force.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ pub fn integrate_force(
if let Some(max_velocity) = max_velocity {
**velocity = velocity.0.clamp_length_max(**max_velocity);
}

transform.translation += **velocity * time.delta_seconds();
}
}
Expand Down

0 comments on commit b40ae76

Please sign in to comment.