pub struct TnuaActionsCounter<S: TnuaActionSlots> {
pub slots: S,
/* private fields */
}Expand description
An helper for counting the actions in scenarios where actions can only be done a limited amount of times. Mainly used for implementing air actions.
It’s update must be called every frame - even when the result is not used -
in the same schedule as TnuaControllerPlugin. For air actions,
this can usually be done with TnuaAirActionsPlugin.
This type exposes the slots struct to allow manual interference with the counting, but the
actually checking of counters should use count_for which also takes into
account the currently active action.
Fields§
§slots: SImplementations§
Source§impl<S: TnuaActionSlots> TnuaActionsCounter<S>
impl<S: TnuaActionSlots> TnuaActionsCounter<S>
Sourcepub fn update(
&mut self,
controller: &TnuaController<S::Scheme>,
status_for_basis: impl FnOnce(&TnuaBasisAccess<'_, <S::Scheme as TnuaScheme>::Basis>) -> TnuaActionCountingStatus,
)
pub fn update( &mut self, controller: &TnuaController<S::Scheme>, status_for_basis: impl FnOnce(&TnuaBasisAccess<'_, <S::Scheme as TnuaScheme>::Basis>) -> TnuaActionCountingStatus, )
Call this every frame, at the schedule of
TnuaControllerPlugin, to track the actions.
The predicate and the TnuaActionSlots from the generic parameter define how the
counters will get updated.
Sourcepub fn count_for(
&self,
action: <S::Scheme as TnuaScheme>::ActionDiscriminant,
) -> usize
pub fn count_for( &self, action: <S::Scheme as TnuaScheme>::ActionDiscriminant, ) -> usize
Calculate the “number” of an action.
If actions are not currently being counted, this will return 0. Otherwise, it will return the number the requested action will be - meaning the first one in the counting duration will be numbered 1.
If the specified action is currently running, this method will return the number of the
currently running action, not the next action of the same variant. This is done so that
user control systems will keep feeding it - with allow_in_air: true - for as long as the
player holds the button. Note that this means that while the very action that triggered the
counting (e.g. - jumping off the ground when counting air actions) is still active, its
number will be 0 (even though action counting starts from 1, this action was from before
the counting so it gets to be 0)
Each slot gets counted separately. If the action does not belong to any slot, or if actions are not currently being counted, this returns 0.
let air_actions: TnuaActionsCounter<AirActionSlots>; // actually get this from a Query
controller.action(ControlScheme::Jump(TnuaBuiltinJump {
allow_in_air: air_actions.count_for(ControlSchemeActionDiscriminant::Jump)
// Allow one air jump - use <= instead of < because the first one in the air will
// be have its `count_for` return 1.
<= 1,
..Default::default()
}));Trait Implementations§
Source§impl<S: TnuaActionSlots> Component for TnuaActionsCounter<S>
impl<S: TnuaActionSlots> Component for TnuaActionsCounter<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 relationship_accessor() -> Option<ComponentRelationshipAccessor<Self>>
fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Self>>
ComponentRelationshipAccessor required for working with relationships in dynamic contexts. Read moreSource§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: TnuaActionSlots> Default for TnuaActionsCounter<S>
impl<S: TnuaActionSlots> Default for TnuaActionsCounter<S>
Auto Trait Implementations§
impl<S> Freeze for TnuaActionsCounter<S>
impl<S> RefUnwindSafe for TnuaActionsCounter<S>where
S: RefUnwindSafe,
<<S as TnuaActionSlots>::Scheme as TnuaScheme>::ActionDiscriminant: RefUnwindSafe,
impl<S> Send for TnuaActionsCounter<S>
impl<S> Sync for TnuaActionsCounter<S>
impl<S> Unpin for TnuaActionsCounter<S>
impl<S> UnwindSafe for TnuaActionsCounter<S>where
S: UnwindSafe,
<<S as TnuaActionSlots>::Scheme as TnuaScheme>::ActionDiscriminant: UnwindSafe,
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<'_>, ) -> impl Iterator<Item = ComponentId> + use<C>
Source§fn get_component_ids(
components: &Components,
) -> impl Iterator<Item = Option<ComponentId>>
fn get_component_ids( components: &Components, ) -> impl Iterator<Item = 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