From 60919ef1f6da7d2d50c1ff7d881a2fde849b6b52 Mon Sep 17 00:00:00 2001 From: copygirl Date: Sat, 21 Jan 2023 10:34:43 +0100 Subject: [PATCH] Add EntityBuilder constructor with parent arg --- src/gaemstone.ECS/EntityBuilder.cs | 9 +++++++++ src/gaemstone.ECS/World.cs | 12 ++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/gaemstone.ECS/EntityBuilder.cs b/src/gaemstone.ECS/EntityBuilder.cs index 8a4734b..fdbd542 100644 --- a/src/gaemstone.ECS/EntityBuilder.cs +++ b/src/gaemstone.ECS/EntityBuilder.cs @@ -50,6 +50,15 @@ public class EntityBuilder public EntityBuilder(World world, EntityPath? path = null) { World = world; Path = path; } + public EntityBuilder(World world, Entity parent, EntityPath? path = null) + : this(world, path) + { + // If given path is absolute, the new entity won't be created as a + // child of the specified parent. Alternatively, EntityRef.NewChild + // can be used, which will throw when an absolute path is given. + if ((path?.IsRelative != false) && parent.IsSome) ChildOf(parent); + } + public override EntityBuilder Add(Id id) { // If adding a ChildOf relation, store the parent separately. diff --git a/src/gaemstone.ECS/World.cs b/src/gaemstone.ECS/World.cs index 3220f67..00ad339 100644 --- a/src/gaemstone.ECS/World.cs +++ b/src/gaemstone.ECS/World.cs @@ -34,18 +34,10 @@ public unsafe partial class World public EntityBuilder New(EntityPath? path = null) - => new(this, path); + => new(this, default, path); public EntityBuilder New(EntityRef? parent, EntityPath? path = null) - { - var entity = New(path); - // If given path is absolute, the new entity won't be created as a - // child of the specified parent. Alternatively, EntityRef.NewChild - // can be used, which will throw when an absolute path is given. - if ((path?.IsRelative != false) && (parent != null)) - entity.ChildOf(parent); - return entity; - } + => new(this, parent, path); public bool Progress(TimeSpan delta)