~starkingdoms/starkingdoms

ref: b7220be1cb42d789d750e252d109490cb5578f2f starkingdoms/crates/unified/src/server/net.rs -rw-r--r-- 542 bytes
b7220be1 — core Revert "netcode: planet updates" 7 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::{prelude::*, shared::net::{Mapped, SendTargets, SpawnEntity, ToClients}};

pub fn net_plugin(app: &mut App) {
    app.add_systems(PreUpdate, detect_entity_spawn);
}

fn detect_entity_spawn(
    mapped_entities: Query<Entity, Added<Mapped>>,
    mut spawn_entity: MessageWriter<ToClients<SpawnEntity>>,
) {
    for entity in mapped_entities {
        debug!("entity was spawned");
        spawn_entity.write(ToClients {
            message: SpawnEntity { server: entity },
            targets: SendTargets::All,
        });
    }
}