Struct ActionBinding

Source
pub struct ActionBinding { /* private fields */ }
Expand description

Bindings associated with an InputAction marker.

Stored inside Actions.

Bindings are stored separately from ActionMap to allow reading other actions’ data during evaluation.

Action bindings evaluation follows these steps:

  1. Iterate over each ActionValue from the associated Inputs: 1.1. Apply input-level InputModifiers. 1.2. Evaluate input-level InputConditions, combining their results based on their InputCondition::kind.
  2. Select all ActionValues with the most significant ActionState and combine based on InputAction::ACCUMULATION. Combined value will be converted into InputAction::Output using ActionValue::convert.
  3. Apply action level InputModifiers.
  4. Evaluate action level InputConditions, combining their results according to InputCondition::kind.
  5. Set the final ActionState based on the results. Final value will be converted into InputAction::Output using ActionValue::convert.

Implementations§

Source§

impl ActionBinding

Source

pub fn inputs(&self) -> &[InputBinding]

Returns associated input bindings.

See also Self::to.

Source

pub fn with_modifiers(&mut self, modifiers: impl IntoModifiers) -> &mut Self

Adds action-level modifiers.

For input-level modifiers see BindingBuilder::with_modifiers.

§Examples

Single modifier:

actions.bind::<Jump>()
    .to(KeyCode::Space)
    .with_modifiers(Scale::splat(2.0));

Multiple modifiers:

actions.bind::<Jump>()
    .to(KeyCode::Space)
    .with_modifiers((Scale::splat(2.0), Negate::all()));
Source

pub fn with_conditions(&mut self, conditions: impl IntoConditions) -> &mut Self

Adds action-level conditions.

For input-level conditions see BindingBuilder::with_conditions.

§Examples

Single condition:

actions.bind::<Jump>()
    .to(KeyCode::Space)
    .with_conditions(Release::default());

Multiple conditions:

actions.bind::<Jump>()
    .to(KeyCode::Space)
    .with_conditions((Release::default(), JustPress::default()));
Source

pub fn to(&mut self, bindings: impl IntoBindings) -> &mut Self

Adds input mapping.

Thanks to traits, this function can be called with multiple types:

  1. Raw input types.
  2. Input enum which wraps any supported raw input and can store keyboard modifiers.
  3. InputBinding which wraps Input and can store input modifiers or conditions.
  4. IntoBindings which wraps InputBinding and can store multiple InputBindings. Also implemented on tuples, so you can pass multiple inputs to a single call.

All assigned inputs will be evaluated separately (equivalent to “any of”). If you’re looking for a chord, see the Chord condition.

§Examples

Raw input:

actions.bind::<Jump>()
    .to((KeyCode::Space, GamepadButton::South));

Raw input with keyboard modifiers:

actions.bind::<Jump>().to(KeyCode::Space.with_mod_keys(ModKeys::CONTROL));

Raw input with input conditions or modifiers:

actions.bind::<Jump>().to(KeyCode::Space.with_conditions(Release::default()));
actions.bind::<Attack>().to(MouseButton::Left.with_modifiers(Scale::splat(10.0)));

Input type directly:

actions.bind::<Zoom>().to(Input::mouse_wheel());
actions.bind::<Move>().to(Input::mouse_motion());

Convenience preset which consists of multiple inputs with predefined conditions and modifiers:

actions.bind::<Move>().to(Cardinal::wasd_keys());

Multiple buttons from settings:

actions.bind::<Inspect>().to(&settings.inspect);

struct KeyboardSettings {
    inspect: Vec<KeyCode>,
}

Auto Trait Implementations§

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

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

Source§

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

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

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

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

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ConditionalSend for T
where T: Send,