Add Entity.getTargets

main
copygirl 6 months ago
parent 2ff2579d87
commit 4e101a1643
  1. 20
      src/entity.zig

@ -259,6 +259,26 @@ pub fn Entity(comptime ctx: anytype) type {
return if (result != 0) fromRaw(self.world, result) else null;
}
/// Returns an iterator that yields each of the targets of the
/// specified `relation` that this `Entity` has, if any.
pub fn getTargets(self: Self, relation: anytype) TargetIterator {
const rel = util.anyToEntity(ctx, relation);
return .{ .world = self.world, .entity = self.raw, .relation = rel.raw };
}
pub const TargetIterator = struct {
world: World(ctx),
entity: c.ecs_entity_t,
relation: c.ecs_entity_t,
index: c_int = 0,
pub fn next(self: *TargetIterator) ?Self {
var result = c.ecs_get_target(self.world.raw, self.entity, self.relation, self.index);
self.index += 1;
return if (result != 0) Self.fromRaw(self.world, result) else null;
}
};
/// Returns whether this `Entity` has the specified value.
///
/// `id` must be convertible to an id. See also: `util.anyToId(...)`.

Loading…
Cancel
Save