From bb7ccd97bb22d7ed2d71f58af2ca4886727b5c97 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Fri, 22 Sep 2023 19:41:27 -0700 Subject: [PATCH] wip --- src/load_roblox.rs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/load_roblox.rs b/src/load_roblox.rs index d555879..4b57736 100644 --- a/src/load_roblox.rs +++ b/src/load_roblox.rs @@ -10,16 +10,27 @@ fn class_is_a(class: &str, superclass: &str) -> bool { } return false } - -pub fn get_objects(dom:rbx_dom_weak::WeakDom, superclass: &str) -> Result, Box> { - let mut objects = std::vec::Vec::::new(); - //move matching instances into objects - let (_,mut instances) = dom.into_raw(); - for (_,instance) in instances.drain() { - if class_is_a(instance.class.as_str(), superclass) { - objects.push(instance); +fn recursive_collect_superclass(objects: &mut std::vec::Vec,dom: &rbx_dom_weak::WeakDom, instance: &rbx_dom_weak::Instance, superclass: &str){ + for &referent in instance.children() { + if let Some(c) = dom.get_by_ref(referent) { + if class_is_a(c.class.as_str(), superclass) { + objects.push(c.referent());//copy ref + } + recursive_collect_superclass(objects,dom,c,superclass); } } +} +fn get_texture_refs(dom:&rbx_dom_weak::WeakDom) -> Vec{ + let mut objects = std::vec::Vec::new(); + recursive_collect_superclass(&mut objects, dom, dom.root(),"Decal"); + //get ids + //clear vec + //next class + objects +} +pub fn get_objects(dom:rbx_dom_weak::WeakDom, superclass: &str) -> Result, Box> { + let mut objects = std::vec::Vec::new(); + recursive_collect_superclass(&mut objects, &dom, dom.root(),superclass); return Ok(objects) }