Skip to content

Commit

Permalink
fix example
Browse files Browse the repository at this point in the history
  • Loading branch information
SpecificProtagonist committed Dec 12, 2024
1 parent 6245c93 commit c985e7f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 6 additions & 2 deletions examples/ecs/component_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ fn setup(world: &mut World) {
let value = world.get::<MyComponent>(entity).unwrap().0;
println!(
"{component_id:?} added to {entity:?} with value {value:?}{}",
caller.map(|location| format!("due to {location}").unwrap_or_default())
caller
.map(|location| format!("due to {location}"))
.unwrap_or_default()
);
// Or access resources
world
Expand All @@ -102,7 +104,9 @@ fn setup(world: &mut World) {
let value = world.get::<MyComponent>(entity).unwrap().0;
println!(
"{component_id:?} removed from {entity:?} with value {value:?}{}",
caller.map(|location| format!("due to {location}").unwrap_or_default())
caller
.map(|location| format!("due to {location}"))
.unwrap_or_default()
);
// You can also issue commands through `.commands()`
world.commands().entity(entity).despawn();
Expand Down
15 changes: 13 additions & 2 deletions examples/ecs/immutable_components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use bevy::{
utils::HashMap,
};
use core::alloc::Layout;
use core::panic::Location;

/// This component is mutable, the default case. This is indicated by components
/// implementing [`Component`] where [`Component::Mutability`] is [`Mutable`](bevy::ecs::component::Mutable).
Expand Down Expand Up @@ -73,7 +74,12 @@ impl NameIndex {
///
/// Since all mutations to [`Name`] are captured by hooks, we know it is not currently
/// inserted in the index, and its value will not change without triggering a hook.
fn on_insert_name(mut world: DeferredWorld<'_>, entity: Entity, _component: ComponentId) {
fn on_insert_name(
mut world: DeferredWorld<'_>,
entity: Entity,
_component: ComponentId,
_caller: Option<&'static Location<'static>>,
) {
let Some(&name) = world.entity(entity).get::<Name>() else {
unreachable!("OnInsert hook guarantees `Name` is available on entity")
};
Expand All @@ -88,7 +94,12 @@ fn on_insert_name(mut world: DeferredWorld<'_>, entity: Entity, _component: Comp
///
/// Since all mutations to [`Name`] are captured by hooks, we know it is currently
/// inserted in the index.
fn on_replace_name(mut world: DeferredWorld<'_>, entity: Entity, _component: ComponentId) {
fn on_replace_name(
mut world: DeferredWorld<'_>,
entity: Entity,
_component: ComponentId,
_caller: Option<&'static Location<'static>>,
) {
let Some(&name) = world.entity(entity).get::<Name>() else {
unreachable!("OnReplace hook guarantees `Name` is available on entity")
};
Expand Down

0 comments on commit c985e7f

Please sign in to comment.