module: add getFirstChildOfType helper

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2024-12-01 11:46:10 -07:00 committed by Emi Gutekanst
parent cddebeb01f
commit 6dd7b48662

View file

@ -391,6 +391,18 @@ pub fn Objects(options: ObjectsOptions, comptime T: type) type {
pub fn removeChild(objs: *@This(), id: ObjectID, child: ObjectID) !void {
return objs.internal.graph.removeChild(objs.internal.allocator, id, child);
}
/// Queries the children of the given object ID (which may be any object, including one not
/// in this list of objects - and finds the first child which would be from this list of
/// objects.
pub fn getFirstChildOfType(objs: *@This(), id: ObjectID) !?ObjectID {
var children = try objs.getChildren(id);
defer children.deinit();
for (children.items) |child_id| {
if (objs.is(child_id)) return child_id;
}
return null;
}
};
}