pub struct TnuaSimpleAirActionsCounter<S: TnuaScheme> { /* private fields */ }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.
Implementations§
Source§impl<S> TnuaSimpleAirActionsCounter<S>
impl<S> TnuaSimpleAirActionsCounter<S>
Sourcepub fn update(&mut self, controller: &TnuaController<S>)
pub fn update(&mut self, controller: &TnuaController<S>)
Call this every frame to track the air actions.
Sourcepub fn reset_count_to(&mut self, count: usize)
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);Sourcepub fn get_count_mut(&mut self) -> Option<&mut usize>
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_forreturns for an action that continues to be fed.
Sourcepub fn reset_count(&mut self)
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.
Sourcepub fn air_count_for(&self, action: S::ActionDiscriminant) -> usize
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:
- Determine if the action is allowed.
- 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>
impl<S: TnuaScheme> Component for TnuaSimpleAirActionsCounter<S>
Source§const STORAGE_TYPE: StorageType = ::bevy::ecs::component::StorageType::Table
const STORAGE_TYPE: StorageType = ::bevy::ecs::component::StorageType::Table
Source§type Mutability = Mutable
type Mutability = Mutable
Component<Mutability = Mutable>,
while immutable components will instead have Component<Mutability = Immutable>. Read moreSource§fn register_required_components(
_requiree: ComponentId,
required_components: &mut RequiredComponentsRegistrator<'_, '_>,
)
fn register_required_components( _requiree: ComponentId, required_components: &mut RequiredComponentsRegistrator<'_, '_>, )
Source§fn clone_behavior() -> ComponentCloneBehavior
fn clone_behavior() -> ComponentCloneBehavior
Source§fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_replace() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_replace() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
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 moreSource§impl<S: TnuaScheme> Default for TnuaSimpleAirActionsCounter<S>
impl<S: TnuaScheme> Default for TnuaSimpleAirActionsCounter<S>
Auto Trait Implementations§
impl<S> Freeze for TnuaSimpleAirActionsCounter<S>
impl<S> RefUnwindSafe for TnuaSimpleAirActionsCounter<S>
impl<S> Send for TnuaSimpleAirActionsCounter<S>
impl<S> Sync for TnuaSimpleAirActionsCounter<S>
impl<S> Unpin for TnuaSimpleAirActionsCounter<S>
impl<S> UnwindSafe for TnuaSimpleAirActionsCounter<S>
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.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
Source§impl<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut ComponentsRegistrator<'_>, ids: &mut impl FnMut(ComponentId), )
Source§fn get_component_ids(
components: &Components,
ids: &mut impl FnMut(Option<ComponentId>),
)
fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )
Source§impl<C> BundleFromComponents for Cwhere
C: Component,
impl<C> BundleFromComponents for Cwhere
C: Component,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§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>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§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.Source§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.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<C> DynamicBundle for Cwhere
C: Component,
impl<C> DynamicBundle for Cwhere
C: Component,
Source§unsafe fn get_components(
ptr: MovingPtr<'_, C>,
func: &mut impl FnMut(StorageType, OwningPtr<'_>),
) -> <C as DynamicBundle>::Effect
unsafe fn get_components( ptr: MovingPtr<'_, C>, func: &mut impl FnMut(StorageType, OwningPtr<'_>), ) -> <C as DynamicBundle>::Effect
Source§unsafe fn apply_effect(
_ptr: MovingPtr<'_, MaybeUninit<C>>,
_entity: &mut EntityWorldMut<'_>,
)
unsafe fn apply_effect( _ptr: MovingPtr<'_, MaybeUninit<C>>, _entity: &mut EntityWorldMut<'_>, )
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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