~starkingdoms/starkingdoms

ref: aa66f9e7ccc943f231bba5bdd9d58d46d935a056 starkingdoms/crates/unified/src/server/net.rs -rw-r--r-- 542 bytes
aa66f9e7ghostly_zsh working on making the game work with this networking 9 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,
        });
    }
}