pub struct SwarmBuilder<S, SS>where
S: Send + Sync + Clone + Component + 'static,
SS: Default + Send + Sync + Clone + Resource + 'static,{ /* private fields */ }
Expand description
Create a new Swarm
.
Implementations§
Source§impl SwarmBuilder<NoState, NoSwarmState>
impl SwarmBuilder<NoState, NoSwarmState>
Sourcepub fn new() -> SwarmBuilder<NoState, NoSwarmState>
pub fn new() -> SwarmBuilder<NoState, NoSwarmState>
Start creating the swarm.
Sourcepub fn new_without_plugins() -> SwarmBuilder<NoState, NoSwarmState>
pub fn new_without_plugins() -> SwarmBuilder<NoState, NoSwarmState>
Self::new
but without adding the plugins by default. This is useful
if you want to disable a default plugin.
You must add DefaultPlugins
, DefaultBotPlugins
, and
DefaultSwarmPlugins
to this.
use azalea::{app::PluginGroup, DefaultBotPlugins, DefaultPlugins, swarm::{DefaultSwarmPlugins}};
use bevy_log::LogPlugin;
let swarm_builder = SwarmBuilder::new_without_plugins()
.add_plugins(DefaultPlugins.build().disable::<LogPlugin>())
.add_plugins(DefaultBotPlugins)
.add_plugins(DefaultSwarmPlugins);
Source§impl<SS> SwarmBuilder<NoState, SS>
impl<SS> SwarmBuilder<NoState, SS>
Sourcepub fn set_handler<S, Fut>(
self,
handler: HandleFn<S, Fut>,
) -> SwarmBuilder<S, SS>
pub fn set_handler<S, Fut>( self, handler: HandleFn<S, Fut>, ) -> SwarmBuilder<S, SS>
Set the function that’s called every time a bot receives an Event
.
This is the way to handle normal per-bot events.
Currently you can have up to one handler.
swarm_builder.set_handler(handle);
#[derive(Component, Default, Clone)]
struct State {}
async fn handle(mut bot: Client, event: Event, state: State) -> anyhow::Result<()> {
Ok(())
}
Source§impl<S> SwarmBuilder<S, NoSwarmState>
impl<S> SwarmBuilder<S, NoSwarmState>
Sourcepub fn set_swarm_handler<SS, Fut>(
self,
handler: SwarmHandleFn<SS, Fut>,
) -> SwarmBuilder<S, SS>
pub fn set_swarm_handler<SS, Fut>( self, handler: SwarmHandleFn<SS, Fut>, ) -> SwarmBuilder<S, SS>
Set the function that’s called every time the swarm receives a
SwarmEvent
. This is the way to handle global swarm events.
Currently you can have up to one swarm handler.
swarm_builder.set_swarm_handler(swarm_handle);
#[derive(Resource, Default, Clone)]
struct SwarmState {}
async fn swarm_handle(
mut swarm: Swarm,
event: SwarmEvent,
state: SwarmState,
) -> anyhow::Result<()> {
Ok(())
}
Source§impl<S, SS> SwarmBuilder<S, SS>
impl<S, SS> SwarmBuilder<S, SS>
Sourcepub fn add_accounts(self, accounts: Vec<Account>) -> Selfwhere
S: Default,
pub fn add_accounts(self, accounts: Vec<Account>) -> Selfwhere
S: Default,
Add a vec of Account
s to the swarm.
Use Self::add_account
to only add one account. If you want the
clients to have different default states, add them one at a time with
Self::add_account_with_state
.
By default every account will join at the same time, you can add a delay
with Self::join_delay
.
Sourcepub fn add_account(self, account: Account) -> Selfwhere
S: Default,
pub fn add_account(self, account: Account) -> Selfwhere
S: Default,
Add a single new Account
to the swarm. Use Self::add_accounts
to
add multiple accounts at a time.
This will make the state for this client be the default, use
Self::add_account_with_state
to avoid that.
Sourcepub fn add_account_with_state(self, account: Account, state: S) -> Self
pub fn add_account_with_state(self, account: Account, state: S) -> Self
Add an account with a custom initial state. Use just
Self::add_account
to use the Default implementation for the state.
Sourcepub fn add_account_with_state_and_opts(
self,
account: Account,
state: S,
join_opts: JoinOpts,
) -> Self
pub fn add_account_with_state_and_opts( self, account: Account, state: S, join_opts: JoinOpts, ) -> Self
Same as Self::add_account_with_state
, but allow passing in custom
join options.
Sourcepub fn set_swarm_state(self, swarm_state: SS) -> Self
pub fn set_swarm_state(self, swarm_state: SS) -> Self
Set the swarm state instead of initializing defaults.
Sourcepub fn add_plugins<M>(self, plugins: impl Plugins<M>) -> Self
pub fn add_plugins<M>(self, plugins: impl Plugins<M>) -> Self
Add one or more plugins to this swarm.
Sourcepub fn join_delay(self, delay: Duration) -> Self
pub fn join_delay(self, delay: Duration) -> Self
Set how long we should wait between each bot joining the server.
By default, every bot will connect at the same time. If you set this field, however, the bots will wait for the previous one to have connected and then they’ll wait the given duration.
Sourcepub async fn start(
self,
address: impl TryInto<ServerAddress>,
) -> Result<!, StartError>
pub async fn start( self, address: impl TryInto<ServerAddress>, ) -> Result<!, StartError>
Build this SwarmBuilder
into an actual Swarm
and join the given
server.
The address
argument can be a &str
, ServerAddress
, or anything
that implements TryInto<ServerAddress>
.
Sourcepub async fn start_with_default_opts(
self,
address: impl TryInto<ServerAddress>,
default_join_opts: JoinOpts,
) -> Result<!, StartError>
pub async fn start_with_default_opts( self, address: impl TryInto<ServerAddress>, default_join_opts: JoinOpts, ) -> Result<!, StartError>
Do the same as Self::start
, but allow passing in default join
options for the bots.
Trait Implementations§
Source§impl Default for SwarmBuilder<NoState, NoSwarmState>
impl Default for SwarmBuilder<NoState, NoSwarmState>
Auto Trait Implementations§
impl<S, SS> !Freeze for SwarmBuilder<S, SS>
impl<S, SS> !RefUnwindSafe for SwarmBuilder<S, SS>
impl<S, SS> !Send for SwarmBuilder<S, SS>
impl<S, SS> !Sync for SwarmBuilder<S, SS>
impl<S, SS> Unpin for SwarmBuilder<S, SS>
impl<S, SS> !UnwindSafe for SwarmBuilder<S, SS>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> Downcast for Twhere
T: AsAny + ?Sized,
impl<T> Downcast for Twhere
T: AsAny + ?Sized,
§fn downcast_ref<T>(&self) -> Option<&T>where
T: AsAny,
fn downcast_ref<T>(&self) -> Option<&T>where
T: AsAny,
Any
.§fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: AsAny,
fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: AsAny,
Any
.§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Self
using data from the given [World
].