Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remove bundle to bevy_ecs commands #579

Merged
merged 4 commits into from
Sep 26, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 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,24 @@ 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) {
// TODO: need equivalent of world.get::<T>(self.entity).is_ok() check from RemoveOne?
Raymond26 marked this conversation as resolved.
Show resolved Hide resolved
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 +337,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