Add Entity.GetTargets which returns IEnumerable

Old GetTarget was removed / made private.
wip/bindgen
copygirl 2 years ago
parent c949257d1d
commit ad9b3f6736
  1. 15
      src/gaemstone.ECS/EntityRef.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using gaemstone.Utility;
@ -60,7 +61,7 @@ public unsafe class EntityRef
public EntityRef? Parent
=> GetTarget(World.ChildOf);
=> GetTargets(World.ChildOf).FirstOrDefault();
public IEnumerable<EntityRef> GetChildren()
{
@ -139,12 +140,14 @@ public unsafe class EntityRef
return this;
}
public EntityRef? GetTarget(Entity relation, int index = 0)
private EntityRef? GetTarget(Entity relation, int index)
=> CreateOrNull(World, new(ecs_get_target(World, this, relation, index)));
public EntityRef? GetTarget(string symbol, int index = 0)
=> GetTarget(World.LookupBySymbolOrThrow(symbol), index);
public EntityRef? GetTarget<T>(int index = 0)
=> GetTarget(World.LookupByTypeOrThrow(typeof(T)), index);
public IEnumerable<EntityRef> GetTargets(Entity relation)
{ var index = 0; while (GetTarget(relation, index++) is EntityRef target) yield return target; }
public IEnumerable<EntityRef> GetTargets(string symbol)
=> GetTargets(World.LookupBySymbolOrThrow(symbol));
public IEnumerable<EntityRef> GetTargets<T>()
=> GetTargets(World.LookupByTypeOrThrow(typeof(T)));
public bool Equals(EntityRef? other) => (other is not null) && (World == other.World) && (Entity == other.Entity);
public override bool Equals(object? obj) => Equals(obj as EntityRef);

Loading…
Cancel
Save