lightyear 0.26.4

Server-client networking library for the Bevy game engine with modular architecture
Documentation
use bevy_app::{PluginGroup, PluginGroupBuilder};

use crate::shared::SharedPlugins;
use core::time::Duration;

/// A plugin group containing all the client plugins.
///
/// The order in which the plugins are added matters!
/// You need to add:
/// - first add the `ClientPlugins`
/// - then build your protocol (usually in a `ProtocolPlugin`)
/// - then spawn your `Client` entity
pub struct ClientPlugins {
    /// The tick interval for the client. This is used to determine how often the client should tick.
    /// The default value is 1/60 seconds.
    pub tick_duration: Duration,
}

impl Default for ClientPlugins {
    fn default() -> Self {
        Self {
            tick_duration: Duration::from_secs_f32(1.0 / 60.0),
        }
    }
}

impl PluginGroup for ClientPlugins {
    #[allow(clippy::let_and_return)]
    fn build(self) -> PluginGroupBuilder {
        let builder = PluginGroupBuilder::start::<Self>();

        let builder = builder.add(lightyear_sync::client::ClientPlugin);

        let builder = builder.add(SharedPlugins {
            tick_duration: self.tick_duration,
        });

        // if the server feature is enabled (e.g. for host-server mode), then we don't need
        // the client to send checksum messages
        #[cfg(feature = "deterministic")]
        let builder = builder.add(lightyear_deterministic_replication::prelude::ChecksumSendPlugin);

        #[cfg(feature = "prediction")]
        let builder = builder.add(lightyear_prediction::plugin::PredictionPlugin);

        // IO
        #[cfg(feature = "webtransport")]
        let builder = builder.add(lightyear_webtransport::client::WebTransportClientPlugin);
        #[cfg(feature = "websocket")]
        let builder = builder.add(lightyear_websocket::client::WebSocketClientPlugin);
        #[cfg(feature = "steam")]
        let builder = builder.add(lightyear_steam::client::SteamClientPlugin);

        // CONNECTION
        #[cfg(feature = "netcode")]
        let builder = builder.add(lightyear_netcode::client_plugin::NetcodeClientPlugin);
        #[cfg(feature = "raw_connection")]
        let builder = builder.add(lightyear_raw_connection::client::RawConnectionPlugin);

        #[cfg(target_family = "wasm")]
        let builder = builder.add(lightyear_web::WebKeepalivePlugin {
            // The interval is in milliseconds. We can run app.update() infrequently when in the background
            wake_delay: 100.0,
        });

        builder
    }
}