Skip to content

Commit

Permalink
Add system labels (#26)
Browse files Browse the repository at this point in the history
* add system labels

* update visibility

* add system label

* re-add playing

* run rustfmt

* have only one system label

* fix clippy

* fix clippy ..

* clippy + fmt

Co-authored-by: Charles Bournhonesque <[email protected]>
  • Loading branch information
cBournhonesque and cbournhonesque-sc authored Jan 5, 2023
1 parent d2a0ae5 commit f88fd40
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ pub struct Playing;
pub struct RunningState {
/// Tracks the current amount of time since the start of the system.
///
/// This is reset when the running time surpases the ``system_duration_seconds``.
/// This is reset when the running time surpasses the ``system_duration_seconds``.
pub running_time: f32,

/// The truncated current second.
Expand Down
18 changes: 12 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ mod systems;
pub mod values;

use bevy_app::prelude::{App, Plugin};
use bevy_ecs::prelude::SystemSet;
pub use components::*;
pub use systems::ParticleSystemLabel;
use systems::{
particle_cleanup, particle_color, particle_lifetime, particle_spawner, particle_transform,
};
Expand Down Expand Up @@ -91,12 +93,16 @@ pub struct ParticleSystemPlugin;

impl Plugin for ParticleSystemPlugin {
fn build(&self, app: &mut App) {
app.add_system(particle_spawner)
.add_system(particle_lifetime)
.add_system(particle_color)
.add_system(particle_transform)
.add_system(particle_cleanup)
.register_type::<ParticleSystem>()
app.add_system_set(
SystemSet::new()
.label(ParticleSystemLabel::ParticleSystem)
.with_system(particle_spawner)
.with_system(particle_lifetime)
.with_system(particle_color)
.with_system(particle_transform)
.with_system(particle_cleanup),
);
app.register_type::<ParticleSystem>()
.register_type::<ParticleCount>()
.register_type::<RunningState>()
.register_type::<BurstIndex>();
Expand Down
10 changes: 10 additions & 0 deletions src/systems.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use bevy_ecs::prelude::{Commands, Entity, Query, Res, With};
use bevy_ecs::schedule::SystemLabel;
use bevy_hierarchy::BuildChildren;
use bevy_math::Vec3;
use bevy_sprite::prelude::{Sprite, SpriteBundle};
Expand All @@ -16,6 +17,15 @@ use crate::{
DistanceTraveled, ParticleTexture,
};

/// System label attached to the `SystemSet` provided in this plugin
///
/// This is provided so that users can order their systems to run before/after this plugin.
#[derive(Debug, SystemLabel)]
pub enum ParticleSystemLabel {
/// Label for the main systems
ParticleSystem,
}

#[allow(
clippy::cast_sign_loss,
clippy::cast_precision_loss,
Expand Down

0 comments on commit f88fd40

Please sign in to comment.