Add world.pair function

main
copygirl 6 months ago
parent 90e1fba5fd
commit 8719bfeebe
  1. 13
      src/world.zig

@ -17,6 +17,7 @@ pub fn World(comptime ctx: anytype) type {
const Context = @import("./context.zig").Context(ctx);
const Entity = Context.Entity;
const Iter = Context.Iter;
const Pair = Context.Pair;
raw: *c.ecs_world_t,
@ -118,6 +119,18 @@ pub fn World(comptime ctx: anytype) type {
return lookupAlive(self, Context.lookup(T));
}
/// Looks up and returns a `Pair` made from the specified relation
/// and target entities, returning an error if either is not alive.
///
/// Note that in most cases, for functions that accept an `anytype`,
/// you can simply specify the tuple `.{ relation, target }` to
/// specify a pair, without having to use this function.
pub fn pair(self: *Self, relation: anytype, target: anytype) !Pair {
const rel = try self.lookupAlive(Context.anyToEntity(relation));
const tar = try self.lookupAlive(Context.anyToEntity(target));
return Pair.fromRaw(self, rel.raw, tar.raw);
}
/// Creates or modifies an `Entity` in this `World`.
/// See `Entity.init(...)` for more information.
pub fn entity(self: *Self, config: Entity.Config, add: anytype) !Entity {

Loading…
Cancel
Save