mirror of
https://github.com/bevyengine/bevy
synced 2024-11-23 05:03:47 +00:00
commit
938d381d45
1 changed files with 34 additions and 2 deletions
|
@ -1,7 +1,10 @@
|
||||||
use super::SystemId;
|
use super::SystemId;
|
||||||
use crate::resource::{Resource, Resources};
|
use crate::resource::{Resource, Resources};
|
||||||
use bevy_hecs::{Bundle, Component, DynamicBundle, Entity, World};
|
use bevy_hecs::{Bundle, Component, DynamicBundle, Entity, World};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::{
|
||||||
|
marker::PhantomData,
|
||||||
|
sync::{Arc, Mutex},
|
||||||
|
};
|
||||||
|
|
||||||
/// A queued command to mutate the current [World] or [Resources]
|
/// A queued command to mutate the current [World] or [Resources]
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
|
@ -109,6 +112,25 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) struct RemoveOne<T>
|
||||||
|
where
|
||||||
|
T: Component,
|
||||||
|
{
|
||||||
|
entity: Entity,
|
||||||
|
phantom: PhantomData<T>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> WorldWriter for RemoveOne<T>
|
||||||
|
where
|
||||||
|
T: Component,
|
||||||
|
{
|
||||||
|
fn write(self: Box<Self>, world: &mut World) {
|
||||||
|
if world.get::<T>(self.entity).is_ok() {
|
||||||
|
world.remove_one::<T>(self.entity).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait ResourcesWriter: Send + Sync {
|
pub trait ResourcesWriter: Send + Sync {
|
||||||
fn write(self: Box<Self>, resources: &mut Resources);
|
fn write(self: Box<Self>, resources: &mut Resources);
|
||||||
}
|
}
|
||||||
|
@ -321,6 +343,16 @@ impl Commands {
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn remove_one<T>(&mut self, entity: Entity) -> &mut Self
|
||||||
|
where
|
||||||
|
T: Component,
|
||||||
|
{
|
||||||
|
self.write_world(RemoveOne::<T> {
|
||||||
|
entity,
|
||||||
|
phantom: PhantomData,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Reference in a new issue