pub struct StatSet { /* private fields */ }Expand description
Runtime stat values keyed by author-defined StatId.
A StatSet can be used as the global stats Resource initialized by
VoxelStatsPlugin or attached directly to entities as a Component.
The framework does not assign a meaning to the owner entity: it can be a
player, mob, vehicle, machine, colony, or any author-defined subject.
Implementations§
Source§impl StatSet
impl StatSet
Sourcepub fn from_registry(registry: &StatRegistry) -> Self
pub fn from_registry(registry: &StatRegistry) -> Self
Creates a stat set initialized with every registered stat default.
Sourcepub fn ensure_registered(&mut self, registry: &StatRegistry)
pub fn ensure_registered(&mut self, registry: &StatRegistry)
Inserts any missing registered stats with their configured defaults.
Sourcepub fn set(
&mut self,
id: impl AsRef<str>,
value: f32,
registry: &StatRegistry,
) -> Result<f32, StatError>
pub fn set( &mut self, id: impl AsRef<str>, value: f32, registry: &StatRegistry, ) -> Result<f32, StatError>
Sets a stat value after resolving and clamping it through the registry.
Sourcepub fn add(
&mut self,
id: impl AsRef<str>,
delta: f32,
registry: &StatRegistry,
) -> Result<f32, StatError>
pub fn add( &mut self, id: impl AsRef<str>, delta: f32, registry: &StatRegistry, ) -> Result<f32, StatError>
Adds a delta to a stat and returns the clamped value.
Sourcepub fn drain(
&mut self,
id: impl AsRef<str>,
amount: f32,
registry: &StatRegistry,
) -> Result<f32, StatError>
pub fn drain( &mut self, id: impl AsRef<str>, amount: f32, registry: &StatRegistry, ) -> Result<f32, StatError>
Removes from a stat and returns the clamped value.
Sourcepub fn fill(
&mut self,
id: impl AsRef<str>,
amount: f32,
registry: &StatRegistry,
) -> Result<f32, StatError>
pub fn fill( &mut self, id: impl AsRef<str>, amount: f32, registry: &StatRegistry, ) -> Result<f32, StatError>
Adds to a stat and returns the clamped value.
Sourcepub fn get(
&self,
id: impl AsRef<str>,
registry: &StatRegistry,
) -> Result<f32, StatError>
pub fn get( &self, id: impl AsRef<str>, registry: &StatRegistry, ) -> Result<f32, StatError>
Returns the current stat value, falling back to the registered default when the stat is not yet stored in this set.
Sourcepub fn normalized(
&self,
id: impl AsRef<str>,
registry: &StatRegistry,
) -> Result<f32, StatError>
pub fn normalized( &self, id: impl AsRef<str>, registry: &StatRegistry, ) -> Result<f32, StatError>
Returns the current value normalized to 0.0..=1.0 across the
registered stat bounds.
This is only an inspection helper: it does not imply HUD, rules, or
effects behavior. A stat whose minimum and maximum are equal normalizes
to 1.0 to avoid division by zero.
Sourcepub fn is_at_or_below(
&self,
id: impl AsRef<str>,
threshold: f32,
registry: &StatRegistry,
) -> Result<bool, StatError>
pub fn is_at_or_below( &self, id: impl AsRef<str>, threshold: f32, registry: &StatRegistry, ) -> Result<bool, StatError>
Returns true when the current value is at or below an absolute threshold.
Sourcepub fn is_at_or_above(
&self,
id: impl AsRef<str>,
threshold: f32,
registry: &StatRegistry,
) -> Result<bool, StatError>
pub fn is_at_or_above( &self, id: impl AsRef<str>, threshold: f32, registry: &StatRegistry, ) -> Result<bool, StatError>
Returns true when the current value is at or above an absolute threshold.
Sourcepub fn is_at_or_below_percent(
&self,
id: impl AsRef<str>,
threshold: f32,
registry: &StatRegistry,
) -> Result<bool, StatError>
pub fn is_at_or_below_percent( &self, id: impl AsRef<str>, threshold: f32, registry: &StatRegistry, ) -> Result<bool, StatError>
Returns true when the normalized value is at or below threshold.
threshold is clamped to 0.0..=1.0; for example, 0.15 means 15%.
Sourcepub fn is_at_or_above_percent(
&self,
id: impl AsRef<str>,
threshold: f32,
registry: &StatRegistry,
) -> Result<bool, StatError>
pub fn is_at_or_above_percent( &self, id: impl AsRef<str>, threshold: f32, registry: &StatRegistry, ) -> Result<bool, StatError>
Returns true when the normalized value is at or above threshold.
threshold is clamped to 0.0..=1.0; for example, 0.85 means 85%.
Sourcepub fn is_min(
&self,
id: impl AsRef<str>,
registry: &StatRegistry,
) -> Result<bool, StatError>
pub fn is_min( &self, id: impl AsRef<str>, registry: &StatRegistry, ) -> Result<bool, StatError>
Returns true when this stat value is at or below its minimum bound.
Sourcepub fn is_max(
&self,
id: impl AsRef<str>,
registry: &StatRegistry,
) -> Result<bool, StatError>
pub fn is_max( &self, id: impl AsRef<str>, registry: &StatRegistry, ) -> Result<bool, StatError>
Returns true when this stat value is at or above its maximum bound.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&StatId, f32)>
pub fn iter(&self) -> impl Iterator<Item = (&StatId, f32)>
Iterates explicitly stored values in unspecified hash-map order.
Sourcepub fn snapshot(&self) -> Vec<StatValueSnapshot>
pub fn snapshot(&self) -> Vec<StatValueSnapshot>
Returns deterministic serializable snapshots of the explicitly stored values.
Trait Implementations§
Source§impl Component for StatSet
impl Component for StatSet
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<'de> Deserialize<'de> for StatSet
impl<'de> Deserialize<'de> for StatSet
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Resource for StatSet
Auto Trait Implementations§
impl Forget for StatSet
impl Freeze for StatSet
impl Move for StatSet
impl RefUnwindSafe for StatSet
impl Send for StatSet
impl Sync for StatSet
impl Unpin for StatSet
impl UnsafeUnpin for StatSet
impl UnwindSafe for StatSet
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,
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ConditionalSend for Twhere
T: Send,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
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<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
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