TnuaSimpleAirActionsCounter

Struct TnuaSimpleAirActionsCounter 

Source
pub struct TnuaSimpleAirActionsCounter<S: TnuaScheme> { /* private fields */ }
๐Ÿ‘ŽDeprecated: Use TnuaActionsCounter instead
Expand description

A simple counter that counts together all the air actions a character is able to perform.

Itโ€™s update must be called every frame, in the same schedule as TnuaControllerPlugin.

Implementationsยง

Sourceยง

impl<S> TnuaSimpleAirActionsCounter<S>

Source

pub fn update(&mut self, controller: &TnuaController<S>)

Call this every frame, in the same schedule as TnuaControllerPlugin, to track the air actions.

Source

pub fn reset_count_to(&mut self, count: usize)

Resets the air actions counter to a specific count, excluding the current action.

This method allows you to manually set the count of air actions (excluding the current action) to a specified value. Use this when you need to synchronize or initialize the air actions count to a specific state.

ยงArguments
  • count - The new count to set for air actions, excluding the current action.
ยงExample

// Reset the air actions count to 3 (excluding the current action). should also be updated as stated in TnuaAirActionsTracker
air_actions_counter.reset_count_to(3);
Source

pub fn get_count_mut(&mut self) -> Option<&mut usize>

Obtain a mutable reference to the air counter.

This can be use to modify the air counter while the player is in the air - for example, restoring an air jump when they pick up a floating token.

When it fits the usage, prefer reset_count which is simpler. get_count_mut should be used for more complex cases, e.g. when the player is allowed multiple air jumps, but only one jump gets restored per token.

Note that:

  • When the character is grounded, this method returns None. This is only for mutating the counter while the character is airborne.
  • When the character jumps from the ground, or starts a free fall, the counter is one - not zero. Setting the counter to 0 will mean that the next air jump will actually be treated as a ground jump - and theyโ€™ll get another air jump in addition to it. This is usually not the desired behavior.
  • Changing the action counter returned by this method will not affect the value air_count_for returns for an action that continues to be fed.
Source

pub fn reset_count(&mut self)

Resets the air actions counter.

This is equivalent to setting the counter to 1 using:

if let Some(count) = air_actions_counter.get_count_mut() {
    *count = 1;
}

The reason it is set to 1 and not 0 is that when the character jumps from the ground or starts a free fall the counter is 1 - and this is what one would usually want to reset to. Having a counter of 0 means that the character is grounded - but in that case get_count_mut will return None and the counter will not change.

Source

pub fn air_count_for(&self, action: S::ActionDiscriminant) -> usize

Calculate the โ€œair numberโ€ of an action.

The air number of a ground action is 0. The first air jump (double jump) as an air number of 1, the second (triple jump) has an air number of 2 and so on. Other air actions (like air dashes) are counted together with the jumps.

Use this number to:

  1. Determine if the action is allowed.
  2. Optionally change the actionโ€™s parameters as the air number progresses.

Note that the action discriminant is important, because Tnua relies on constant feed of some actions. As long as you pass the correct discriminant, the number will not change while the action continues to be fed. The discriminant can be obtained with TnuaController::action_discriminant.

Trait Implementationsยง

Sourceยง

impl<S: TnuaScheme> Component for TnuaSimpleAirActionsCounter<S>
where Self: Send + Sync + 'static,

Sourceยง

const STORAGE_TYPE: StorageType = ::bevy::ecs::component::StorageType::Table

A constant indicating the storage type used for this component.
Sourceยง

type Mutability = Mutable

A marker type to assist Bevy with determining if this component is mutable, or immutable. Mutable components will have Component<Mutability = Mutable>, while immutable components will instead have Component<Mutability = Immutable>. Read more
Sourceยง

fn register_required_components( _requiree: ComponentId, required_components: &mut RequiredComponentsRegistrator<'_, '_>, )

Registers required components. Read more
Sourceยง

fn clone_behavior() -> ComponentCloneBehavior

Called when registering this component, allowing to override clone function (or disable cloning altogether) for this component. Read more
Sourceยง

fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Self>>

Returns ComponentRelationshipAccessor required for working with relationships in dynamic contexts. Read more
Sourceยง

fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_add ComponentHook for this Component if one is defined.
Sourceยง

fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_insert ComponentHook for this Component if one is defined.
Sourceยง

fn on_replace() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_replace ComponentHook for this Component if one is defined.
Sourceยง

fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_remove ComponentHook for this Component if one is defined.
Sourceยง

fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_despawn ComponentHook for this Component if one is defined.
Sourceยง

fn map_entities<E>(_this: &mut Self, _mapper: &mut E)
where E: EntityMapper,

Maps the entities on this component using the given EntityMapper. This is used to remap entities in contexts like scenes and entity cloning. When deriving Component, this is populated by annotating fields containing entities with #[entities] Read more
Sourceยง

impl<S: TnuaScheme> Default for TnuaSimpleAirActionsCounter<S>

Sourceยง

fn default() -> Self

Returns the โ€œdefault valueโ€ for a type. Read more

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, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

Sourceยง

fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
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<C> Bundle for C
where C: Component,

Sourceยง

fn component_ids( components: &mut ComponentsRegistrator<'_>, ) -> impl Iterator<Item = ComponentId> + use<C>

Sourceยง

fn get_component_ids( components: &Components, ) -> impl Iterator<Item = Option<ComponentId>>

Return a iterator over this Bundleโ€™s component ids. This will be None if the component has not been registered.
Sourceยง

impl<C> BundleFromComponents for C
where C: Component,

Sourceยง

unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
where F: for<'a> FnMut(&'a mut T) -> OwningPtr<'a>,

Sourceยง

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

Sourceยง

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

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Sourceยง

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Sourceยง

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

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

Converts &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> DowncastSend for T
where T: Any + Send,

Sourceยง

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Sourceยง

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

Sourceยง

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Sourceยง

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

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Sourceยง

impl<C> DynamicBundle for C
where C: Component,

Sourceยง

type Effect = ()

An operation on the entity that happens after inserting this bundle.
Sourceยง

unsafe fn get_components( ptr: MovingPtr<'_, C>, func: &mut impl FnMut(StorageType, OwningPtr<'_>), ) -> <C as DynamicBundle>::Effect

Moves the components out of the bundle. Read more
Sourceยง

unsafe fn apply_effect( _ptr: MovingPtr<'_, MaybeUninit<C>>, _entity: &mut EntityWorldMut<'_>, )

Applies the after-effects of spawning this bundle. Read more
Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

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

Sourceยง

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

Creates Self using default().

Sourceยง

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Sourceยง

const WITNESS: W = W::MAKE

A constant of the type witness
Sourceยง

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

Sourceยง

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Sourceยง

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
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> IntoResult<T> for T

Sourceยง

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Sourceยง

impl<A> Is for A
where A: Any,

Sourceยง

fn is<T>() -> bool
where T: Any,

Checks if the current type โ€œisโ€ another type, using a TypeId equality comparison. This is most useful in the context of generic logic. 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<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,

Sourceยง

impl<T> Settings for T
where T: 'static + Send + Sync,

Sourceยง

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

Sourceยง

impl<T> WasmNotSendSync for T

Sourceยง

impl<T> WasmNotSync for T
where T: Sync,