Switch to replicon (#80)

This commit is contained in:
PROMETHIA-27
2025-12-08 19:22:17 -05:00
committed by GitHub
parent 7a5d2e6914
commit ff52258ad2
55 changed files with 1212 additions and 2951 deletions

View File

@@ -1,8 +1,8 @@
use bevy::prelude::*;
use lightyear::prelude::{Connected, MessageSender};
use bevy_replicon::prelude::{ClientId, ConnectedClient, SendMode, ToClients};
use shared::{
GameState, global_observer,
protocol::{TbMapEntityId, channels::UnorderedReliableChannel, messages::DespawnTbMapEntity},
protocol::{TbMapEntityId, messages::DespawnTbMapEntity},
};
pub fn plugin(app: &mut App) {
@@ -32,12 +32,14 @@ fn add_despawned_entities_to_cache(
pub struct DespawnedTbEntityCache(pub Vec<u64>);
fn send_new_client_despawned_cache(
trigger: On<Add, Connected>,
on: On<Add, ConnectedClient>,
cache: Res<DespawnedTbEntityCache>,
mut send: Query<&mut MessageSender<DespawnTbMapEntity>>,
mut send: MessageWriter<ToClients<DespawnTbMapEntity>>,
) {
let mut send = send.get_mut(trigger.event().entity).unwrap();
for &id in cache.0.iter() {
send.send::<UnorderedReliableChannel>(DespawnTbMapEntity(id));
send.write(ToClients {
mode: SendMode::Direct(ClientId::Client(on.entity)),
message: DespawnTbMapEntity(id),
});
}
}