|
|
@ -1,4 +1,5 @@ |
|
|
|
const std = @import("std"); |
|
|
|
const std = @import("std"); |
|
|
|
|
|
|
|
const Allocator = std.mem.Allocator; |
|
|
|
|
|
|
|
|
|
|
|
const c = @import("./c.zig"); |
|
|
|
const c = @import("./c.zig"); |
|
|
|
const err = @import("./error.zig"); |
|
|
|
const err = @import("./error.zig"); |
|
|
@ -6,6 +7,7 @@ const util = @import("./util.zig"); |
|
|
|
|
|
|
|
|
|
|
|
const Id = @import("./id.zig").Id; |
|
|
|
const Id = @import("./id.zig").Id; |
|
|
|
const Lookup = @import("./main.zig").Lookup; |
|
|
|
const Lookup = @import("./main.zig").Lookup; |
|
|
|
|
|
|
|
const Path = @import("./path.zig").Path; |
|
|
|
const World = @import("./world.zig").World; |
|
|
|
const World = @import("./world.zig").World; |
|
|
|
|
|
|
|
|
|
|
|
pub const EntityError = error{ |
|
|
|
pub const EntityError = error{ |
|
|
@ -141,6 +143,13 @@ pub fn Entity(comptime ctx: anytype) type { |
|
|
|
c.ecs_delete(self.world.raw, self.raw); |
|
|
|
c.ecs_delete(self.world.raw, self.raw); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns the full, absolute `Path` of this `Entity`. |
|
|
|
|
|
|
|
/// The entity is assumed to be alive. |
|
|
|
|
|
|
|
/// See also: `Path.fromEntity(...)`. |
|
|
|
|
|
|
|
pub fn getPath(self: Self, alloc: Allocator) !Path { |
|
|
|
|
|
|
|
return Path.fromEntity(ctx, null, self, alloc); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Gets the name of this `Entity`, or `null` if none. |
|
|
|
/// Gets the name of this `Entity`, or `null` if none. |
|
|
|
pub fn getName(self: Self) ?[:0]const u8 { |
|
|
|
pub fn getName(self: Self) ?[:0]const u8 { |
|
|
|
const result = c.ecs_get_name(self.world.raw, self.raw); |
|
|
|
const result = c.ecs_get_name(self.world.raw, self.raw); |
|
|
@ -163,6 +172,12 @@ pub fn Entity(comptime ctx: anytype) type { |
|
|
|
_ = c.ecs_set_symbol(self.world.raw, self.raw, value); |
|
|
|
_ = c.ecs_set_symbol(self.world.raw, self.raw, value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Gets the parent of this `Entity`, or `null` if it has none. |
|
|
|
|
|
|
|
pub fn getParent(self: Self) ?Self { |
|
|
|
|
|
|
|
const result = c.ecs_get_parent(self.world.raw, self.raw); |
|
|
|
|
|
|
|
return if (result != 0) fromRaw(self.world, result) else null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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))); |
|
|
|