|
|
|
@ -137,17 +137,15 @@ pub fn World(comptime ctx: anytype) type { |
|
|
|
|
return Entity.init(self, config, add); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn tag(self: *Self, comptime T: type) !Entity { |
|
|
|
|
pub fn tag(self: *Self, name: [:0]const u8, comptime T: type) !Entity { |
|
|
|
|
if (@sizeOf(T) > 0) @compileError("'" ++ @typeName(T) ++ "' must be a zero-sized type"); |
|
|
|
|
const name = meta.simpleTypeName(T); |
|
|
|
|
const result = try self.entity(.{ .name = name, .symbol = name }, .{}); |
|
|
|
|
Context.lookupMut(T).* = result.raw; |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn component(self: *Self, comptime T: type) !Entity { |
|
|
|
|
pub fn component(self: *Self, name: [:0]const u8, comptime T: type) !Entity { |
|
|
|
|
if (@sizeOf(T) == 0) @compileError("'" ++ @typeName(T) ++ "' must not be a zero-sized type"); |
|
|
|
|
const name = meta.simpleTypeName(T); |
|
|
|
|
const entity_ = try self.entity(.{ .name = name, .symbol = name, .use_low_id = true }, .{}); |
|
|
|
|
|
|
|
|
|
const result = c.ecs_component_init(self.raw, &.{ |
|
|
|
@ -169,8 +167,8 @@ pub fn World(comptime ctx: anytype) type { |
|
|
|
|
/// Use `get()` and `set()` to get and set the value of this singleton. |
|
|
|
|
/// |
|
|
|
|
/// Returns the created component entity. |
|
|
|
|
pub fn singleton(self: *Self, comptime T: type, value: T) !Entity { |
|
|
|
|
const single = try component(self, T); |
|
|
|
|
pub fn singleton(self: *Self, name: [:0]const u8, comptime T: type, value: T) !Entity { |
|
|
|
|
const single = try component(self, name, T); |
|
|
|
|
single.set(T, value); |
|
|
|
|
return single; |
|
|
|
|
} |
|
|
|
|