diff --git a/src/world.zig b/src/world.zig index 14bd4e4..b8f10a1 100644 --- a/src/world.zig +++ b/src/world.zig @@ -59,13 +59,32 @@ pub fn World(comptime ctx: anytype) type { return result; } + /// Returns the `Entity` with the specified unique symbol, or null if none. + pub fn lookupSymbol(self: *Self, symbol: []const u8) ?Entity { + const result = c.ecs_lookup_symbol(self.raw, symbol.ptr, false, false); + return if (result != 0) Entity.fromRaw(self, result) else null; + } + + /// Returns the `Entity` with the specified parent and name, or null if none. + /// If no parent is specified, the world root is used instead. + pub fn lookupChild(self: *Self, parent: anytype, name: []const u8) ?Entity { + var name_buffer: [256]u8 = undefined; + if (name.len + 1 > name_buffer.len) @panic("Name too long"); + @memcpy(name_buffer[0..name.len], name); + name_buffer[name.len] = 0; + + const parent_ = Context.anyToEntity(parent); + const result = c.ecs_lookup_child(self.raw, parent_, &name_buffer); + return if (result != 0) Entity.fromRaw(self, result) else null; + } + // TODO: Reconsider whether lookup functions should return errors or just optionals. // TODO: Reconsider whether "Entity" should always be in backticks in our doc comments. // TODO: We really need tests for this function. /// Returns the `Entity` at the specified path, or an error if the /// entity does not exist. If the path is not absolute, the operation /// will use the current scope, or the world root. - pub fn lookupByPath(self: *Self, path: Path) !Entity { + pub fn lookupPath(self: *Self, path: Path) !Entity { var parent = if (path.absolute) 0 else c.ecs_get_scope(self.raw); var current: c.ecs_entity_t = undefined; for (path.parts) |part| {