ecs: add write_world and write_resources to Commands
this allows for custom commands
This commit is contained in:
parent
1c976ea5b8
commit
85bd0342d4
@ -206,24 +206,11 @@ impl Commands {
|
|||||||
I: IntoIterator + Send + Sync + 'static,
|
I: IntoIterator + Send + Sync + 'static,
|
||||||
I::Item: Bundle,
|
I::Item: Bundle,
|
||||||
{
|
{
|
||||||
self.commands
|
self.write_world(SpawnBatch { components_iter })
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.commands
|
|
||||||
.push(Command::WriteWorld(Box::new(SpawnBatch {
|
|
||||||
components_iter,
|
|
||||||
})));
|
|
||||||
self
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn despawn(&mut self, entity: Entity) -> &mut Self {
|
pub fn despawn(&mut self, entity: Entity) -> &mut Self {
|
||||||
self.commands
|
self.write_world(Despawn { entity })
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.commands
|
|
||||||
.push(Command::WriteWorld(Box::new(Despawn { entity })));
|
|
||||||
|
|
||||||
self
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with(&mut self, component: impl Component) -> &mut Self {
|
pub fn with(&mut self, component: impl Component) -> &mut Self {
|
||||||
@ -250,35 +237,15 @@ impl Commands {
|
|||||||
entity: Entity,
|
entity: Entity,
|
||||||
components: impl DynamicBundle + Send + Sync + 'static,
|
components: impl DynamicBundle + Send + Sync + 'static,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
self.commands
|
self.write_world(Insert { entity, components })
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.commands
|
|
||||||
.push(Command::WriteWorld(Box::new(Insert { entity, components })));
|
|
||||||
self
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_one(&mut self, entity: Entity, component: impl Component) -> &mut Self {
|
pub fn insert_one(&mut self, entity: Entity, component: impl Component) -> &mut Self {
|
||||||
self.commands
|
self.write_world(InsertOne { entity, component })
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.commands
|
|
||||||
.push(Command::WriteWorld(Box::new(InsertOne {
|
|
||||||
entity,
|
|
||||||
component,
|
|
||||||
})));
|
|
||||||
self
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_resource<T: Resource>(&mut self, resource: T) -> &mut Self {
|
pub fn insert_resource<T: Resource>(&mut self, resource: T) -> &mut Self {
|
||||||
self.commands
|
self.write_resources(InsertResource { resource })
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.commands
|
|
||||||
.push(Command::WriteResources(Box::new(InsertResource {
|
|
||||||
resource,
|
|
||||||
})));
|
|
||||||
self
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_local_resource<T: Resource>(
|
pub fn insert_local_resource<T: Resource>(
|
||||||
@ -286,14 +253,30 @@ impl Commands {
|
|||||||
system_id: SystemId,
|
system_id: SystemId,
|
||||||
resource: T,
|
resource: T,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
|
self.write_resources(InsertLocalResource {
|
||||||
|
system_id,
|
||||||
|
resource,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write_world<W: WorldWriter + 'static>(&mut self, world_writer: W) -> &mut Self {
|
||||||
self.commands
|
self.commands
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.commands
|
.commands
|
||||||
.push(Command::WriteResources(Box::new(InsertLocalResource {
|
.push(Command::WriteWorld(Box::new(world_writer)));
|
||||||
system_id,
|
self
|
||||||
resource,
|
}
|
||||||
})));
|
|
||||||
|
pub fn write_resources<W: ResourcesWriter + 'static>(
|
||||||
|
&mut self,
|
||||||
|
resources_writer: W,
|
||||||
|
) -> &mut Self {
|
||||||
|
self.commands
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.commands
|
||||||
|
.push(Command::WriteResources(Box::new(resources_writer)));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user