2024-09-17 01:54:04 +00:00
|
|
|
use rbx_dom_weak::{types::Ref,WeakDom};
|
|
|
|
|
|
|
|
pub fn class_is_a(class:&str,superclass:&str)->bool{
|
|
|
|
class==superclass
|
|
|
|
||rbx_reflection_database::get().classes.get(class)
|
|
|
|
.is_some_and(|descriptor|
|
|
|
|
descriptor.superclass.as_ref().is_some_and(|class_super|
|
|
|
|
class_is_a(class_super,superclass)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-09-18 22:30:28 +00:00
|
|
|
pub struct Context<'a>{
|
|
|
|
pub(crate)dom:&'a mut WeakDom,
|
2024-09-17 01:54:04 +00:00
|
|
|
}
|
|
|
|
|
2024-09-18 22:30:28 +00:00
|
|
|
impl Context<'_>{
|
|
|
|
pub fn new(dom:&mut WeakDom)->Context<'_>{
|
|
|
|
Context{dom}
|
2024-09-17 01:54:04 +00:00
|
|
|
}
|
|
|
|
/// Creates an iterator over all items of a particular class.
|
|
|
|
pub fn superclass_iter<'a>(&'a self,superclass:&'a str)->impl Iterator<Item=Ref>+'a{
|
|
|
|
self.dom.descendants().filter(|&instance|
|
|
|
|
class_is_a(instance.class.as_ref(),superclass)
|
|
|
|
).map(|instance|instance.referent())
|
|
|
|
}
|
|
|
|
pub fn scripts(&self)->Vec<crate::script::Script>{
|
|
|
|
self.superclass_iter("LuaSourceContainer").map(crate::script::Script::new).collect()
|
|
|
|
}
|
|
|
|
}
|