From 90e1fba5fd4d04e6adb97605e70c091439c46966 Mon Sep 17 00:00:00 2001 From: copygirl Date: Sun, 31 Mar 2024 11:54:31 +0200 Subject: [PATCH] Fix Pair.init and add .fromRaw constructor --- src/pair.zig | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/pair.zig b/src/pair.zig index 29d4061..ebce799 100644 --- a/src/pair.zig +++ b/src/pair.zig @@ -31,11 +31,16 @@ pub fn Pair(comptime ctx: anytype) type { world: *World, raw: c.ecs_id_t, + pub fn fromRaw(world: *World, relation_: c.ecs_entity_t, target_: c.ecs_entity_t) Self { + return .{ .world = world, .raw = c.ecs_pair(relation_, target_) }; + } + /// Build a pair from the specified `relation` and `target` entities. - /// The specified entities must be alive in the world. + /// Returns an error if either of the entities is not alive. pub fn init(relation_: Entity, target_: Entity) !Self { - const raw = c.ecs_make_pair(relation_.ensureAlive().raw, target_.ensureAlive().raw); - return .{ .world = relation_.world, .raw = raw }; + try relation_.ensureAlive(); + try target_.ensureAlive(); + return fromRaw(relation_.world, relation_.raw, target_.raw); } /// Ensures this `Pair` is valid and its `relation` and `target`