Spend last week working on remote triggers for bevy_replicon
.
Tried many approaches and finally satisfied with the implementation and public API.
Client triggers example:
app.add_client_trigger::<DummyEvent>(ChannelKind::Ordered)
.add_observer(receive_events)
.add_systems(Update, send_events.run_if(client_connected));
fn send_events(mut commands: Commands) {
commands.client_trigger(DummyEvent);
}
fn receive_events(trigger: Trigger<FromClient<DummyEvent>>) {
let FromClient { client_id, event } = trigger.event();
info!("received event {event:?} from {client_id:?}");
}
Server triggers example:
app.add_server_trigger::<DummyEvent>(ChannelKind::Ordered)
.add_observer(receive_events)
.add_systems(Update, send_events.run_if(server_running));
fn send_events(mut commands: Commands) {
commands.server_trigger(ToClients {
mode: SendMode::Broadcast,
event: DummyEvent,
});
}
fn receive_events(trigger: Trigger<DummyEvent>) {
info!("received event {:?} from server", trigger.event());
}
Observers are so nice, I use them in my game a lot and not having them networked was quite limiting.
After a review from second maintainer I will merge it and draft a new release 🙂
Ah, you are right. But I didn't know where to upload them. What would you use for files?