1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use bevy::prelude::*;
use game_library::SpellLifetime;

/// Despawns spells when their lifetime expires, and updates their lifetime
pub fn despawn_expired_spells(
    mut commands: Commands,
    time: Res<Time>,
    mut query: Query<(Entity, &mut SpellLifetime)>,
) {
    for (entity, mut lifetime) in &mut query {
        lifetime.update(time.delta_seconds());
        if lifetime.is_expired() {
            commands.entity(entity).despawn_recursive();
        }
    }
}

#[derive(Component, Debug, Reflect)]
pub struct SpellEntity;