From 67a5c566a4974822833e1de578fd4d76227f6410 Mon Sep 17 00:00:00 2001 From: copygirl Date: Thu, 7 Sep 2023 12:39:22 +0200 Subject: [PATCH] Add World.tag to created Tag by type --- src/world.zig | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/world.zig b/src/world.zig index 2e50de4..077335c 100644 --- a/src/world.zig +++ b/src/world.zig @@ -67,7 +67,16 @@ pub fn World(comptime ctx: anytype) type { return Entity(ctx).new(self, config, add); } + pub fn tag(self: *Self, comptime T: type) !Entity(ctx) { + if (@sizeOf(T) > 0) @compileError("'" ++ @typeName(T) ++ "' must be a zero-sized type"); + const name = util.simpleTypeName(T); + const result = try self.entity(.{ .name = name, .symbol = name }, .{}); + Lookup(ctx, T).id = result.raw; + return result; + } + pub fn component(self: *Self, comptime T: type) !Entity(ctx) { + if (@sizeOf(T) == 0) @compileError("'" ++ @typeName(T) ++ "' must not be a zero-sized type"); const name = util.simpleTypeName(T); const entity2 = try self.entity(.{ .name = name, .symbol = name, .use_low_id = true }, .{});