2024-09-17 01:54:04 +00:00
|
|
|
use rbx_dom_weak::types::Ref;
|
|
|
|
|
2024-09-19 01:47:38 +00:00
|
|
|
use crate::context::Context;
|
|
|
|
|
2024-09-18 01:00:17 +00:00
|
|
|
#[derive(Debug)]
|
2024-09-17 01:54:04 +00:00
|
|
|
pub enum Error{
|
|
|
|
NoScript,
|
|
|
|
NoSource,
|
|
|
|
}
|
|
|
|
|
2024-09-18 01:26:58 +00:00
|
|
|
fn get_full_name(dom:&rbx_dom_weak::WeakDom,instance:&rbx_dom_weak::Instance)->String{
|
|
|
|
let mut full_name=instance.name.clone();
|
|
|
|
let mut pref=instance.parent();
|
|
|
|
while let Some(parent)=dom.get_by_ref(pref){
|
|
|
|
full_name.insert(0,'.');
|
|
|
|
full_name.insert_str(0,parent.name.as_str());
|
|
|
|
pref=parent.parent();
|
|
|
|
}
|
|
|
|
full_name
|
|
|
|
}
|
|
|
|
|
2024-09-17 01:54:04 +00:00
|
|
|
pub struct Script{
|
2024-09-19 01:47:38 +00:00
|
|
|
pub(crate)script:Ref,
|
2024-09-17 01:54:04 +00:00
|
|
|
}
|
|
|
|
impl Script{
|
|
|
|
pub const fn new(script:Ref)->Self{
|
|
|
|
Self{script}
|
|
|
|
}
|
2024-09-19 01:47:38 +00:00
|
|
|
pub fn name_source(&self,context:&Context)->Result<(String,String),Error>{
|
|
|
|
let instance=context.dom.get_by_ref(self.script).ok_or(Error::NoScript)?;
|
|
|
|
let source=match instance.properties.get("Source").ok_or(Error::NoSource)?{
|
|
|
|
rbx_dom_weak::types::Variant::String(s)=>s.clone(),
|
|
|
|
_=>Err(Error::NoSource)?,
|
2024-09-17 01:54:04 +00:00
|
|
|
};
|
2024-09-19 01:47:38 +00:00
|
|
|
Ok((get_full_name(&context.dom,instance),source))
|
2024-09-17 01:54:04 +00:00
|
|
|
}
|
|
|
|
}
|