From b40ae76303f3566c561034c5de2cba807239811c Mon Sep 17 00:00:00 2001 From: Peter Hayman Date: Tue, 8 Oct 2024 16:57:19 +1100 Subject: [PATCH] fix: implement MapEntities for OnTrigger --- .../actions/on_trigger/insert_on_trigger.rs | 1 + .../actions/on_trigger/on_trigger_action.rs | 13 ++++++++++++- .../src/actions/on_trigger/trigger_target.rs | 18 ++++++++++++++++++ .../src/movement/integrate_force.rs | 1 - 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/crates/beet_flow/src/actions/on_trigger/insert_on_trigger.rs b/crates/beet_flow/src/actions/on_trigger/insert_on_trigger.rs index 6e76633c..8b7f179d 100644 --- a/crates/beet_flow/src/actions/on_trigger/insert_on_trigger.rs +++ b/crates/beet_flow/src/actions/on_trigger/insert_on_trigger.rs @@ -23,6 +23,7 @@ where trigger: &Trigger, (entity, action): (Entity, &OnTrigger), ) { + // log::info!("InsertOnTrigger: {:?}", std::any::type_name::()); let out = M::map(trigger, (entity, &action.params)); action.target.insert(commands, entity, out); } diff --git a/crates/beet_flow/src/actions/on_trigger/on_trigger_action.rs b/crates/beet_flow/src/actions/on_trigger/on_trigger_action.rs index 3c74d397..ade20ab8 100644 --- a/crates/beet_flow/src/actions/on_trigger/on_trigger_action.rs +++ b/crates/beet_flow/src/actions/on_trigger/on_trigger_action.rs @@ -1,4 +1,6 @@ use crate::prelude::*; +use bevy::ecs::entity::MapEntities; +use bevy::ecs::reflect::ReflectMapEntities; use bevy::prelude::*; use std::marker::PhantomData; @@ -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 { pub params: Handler::Params, /// The entities to watch, defaults to [`Self`] if this is empty @@ -26,6 +28,15 @@ where fn default() -> Self { Self::new(Handler::Params::default()) } } +impl MapEntities for OnTrigger { + fn map_entities(&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 OnTrigger { pub fn new(params: Handler::Params) -> Self { Self { diff --git a/crates/beet_flow/src/actions/on_trigger/trigger_target.rs b/crates/beet_flow/src/actions/on_trigger/trigger_target.rs index 95250c1d..83bc6eb2 100644 --- a/crates/beet_flow/src/actions/on_trigger/trigger_target.rs +++ b/crates/beet_flow/src/actions/on_trigger/trigger_target.rs @@ -1,3 +1,4 @@ +use bevy::ecs::entity::MapEntities; use bevy::prelude::*; @@ -12,6 +13,23 @@ pub enum TriggerTarget { Global, } + +impl MapEntities for TriggerTarget { + fn map_entities(&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, diff --git a/crates/beet_spatial/src/movement/integrate_force.rs b/crates/beet_spatial/src/movement/integrate_force.rs index 2b2d375a..e9225c87 100644 --- a/crates/beet_spatial/src/movement/integrate_force.rs +++ b/crates/beet_spatial/src/movement/integrate_force.rs @@ -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(); } }