Add Entity.getRef function

main
copygirl 3 months ago
parent e695213f65
commit 1b303d0b3a
  1. 7
      src/entity.zig

@ -302,10 +302,13 @@ pub fn Entity(comptime ctx: anytype) type {
}
pub fn get(self: Self, comptime T: type) ?T {
return if (getRef(self, T)) |p| p.* else null;
}
pub fn getRef(self: Self, comptime T: type) ?*const T {
const id = Context.lookup(T).*;
const ptr = c.ecs_get_id(self.world.raw, self.raw, id);
const typed_ptr: ?*const T = @alignCast(@ptrCast(ptr));
return if (typed_ptr) |p| p.* else null;
return @alignCast(@ptrCast(ptr));
}
pub fn getMut(self: Self, comptime T: type) ?*T {

Loading…
Cancel
Save