Add World.New(parent, path) method

wip/bindgen
copygirl 1 year ago
parent ad9b3f6736
commit 552022597f
  1. 7
      src/gaemstone.ECS/EntityRef.cs
  2. 14
      src/gaemstone.ECS/World.cs

@ -50,14 +50,17 @@ public unsafe class EntityRef
=> ecs_delete(World, this);
public EntityBuilder NewChild(EntityPath? path = null)
=> World.New(EnsureRelativePath(path)).ChildOf(this);
=> World.New(this, EnsureRelativePath(path));
public EntityRef? LookupChild(EntityPath path)
=> World.LookupByPath(this, EnsureRelativePath(path)!);
public EntityRef LookupChildOrThrow(EntityPath path)
=> World.LookupByPathOrThrow(this, EnsureRelativePath(path)!);
private static EntityPath? EnsureRelativePath(EntityPath? path)
{ if (path?.IsAbsolute == true) throw new ArgumentException("path must not be absolute", nameof(path)); return path; }
{
if (path?.IsAbsolute == true) throw new ArgumentException(
$"Path '{path}' must not be absolute", nameof(path)); return path;
}
public EntityRef? Parent

@ -33,14 +33,28 @@ public unsafe partial class World
public void Dispose()
=> ecs_fini(this);
public EntityBuilder New(EntityPath? path = null)
=> new(this, 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;
}
public bool Progress(TimeSpan delta)
=> ecs_progress(this, (float)delta.TotalSeconds);
public void Quit()
=> ecs_quit(this);
public static implicit operator ecs_world_t*(World w) => w.Handle;
}

Loading…
Cancel
Save