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.

Start on `EffectStacks` component.

Still needs testing and/or an example. Could also use more documentation.

+74 -6
+5
src/component.rs
··· 1 + mod stack; 2 + mod timer; 3 + 4 + pub use stack::*; 5 + pub use timer::*;
+62
src/component/stack.rs
··· 1 + use crate::EffectMergeRegistry; 2 + use bevy_app::{App, Plugin}; 3 + use bevy_ecs::prelude::ReflectComponent; 4 + use bevy_ecs::prelude::{Component, Entity, EntityWorldMut}; 5 + use bevy_reflect::prelude::ReflectDefault; 6 + use bevy_reflect::Reflect; 7 + use std::ops::{Add, AddAssign, Deref, DerefMut}; 8 + 9 + pub(crate) struct StackPlugin; 10 + 11 + impl Plugin for StackPlugin { 12 + fn build(&self, app: &mut App) { 13 + app.world_mut() 14 + .resource_mut::<EffectMergeRegistry>() 15 + .register::<EffectStacks>(merge_effect_stacks); 16 + } 17 + } 18 + 19 + /// Tracks the number stacks of a [merge effect](crate::EffectMode::Merge) that have been applied to an entity. 20 + #[derive(Component, Reflect, Eq, PartialEq, Ord, PartialOrd, Debug, Copy, Clone)] 21 + #[reflect(Component, Default, PartialEq, Debug, Clone)] 22 + pub struct EffectStacks(pub u8); 23 + 24 + impl Default for EffectStacks { 25 + fn default() -> Self { 26 + Self(1) 27 + } 28 + } 29 + 30 + impl Deref for EffectStacks { 31 + type Target = u8; 32 + 33 + fn deref(&self) -> &Self::Target { 34 + &self.0 35 + } 36 + } 37 + 38 + impl DerefMut for EffectStacks { 39 + fn deref_mut(&mut self) -> &mut Self::Target { 40 + &mut self.0 41 + } 42 + } 43 + 44 + impl Add<u8> for EffectStacks { 45 + type Output = Self; 46 + 47 + fn add(self, rhs: u8) -> Self::Output { 48 + Self(self.0 + rhs) 49 + } 50 + } 51 + 52 + impl AddAssign<u8> for EffectStacks { 53 + fn add_assign(&mut self, rhs: u8) { 54 + self.0 += rhs 55 + } 56 + } 57 + 58 + /// Merge logic for [`EffectStacks`]. 59 + fn merge_effect_stacks(mut new: EntityWorldMut, outgoing: Entity) { 60 + let outgoing = *new.world().get::<EffectStacks>(outgoing).unwrap(); 61 + *new.get_mut::<EffectStacks>().unwrap() += outgoing.0; 62 + }
+5 -4
src/lib.rs
··· 2 2 3 3 mod bundle; 4 4 mod command; 5 + mod component; 5 6 mod registry; 6 7 mod relation; 7 - mod timer; 8 8 9 9 use bevy_app::{App, Plugin}; 10 10 use bevy_ecs::prelude::*; 11 + use bevy_reflect::prelude::ReflectDefault; 11 12 use bevy_reflect::Reflect; 12 - use bevy_reflect::prelude::ReflectDefault; 13 13 14 14 pub use bundle::*; 15 15 pub use command::*; 16 + pub use component::*; 16 17 pub use registry::*; 17 18 pub use relation::*; 18 - pub use timer::*; 19 19 20 20 /// Setup required types and systems for `bevy_alchemy`. 21 21 pub struct AlchemyPlugin; ··· 29 29 .register_type::<Delay>() 30 30 .register_type::<TimerMergeMode>() 31 31 .init_resource::<EffectMergeRegistry>() 32 - .add_plugins(TimerPlugin); 32 + .add_plugins(TimerPlugin) 33 + .add_plugins(StackPlugin); 33 34 } 34 35 } 35 36
+2 -2
src/timer.rs src/component/timer.rs
··· 1 - use crate::ReflectComponent; 2 1 use crate::registry::EffectMergeRegistry; 2 + use crate::ReflectComponent; 3 3 use bevy_app::{App, Plugin, PreUpdate}; 4 4 use bevy_ecs::component::Mutable; 5 5 use bevy_ecs::prelude::{Commands, Component, Entity, Query, Res}; ··· 9 9 use bevy_time::{Time, Timer, TimerMode}; 10 10 use std::time::Duration; 11 11 12 - pub(super) struct TimerPlugin; 12 + pub(crate) struct TimerPlugin; 13 13 14 14 impl Plugin for TimerPlugin { 15 15 fn build(&self, app: &mut App) {