Add EntityBuilder constructor with parent arg

wip/no-type-lookup
copygirl 2 years ago
parent 0527919d47
commit 60919ef1f6
  1. 9
      src/gaemstone.ECS/EntityBuilder.cs
  2. 12
      src/gaemstone.ECS/World.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.

@ -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)

Loading…
Cancel
Save