spru_bevy/lib.rs
1//!
2//!
3//! Add included plugins as required:
4//! ```rust,ignore
5//! type MyServer = spru::server::Impl< /* ... */ >;
6//! type MyClient = spru::client::Impl< /* ... */ >;
7//!
8//! bevy::app::App::new()
9//! // ...
10//! .add_plugins((
11//! // Add the client plugin if any Clients will run on this App
12//! spru_bevy::client::Plugin::<MyClient>::default(),
13//! // Add the client plugin if any Servers will run on this App
14//! spru_bevy::server::Plugin::<MyServer>::default(),
15//! // Add the local plugin to automatically route signals
16//! // between local clients and servers in this App
17//! spru_bevy::local::Plugin::<MyServer, MyClient>::default(),
18//! ))
19//! // ...
20//! ```
21//!
22//! ## Creating Servers
23//! Servers are created by using a command:
24//! ```rust,ignore
25//! commands.queue(spru_bevy::server::command::Init::<MyServer, _> {
26//! // ...
27//! });
28//! ```
29//! The [local::Plugin] automatically creates added players as new Clients in the same [World](bevy::prelude::World).
30//! If you are not using the plugin, dequeue [Seed](spru::common::Seed)s from the
31//! [PendingClients](server::component::PendingClients) component, and use the [client::command::Init]
32//! command to initialize the Client in the desired location.
33//!
34//! ## IDs
35//! Because multiple clients and servers can coexist in the same App, both have a
36//! [GameId](common::component::GameId) component, and clients have a [ClientId](client::component::ClientId).
37//! You can filter a query to a client or server with matching ids using [ServerSSS::filter](server::ServerSSS::filter)
38//! [(_mut)](server::ServerSSS::filter_mut) and [ClientSSS::filter](client::ClientSSS::filter)
39//! [(_mut)](client::ClientSSS::filter_mut) respectively.
40//!
41//! ## Controlling Servers and Clients
42//! Servers and Clients are controlled using the [server::component::FromUser] and [client::component::FromUser] components
43//! attached to the server/client Entity. These are processed in an exclusive system, and fire [event](client::event)s
44//! when run.
45//!
46//! ```rust,ignore
47//! // Add an observer to keep track of all client ids
48//! .add_observer(
49//! |client_init: prelude::On<spru_bevy::client::event::Init<MyClient>>,
50//! mut client_ids: prelude::ResMut<MyClientIds>|
51//! -> prelude::Result {
52//! let client_id = *client_init.result.as_ref().map_err(ToString::to_string)?;
53//! client_ids.0.push(client_id);
54//! Ok(())
55//! },
56//! )
57//! ```
58//!
59
60#![deny(missing_debug_implementations)]
61#![allow(clippy::type_complexity)]
62#![allow(clippy::too_many_arguments)]
63
64#[cfg(feature = "client")]
65pub mod client;
66pub mod common;
67#[cfg(all(feature = "server", feature = "client"))]
68pub mod local;
69#[cfg(feature = "server")]
70pub mod server;