Add Entity.has to check if entity has a value

main
copygirl 1 year ago
parent 67a5c566a4
commit f259c9b821
  1. 8
      src/entity.zig

@ -254,6 +254,14 @@ pub fn Entity(comptime ctx: anytype) type {
return if (result != 0) fromRaw(self.world, result) else null; return if (result != 0) fromRaw(self.world, result) else null;
} }
/// Returns whether this `Entity` has the specified value.
///
/// `value` must be convertible to an id. See also: `util.anyToId(...)`.
pub fn has(self: Self, value: anytype) bool {
const id = util.anyToId(ctx, value);
return c.ecs_has_id(self.world.raw, self.raw, id);
}
pub fn get(self: Self, comptime T: type) ?*const T { pub fn get(self: Self, comptime T: type) ?*const T {
const id = Lookup(ctx, T).id; const id = Lookup(ctx, T).id;
return @alignCast(@ptrCast(c.ecs_get_id(self.world.raw, self.raw, id))); return @alignCast(@ptrCast(c.ecs_get_id(self.world.raw, self.raw, id)));

Loading…
Cancel
Save