lol idk #1

Open
Quaternions wants to merge 826 commits from StrafesNET/strafe-project:master into master
Showing only changes of commit 67223efa26 - Show all commits

View File

@ -29,6 +29,10 @@ fn get_full_name(dom:&rbx_dom_weak::WeakDom,instance:&rbx_dom_weak::Instance)->S
full_name
}
pub fn find_first_child_of_class<'a>(dom:&'a rbx_dom_weak::WeakDom,instance:&rbx_dom_weak::Instance,class:&str)->Option<&'a rbx_dom_weak::Instance>{
instance.children().iter().filter_map(|&r|dom.get_by_ref(r)).find(|inst|inst.class==class)
}
//workaround until I have an enum of classes
struct Dereferent(Ref);
impl mlua::UserData for Dereferent{}
@ -181,6 +185,22 @@ impl Instance{
};
methods.add_method("FindFirstChild",ffc);
methods.add_method("WaitForChild",ffc);
methods.add_method("FindFirstChildOfClass",|lua,this,(class,search_descendants):(mlua::String,mlua::Value)|{
let class_str=class.to_str()?;
let search_descendants=match search_descendants{
mlua::Value::Nil=>false,
mlua::Value::Boolean(b)=>b,
_=>Err(mlua::Error::runtime("Invalid argument #3 bool expected"))?,
};
if search_descendants==true{
return Err(mlua::Error::runtime("FFC of class searching descendants not supported get rekt"));
}
dom(lua,|dom|{
Ok(find_first_child_of_class(dom,this.get(dom)?,class_str)
.map(|inst|(Instance::new(inst.referent())))
)
})
});
methods.add_method("GetDescendants",|lua,this,_:()|
dom(lua,|dom|{
let children:Vec<_>=dom