From e4550aaab29466905b5d84d9080d3ae73eea77e3 Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Mon, 9 Mar 2020 02:08:27 -0700 Subject: [PATCH] tweak add_children --- examples/parenting.rs | 4 ++-- examples/ui.rs | 4 ++-- src/ecs/world_builder.rs | 17 +++++++---------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/examples/parenting.rs b/examples/parenting.rs index f6e9d0fbce..20b934d1cf 100644 --- a/examples/parenting.rs +++ b/examples/parenting.rs @@ -38,9 +38,9 @@ fn setup(world: &mut World, resources: &mut Resources) { ..Default::default() }) .add(Rotator) - .add_children(|child_builder| { + .add_children(|builder| { // cube - child_builder.add_entity(MeshEntity { + builder.add_entity(MeshEntity { mesh: cube_handle, material: StandardMaterial { albedo: math::vec4(0.5, 0.4, 0.3, 1.0).into(), diff --git a/examples/ui.rs b/examples/ui.rs index 1c1fff5406..d334060cbe 100644 --- a/examples/ui.rs +++ b/examples/ui.rs @@ -111,8 +111,8 @@ fn setup(world: &mut World, resources: &mut Resources) { math::vec4(0.1, 0.1, 1.0, 1.0), ), }) - .add_children(|child_builder| { - child_builder.add_entity(UiEntity { + .add_children(|builder| { + builder.add_entity(UiEntity { node: Node::new( math::vec2(0.0, 0.0), Anchors::new(0.0, 1.0, 0.0, 1.0), diff --git a/src/ecs/world_builder.rs b/src/ecs/world_builder.rs index 4ce21b2fad..039b3c1b1f 100644 --- a/src/ecs/world_builder.rs +++ b/src/ecs/world_builder.rs @@ -72,18 +72,15 @@ impl<'a> WorldBuilder<'a> { self } - pub fn add_children(self, build_children: impl Fn(WorldBuilder) -> WorldBuilder) -> Self { - let mut child_builder = WorldBuilder { - world: self.world, - parent_entity: self.current_entity, - current_entity: None, - }; + pub fn add_children(mut self, build_children: impl Fn(WorldBuilder) -> WorldBuilder) -> Self { + self.parent_entity = self.current_entity; + self.current_entity = None; - child_builder = build_children(child_builder); + self = build_children(self); - child_builder.current_entity = child_builder.parent_entity; - child_builder.parent_entity = None; - child_builder + self.current_entity = self.parent_entity; + self.parent_entity = None; + self } fn add_parent_to_current_entity(&mut self) {