~starkingdoms/starkingdoms

ref: 3fda3e4fdab15e5a633d1fc24dece34e16ba0743 starkingdoms/crates/unified/src/client/incoming_particles.rs -rw-r--r-- 1.3 KiB
3fda3e4f — core chore(fmt): format 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use crate::ecs::Particles;
use bevy::prelude::*;
use bevy_enoki::prelude::ParticleSpawnerState;
use bevy_enoki::{ParticleEffectHandle, ParticleSpawner};

pub fn replicated_particles_plugin(app: &mut App) {
    app.add_systems(
        PreUpdate,
        (replicate_new_particles, replicate_updated_particles),
    );
}

fn replicate_new_particles(
    q: Query<(Entity, &Particles), Added<Particles>>,
    assets: Res<AssetServer>,
    mut commands: Commands,
) {
    for (entity, p) in q.iter() {
        commands
            .entity(entity)
            .insert(ParticleSpawner::default())
            .insert(ParticleEffectHandle(assets.load(&p.effect)))
            .insert(ParticleSpawnerState {
                active: p.active,
                ..default()
            });
        info!("replicate_new_particles {:?}", p);
    }
}
fn replicate_updated_particles(
    mut q: Query<
        (
            Entity,
            &mut ParticleEffectHandle,
            &mut ParticleSpawnerState,
            &Particles,
        ),
        Changed<Particles>,
    >,
    assets: Res<AssetServer>,
    mut commands: Commands,
) {
    for (_entity, mut handle, mut state, p) in q.iter_mut() {
        *handle = ParticleEffectHandle(assets.load(&p.effect));
        state.active = p.active;
    }
}