azalea::swarm

Struct SwarmBuilder

Source
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>

Source

pub fn new() -> SwarmBuilder<NoState, NoSwarmState>

Start creating the swarm.

Source

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>
where SS: Default + Send + Sync + Clone + Resource + 'static,

Source

pub fn set_handler<S, Fut>( self, handler: HandleFn<S, Fut>, ) -> SwarmBuilder<S, SS>
where Fut: Future<Output = Result<(), Error>> + Send + 'static, S: Send + Sync + Clone + Component + Default + 'static,

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>
where S: Send + Sync + Clone + Component + 'static,

Source

pub fn set_swarm_handler<SS, Fut>( self, handler: SwarmHandleFn<SS, Fut>, ) -> SwarmBuilder<S, SS>
where SS: Default + Send + Sync + Clone + Resource + 'static, Fut: Future<Output = Result<(), Error>> + Send + 'static,

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>
where S: Send + Sync + Clone + Component + 'static, SS: Default + Send + Sync + Clone + Resource + 'static,

Source

pub fn add_accounts(self, accounts: Vec<Account>) -> Self
where S: Default,

Add a vec of Accounts 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.

Source

pub fn add_account(self, account: Account) -> Self
where 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.

Source

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.

Source

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.

Source

pub fn set_swarm_state(self, swarm_state: SS) -> Self

Set the swarm state instead of initializing defaults.

Source

pub fn add_plugins<M>(self, plugins: impl Plugins<M>) -> Self

Add one or more plugins to this swarm.

Source

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.

Source

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>.

Source

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>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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>
where SS: Unpin, S: Unpin,

§

impl<S, SS> !UnwindSafe for SwarmBuilder<S, SS>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AsAny for T
where T: Any,

§

fn as_any(&self) -> &(dyn Any + 'static)

§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

§

fn type_name(&self) -> &'static str

Gets the type name of self
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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 T
where T: AsAny + ?Sized,

§

fn is<T>(&self) -> bool
where T: AsAny,

Returns true if the boxed type is the same as T. Read more
§

fn downcast_ref<T>(&self) -> Option<&T>
where T: AsAny,

Forward to the method defined on the type Any.
§

fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: AsAny,

Forward to the method defined on the type Any.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromWorld for T
where T: Default,

§

fn from_world(_world: &mut World) -> T

Creates Self using data from the given [World].
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more