···55use bevy_ecs::prelude::{Component, RelationshipTarget, World};
66use bevy_ecs::world::DeferredWorld;
7788+/// A system that registers the effect hook for a given type.
89pub fn init_effect_hook<T: Component + StatusEffect>(world: &mut World) {
910 world
1011 .register_component_hooks::<T>()
+2
bevy_status_effects/src/lib.rs
···3838#[derive(Component, Reflect, Eq, PartialEq, Debug, Default, Copy, Clone)]
3939#[reflect(Component, PartialEq, Debug, Default, Clone)]
4040pub enum EffectMode {
4141+ /// Multiple of the same effect can exist at once.
4142 #[default]
4243 Stack,
4444+ /// When an effect is spawned, any existing effects are replaced (despawned).
4345 Replace,
4446 // Todo
4547 // Merge,
+11-6
bevy_status_effects/src/timer.rs
···44use bevy_time::{Time, Timer, TimerMode};
55use std::time::Duration;
6677+/// A timer which is used for status effects and includes a [`TimerMergeMode`].
78pub trait EffectTimer: Sized {
99+ /// Creates a new timer from a duration.
810 fn new(duration: Duration) -> Self;
9111212+ /// Creates a new time from a duration, in seconds.
1013 fn from_seconds(seconds: f32) -> Self {
1114 Self::new(Duration::from_secs_f32(seconds))
1215 }
13161717+ /// A builder that overwrites the current merge mode with a new value.
1418 fn with_mode(self, mode: TimerMergeMode) -> Self;
15191616- /// Merges a new timer (self) into an existing one (other).
2020+ /// Merges an existing timer (other) with the new one (self).
2121+ /// Behaviour depends on the current [`TimerMergeMode`].
1722 fn merge(&mut self, other: &Self);
1823}
1924···2126#[derive(Component, Reflect, Eq, PartialEq, Debug, Clone)]
2227#[reflect(Component, PartialEq, Debug, Clone)]
2328pub struct Lifetime {
2929+ /// Tracks the elapsed time. Once the timer is finished, the entity will be despawned.
2430 pub timer: Timer,
3131+ /// Controls the merge behaviour when an effect is [replaced](super::EffectMode::Replace).
2532 pub mode: TimerMergeMode,
2633}
2734···3845 self
3946 }
40474141- // Todo Remove duplicates, maybe by adding
4242- // ```
4343- // fn merge(&mut self, other: Self, mode: TimerMergeMode)
4444- // ```
4545- // method to `Timer`.
4648 fn merge(&mut self, other: &Self) {
4749 match self.mode {
4850 TimerMergeMode::Replace => {}
···7880#[derive(Component, Reflect, Eq, PartialEq, Debug, Clone)]
7981#[reflect(Component, PartialEq, Debug, Clone)]
8082pub struct Delay {
8383+ /// Tracks the elapsed time.
8184 pub timer: Timer,
8585+ /// Controls the merge behaviour when an effect is [replaced](super::EffectMode::Replace).
8286 pub mode: TimerMergeMode,
8387}
8488···126130 }
127131}
128132133133+/// Controls the merge behaviour of a timer when it's effect is [replaced](super::EffectMode::Replace).
129134#[derive(Reflect, Eq, PartialEq, Debug, Copy, Clone)]
130135#[reflect(PartialEq, Debug, Clone)]
131136pub enum TimerMergeMode {