From f259c9b8215699c2c50026dc6fe15e11dd9e188a Mon Sep 17 00:00:00 2001 From: copygirl Date: Thu, 7 Sep 2023 12:40:01 +0200 Subject: [PATCH] Add Entity.has to check if entity has a value --- src/entity.zig | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/entity.zig b/src/entity.zig index af51c9e..6e93dc3 100644 --- a/src/entity.zig +++ b/src/entity.zig @@ -254,6 +254,14 @@ pub fn Entity(comptime ctx: anytype) type { 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 { const id = Lookup(ctx, T).id; return @alignCast(@ptrCast(c.ecs_get_id(self.world.raw, self.raw, id)));