Skip to content

Commit

Permalink
Add remove bundle to bevy_ecs commands (#579)
Browse files Browse the repository at this point in the history
add remove bundle to bevy_ecs commands
  • Loading branch information
Raymond26 authored Sep 26, 2020
1 parent 85a7f88 commit 74ad1c3
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions crates/bevy_ecs/src/system/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,23 @@ where
}
}

pub(crate) struct Remove<T>
where
T: Bundle + Send + Sync + 'static,
{
entity: Entity,
phantom: PhantomData<T>,
}

impl<T> WorldWriter for Remove<T>
where
T: Bundle + Send + Sync + 'static,
{
fn write(self: Box<Self>, world: &mut World) {
world.remove::<T>(self.entity).unwrap();
}
}

pub trait ResourcesWriter: Send + Sync {
fn write(self: Box<Self>, resources: &mut Resources);
}
Expand Down Expand Up @@ -319,6 +336,16 @@ impl Commands {
})
}

pub fn remove<T>(&mut self, entity: Entity) -> &mut Self
where
T: Bundle + Send + Sync + 'static,
{
self.write_world(Remove::<T> {
entity,
phantom: PhantomData,
})
}

pub fn set_entity_reserver(&self, entity_reserver: EntityReserver) {
self.commands.lock().entity_reserver = Some(entity_reserver);
}
Expand Down

0 comments on commit 74ad1c3

Please sign in to comment.