An experimental, status effects-as-entities system for Bevy.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Documentation.

+14 -6
+1
bevy_status_effects/src/hook.rs
··· 5 5 use bevy_ecs::prelude::{Component, RelationshipTarget, World}; 6 6 use bevy_ecs::world::DeferredWorld; 7 7 8 + /// A system that registers the effect hook for a given type. 8 9 pub fn init_effect_hook<T: Component + StatusEffect>(world: &mut World) { 9 10 world 10 11 .register_component_hooks::<T>()
+2
bevy_status_effects/src/lib.rs
··· 38 38 #[derive(Component, Reflect, Eq, PartialEq, Debug, Default, Copy, Clone)] 39 39 #[reflect(Component, PartialEq, Debug, Default, Clone)] 40 40 pub enum EffectMode { 41 + /// Multiple of the same effect can exist at once. 41 42 #[default] 42 43 Stack, 44 + /// When an effect is spawned, any existing effects are replaced (despawned). 43 45 Replace, 44 46 // Todo 45 47 // Merge,
+11 -6
bevy_status_effects/src/timer.rs
··· 4 4 use bevy_time::{Time, Timer, TimerMode}; 5 5 use std::time::Duration; 6 6 7 + /// A timer which is used for status effects and includes a [`TimerMergeMode`]. 7 8 pub trait EffectTimer: Sized { 9 + /// Creates a new timer from a duration. 8 10 fn new(duration: Duration) -> Self; 9 11 12 + /// Creates a new time from a duration, in seconds. 10 13 fn from_seconds(seconds: f32) -> Self { 11 14 Self::new(Duration::from_secs_f32(seconds)) 12 15 } 13 16 17 + /// A builder that overwrites the current merge mode with a new value. 14 18 fn with_mode(self, mode: TimerMergeMode) -> Self; 15 19 16 - /// Merges a new timer (self) into an existing one (other). 20 + /// Merges an existing timer (other) with the new one (self). 21 + /// Behaviour depends on the current [`TimerMergeMode`]. 17 22 fn merge(&mut self, other: &Self); 18 23 } 19 24 ··· 21 26 #[derive(Component, Reflect, Eq, PartialEq, Debug, Clone)] 22 27 #[reflect(Component, PartialEq, Debug, Clone)] 23 28 pub struct Lifetime { 29 + /// Tracks the elapsed time. Once the timer is finished, the entity will be despawned. 24 30 pub timer: Timer, 31 + /// Controls the merge behaviour when an effect is [replaced](super::EffectMode::Replace). 25 32 pub mode: TimerMergeMode, 26 33 } 27 34 ··· 38 45 self 39 46 } 40 47 41 - // Todo Remove duplicates, maybe by adding 42 - // ``` 43 - // fn merge(&mut self, other: Self, mode: TimerMergeMode) 44 - // ``` 45 - // method to `Timer`. 46 48 fn merge(&mut self, other: &Self) { 47 49 match self.mode { 48 50 TimerMergeMode::Replace => {} ··· 78 80 #[derive(Component, Reflect, Eq, PartialEq, Debug, Clone)] 79 81 #[reflect(Component, PartialEq, Debug, Clone)] 80 82 pub struct Delay { 83 + /// Tracks the elapsed time. 81 84 pub timer: Timer, 85 + /// Controls the merge behaviour when an effect is [replaced](super::EffectMode::Replace). 82 86 pub mode: TimerMergeMode, 83 87 } 84 88 ··· 126 130 } 127 131 } 128 132 133 + /// Controls the merge behaviour of a timer when it's effect is [replaced](super::EffectMode::Replace). 129 134 #[derive(Reflect, Eq, PartialEq, Debug, Copy, Clone)] 130 135 #[reflect(PartialEq, Debug, Clone)] 131 136 pub enum TimerMergeMode {