Add way to get/set Entity name/symbol

main
copygirl 1 year ago
parent 1632e53eae
commit 15640c1b56
  1. 22
      src/entity.zig

@ -141,6 +141,28 @@ pub fn Entity(comptime ctx: anytype) type {
c.ecs_delete(self.world.raw, self.raw); c.ecs_delete(self.world.raw, self.raw);
} }
/// Gets the name of this `Entity`, or `null` if none.
pub fn getName(self: Self) ?[:0]const u8 {
const result = c.ecs_get_name(self.world.raw, self.raw);
return std.mem.sliceTo(result, 0);
}
/// Gets the symbol of this `Entity`, or `null` if none.
pub fn getSymbol(self: Self) ?[:0]const u8 {
const result = c.ecs_get_symbol(self.world.raw, self.raw);
return std.mem.sliceTo(result, 0);
}
/// Sets the name of this `Entity` to the specified value, if any.
pub fn setName(self: Self, value: ?[*:0]const u8) void {
_ = c.ecs_set_name(self.world.raw, self.raw, value);
}
/// Sets the symbol of this `Entity` to the specified value, if any.
pub fn setSymbol(self: Self, value: ?[*:0]const u8) void {
_ = c.ecs_set_symbol(self.world.raw, self.raw, value);
}
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