From 7ab377b5593d993029956f7274408113a203715a Mon Sep 17 00:00:00 2001 From: floralrainfall Date: Thu, 6 Jul 2023 22:27:38 -0400 Subject: [PATCH] Instance::contains and Instance::isAncestorOf --- src/engine/app/v8/tree/Instance.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/engine/app/v8/tree/Instance.cpp b/src/engine/app/v8/tree/Instance.cpp index 58a1ecf..608b384 100644 --- a/src/engine/app/v8/tree/Instance.cpp +++ b/src/engine/app/v8/tree/Instance.cpp @@ -13,12 +13,22 @@ RBX::Instance::Instance(std::string name) bool RBX::Instance::contains(RBX::Instance* child) { - + auto child_it = std::find(m_children.begin(), m_children.end(), (boost::shared_ptr)child); + if(child_it != m_children.end()) + return true; + return false; } bool RBX::Instance::isAncestorOf(RBX::Instance* instance) { - + RBX::Instance* instance_parent = instance->m_parent; + while(instance_parent != 0) + { + instance_parent = instance_parent->m_parent; + if(instance_parent == this) + return true; + } + return false; } bool RBX::Instance::askSetParent(RBX::Instance* instance)