Compare commits

..

No commits in common. "0148476648fc9034b20a198deadcb3d58c3f9b2c" and "e4114ab2cca5dacfbffe97f1ce9b1af4ff81f7a9" have entirely different histories.

View File

@ -87,24 +87,6 @@ macro_rules! class_composition{
}; };
} }
//TODO: update rbx_reflection and use dom.superclasses_iter
pub struct SuperClassIter<'a> {
database: &'a rbx_reflection::ReflectionDatabase<'a>,
descriptor: Option<&'a rbx_reflection::ClassDescriptor<'a>>,
}
impl<'a> SuperClassIter<'a> {
fn next_descriptor(&self) -> Option<&'a rbx_reflection::ClassDescriptor<'a>> {
let superclass = self.descriptor?.superclass.as_ref()?;
self.database.classes.get(superclass)
}
}
impl<'a> Iterator for SuperClassIter<'a> {
type Item = &'a rbx_reflection::ClassDescriptor<'a>;
fn next(&mut self) -> Option<Self::Item> {
let next_descriptor = self.next_descriptor();
std::mem::replace(&mut self.descriptor, next_descriptor)
}
}
class!(Instance); class!(Instance);
class_composition!(Instance,(Instance)); class_composition!(Instance,(Instance));
@ -158,29 +140,6 @@ impl Instance{
Ok(children) Ok(children)
}) })
); );
let ffc=|lua,this:&T,(name,search_descendants):(mlua::String,mlua::Value)|{
let name_str=name.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"))?,
};
dom(lua,|dom|{
let instance=this.get(dom)?;
let child=match search_descendants{
true=>dom.descendants_of(this.referent()).find(|inst|inst.name==name_str),
false=>instance.children().iter().filter_map(|&r|
dom.get_by_ref(r)
).find(|inst|inst.name==name_str),
};
match child{
Some(instance)=>Instance::new(instance.referent()).into_lua(lua),
None=>mlua::Value::Nil.into_lua(lua),
}
})
};
methods.add_method("FindFirstChild",ffc);
methods.add_method("WaitForChild",ffc);
methods.add_method("GetDescendants",|lua,this,_:()| methods.add_method("GetDescendants",|lua,this,_:()|
dom(lua,|dom|{ dom(lua,|dom|{
let children:Vec<_>=dom let children:Vec<_>=dom
@ -224,48 +183,28 @@ impl Instance{
let index_str=index.to_str()?; let index_str=index.to_str()?;
let db=rbx_reflection_database::get(); let db=rbx_reflection_database::get();
let class=db.classes.get(instance.class.as_str()).ok_or(mlua::Error::runtime("Class missing"))?; let class=db.classes.get(instance.class.as_str()).ok_or(mlua::Error::runtime("Class missing"))?;
let mut iter=SuperClassIter{ let property=db.find_default_property(class,index_str).ok_or(mlua::Error::runtime(format!("Property '{index_str}' missing on class '{}'",class.name)))?;
database:db, match property{
descriptor:Some(class), rbx_types::Variant::Vector3(_)=>{
};
let property=iter.find_map(|cls|cls.properties.get(index_str)).ok_or(mlua::Error::runtime(format!("Property '{index_str}' missing on class '{}'",class.name)))?;
match &property.data_type{
rbx_reflection::DataType::Value(rbx_types::VariantType::Vector3)=>{
let typed_value:Vector3=value.as_userdata().ok_or(mlua::Error::runtime("Expected Userdata"))?.take()?; let typed_value:Vector3=value.as_userdata().ok_or(mlua::Error::runtime("Expected Userdata"))?.take()?;
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Vector3(typed_value.into())); instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Vector3(typed_value.into()));
}, },
rbx_reflection::DataType::Value(rbx_types::VariantType::Float32)=>{ rbx_types::Variant::Float32(_)=>{
let typed_value:f32=coerce_float32(&value).ok_or(mlua::Error::runtime("Expected f32"))?; let typed_value:f32=coerce_float32(&value).ok_or(mlua::Error::runtime("Expected f32"))?;
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Float32(typed_value)); instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Float32(typed_value));
}, },
rbx_reflection::DataType::Enum(enum_name)=>{ rbx_types::Variant::Enum(_)=>{
let typed_value=match &value{ let typed_value:super::r#enum::Enum=value.as_userdata().ok_or(mlua::Error::runtime("Expected Enum"))?.take()?;
&mlua::Value::Integer(int)=>Ok(rbx_types::Enum::from_u32(int as u32)), instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Enum(typed_value.into()));
&mlua::Value::Number(num)=>Ok(rbx_types::Enum::from_u32(num as u32)),
mlua::Value::String(s)=>{
let e=db.enums.get(enum_name).ok_or(mlua::Error::runtime("Database DataType Enum name does not exist"))?;
Ok(rbx_types::Enum::from_u32(*e.items.get(s.to_str()?).ok_or(mlua::Error::runtime("Invalid enum item"))?))
}, },
mlua::Value::UserData(any_user_data)=>{ rbx_types::Variant::Color3(_)=>{
let e:super::r#enum::Enum=any_user_data.take()?;
Ok(e.into())
},
_=>Err(mlua::Error::runtime("Expected Enum")),
}?;
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Enum(typed_value));
},
rbx_reflection::DataType::Value(rbx_types::VariantType::Color3)=>{
let typed_value:super::color3::Color3=value.as_userdata().ok_or(mlua::Error::runtime("Expected Color3"))?.take()?; let typed_value:super::color3::Color3=value.as_userdata().ok_or(mlua::Error::runtime("Expected Color3"))?.take()?;
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Color3(typed_value.into())); instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Color3(typed_value.into()));
}, },
rbx_reflection::DataType::Value(rbx_types::VariantType::Bool)=>{ rbx_types::Variant::Bool(_)=>{
let typed_value=value.as_boolean().ok_or(mlua::Error::runtime("Expected boolean"))?; let typed_value=value.as_boolean().ok_or(mlua::Error::runtime("Expected boolean"))?;
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Bool(typed_value)); instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Bool(typed_value));
}, },
rbx_reflection::DataType::Value(rbx_types::VariantType::String)=>{
let typed_value=value.as_str().ok_or(mlua::Error::runtime("Expected boolean"))?;
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::String(typed_value.to_owned()));
},
other=>return Err(mlua::Error::runtime(format!("Unimplemented property type: {other:?}"))), other=>return Err(mlua::Error::runtime(format!("Unimplemented property type: {other:?}"))),
} }
Ok(()) Ok(())